On 25/08/2015 13:15, Steffen Heil (Mailinglisten) wrote:
> Hi
> 
> I am investigating, how I can archive asynchronous writes with tomcat.

archive? I'm guessing you mean achieve.

> For servlets I came up with code like this:
>       final AsyncContext context = request.startAsync();
>       final ServletInputStream input = request.getInputStream();
>       final ServletOutputStream output = response.getOutputStream();
>       ChannelProcessor processor = new ChannelProcessor( channel, input, 
> output );
>       context.addListener( processor );
>       input.setReadListener( processor );
>       output.setWriteListener( processor );
> 
> While ChannelProcessor is my class that implements (beside others) 
> WriteListener, so I get notified, when the ServletOutputStream is ready to 
> send more data.
> However, looking at the code, I suspect that "output.write( byte[] buffer )" 
> will still block, if the amount of data in buffer is larger than the maximum 
> size of the OutputBuffer used by that connection:

No, it will buffer it all in the SocketWrapper. You won't get another
notification until the buffered data has been written.

> For WebSockets there is
>       session.getAsyncRemote().sendBinary( buffer, handkler );
> 
> But that calls ServletOutputStream.write (maybe from another thread)

Same as above.

> So, are these really asynchronous?

Yes.

> Is a call to ServletOutputStream.write always guaranteed to return without 
> blocking?`

Yes, assuming you are not using the BIO connector (where it always
blocks regardless).

> Where is that implemented?

The detail varies between versions due to the refactoring that has gone
on over time in the connectors but in trunk that is all handled by
SocketWrapperBase.writeNonBlocking()

Generally, the trunk code should be easier to follow because of the
refactoring.

HTH,

Mark


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to