On 10/22/2012 11:17 PM, Shing Wai Chan wrote:
> Based on the feedback from JavaOne, we would like to propose the
> following changes:
>
> In section 5.3 of Servlet 3.1, we have
>
> WriteListener
> void onWritePossible(). When a WriteListener is registered with the
> ServletOutputStream, this method will be invoked by the container if
> and only if canWrite method on ServletOutputStream, described below,
> has been called and has returned false.
>
> In other words, one need to write as much data as possible until it is
> blocking before the WriteListener#onWritePossible is invoked.
> In this case, the developer need to do the following pseudo code:
> servletOutputStream.setWriteListener(wlistener);
> writeUntilCannotWrite(servletOutputStream); // (a) first write
> ...
> // (b) more write to WriteListener.onWritePossible later
>
> It is hard to achieve this in the application code as they need to
> keep track of how much data has been written
> and make it available to the WriteListener.
>
> I propose to change the behavior that there is no need to do (a) above.
> The WriteListener#onWritePossible will be invoked once for every write
> operation permitted.
>
> Similarly for ReadListener.
>
>
> Also, we would like to rename
> ServletOutputStream#canWrite
> into
> ServletOutpustStream#isReady
> in order to be consistent with ServletInputStream
+1
In previous discussions on the list, I described canWrite (now isReady)
returning false as the trigger for the listener invocation, since otherwise:
- there will be concurrency issues
- the amount of callbacks will not be optimal
For read, it is the same behavior: the Servlet should be forced to read
all available data.
I remember this clarification of the behavior was very well received, in
particular by Greg (see the archives).
Rémy