jsr340-experts@servlet-spec.java.net

[jsr340-experts] Re: Servlet 3.1 EDR updated draft

From: Rajiv Mordani <rajiv.mordani_at_oracle.com>
Date: Thu, 31 May 2012 17:49:35 -0700

On 5/31/12 1:19 AM, Greg Wilkins wrote:
> On 30 May 2012 16:26, Rajiv Mordani<rajiv.mordani_at_oracle.com> wrote:
>> Yes that's what we have done. If there are references to
>> NonBlockingInputSource and NonBlockingOutputSink in the document then that's
>> a bug. We will fix that. But as you point out - since we removed the Readers
>> and Writers the necessary methods have just been added to SIS and SOS.
>
> Rajiv,
>
> can you clarify how the output methods are meant to work, as I can't
> see how they can be done fully NonBlocking (and may be better named as
> Async as Remy suggests).
>
> For example if servletOutputStream.canWrite() returns true, then I
> immediately do
>
> out.write(verylargearrayofbytes);
>
> then the signature of write has no way to communicate a partial write
> - thus a full write must be done (which is fine). But if that array
> is too large to be written without blocking then there are several
> ways in which this can be done:
>
> a) The write call will block until all data is written. This would
> give us a kind of hybrid mode where small writes could be done
> asynchronously, but large ones may block. Benefit of this approach is
> that it is simple to implement and simple to use without any complex
> buffering.
>
> b) The write will send as much as it can and then copy the unwritten
> data and return immediately. It will flush the unwritten data
> asynchronously and while doing so canWrite will be false and any
> writelistener will be called when the write completes. This gives
> nonBlocking behaviour, but at the cost of a potential big copy.


We have discussed this in the past and what we said was b above.

>
> c) The write will send as much as it can and then return immediately
> but keep a reference to the data array. It will flush the unwritten
> data asynchronously and while doing so CanWrite will be false and any
> writelisteners will be called when the write completes. This gives
> nonBlocking behaviour, but the caller must not change the passed byte
> array until such time as they are told the output stream is writeable
> again. However it avoids a large copy. This mode is kind of like
> NIO.2 style, but without ByteBuffers.
>
> Also I'm not exactly sure how often WriteListener.onWritePossible is
> called? Is it called after every write? ie if I write 1 byte and
> there is not blocking will it be called?

I have clarified this earlier as well and I think it is in the spec too
- but the onWritePossible is called once for every write possible. Once
invoked, it will not be invoked till a write operation is performed or
the canWrite is flipped.

>
> Finally, how does asynchronous mode interact with
> Response.resetBuffer, Response.setBufferSize etc. When writing
> nonBlocking, can we write data< the buffer size and then reset the
> buffer?

The resetBuffer, setBufferSize all work as they have done so far.

>
>
> regards