Consider the following simple async writer
volatile boolean written=false;
@Override
public void onWritePossible() throws IOException
{
if (!written)
{
written=true;
response.setContentLength(5);
servletOutputStream.write("data\n".getBytes());
}
if (servletOutputStream.isReady())
{
asyncContext.complete();
}
}
Because we set a content-length, then the write of 5 bytes is required to
close the output stream when the write completes.
If the write completes during it's call, what should isReady() return?
True even though the output stream is closed and no more data can be
written? False even though that will be interpreted by the caller as
saying that onWritePossible() will be called later when a write is possible
(but it never will be!)
If the write down not complete during the call to write, then obviously
isReady() must return false and call onWritePossible() once the write has
completed. In that case, what should isReady() return? true even though no
data can be written or false which means that yet another callback to owp
will be scheduled!
I think isReady should return true for a closed outputstream - a bit
strange, but will result in the simplest code.
thoughts?
--
Greg Wilkins <gregw_at_intalio.com>
http://www.webtide.com
Developer advice and support from the Jetty & CometD experts.
Intalio, the modern way to build business applications.