jsr340-experts@servlet-spec.java.net

[jsr340-experts] Non-blocking changes

From: Shing Wai Chan <shing.wai.chan_at_oracle.com>
Date: Mon, 22 Oct 2012 14:17:25 -0700

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


Regards,

Shing Wai