On 10 December 2015 at 00:29, Martin Mulholland <mmulholl_at_us.ibm.com> wrote:
> GW> Good catch!
>
> GW> This is just wrong! It is not a perspective thing. A container
> will
> GW> NEVER call onDataAvailable after the first invocation unless isReady
> has
> GW> been called AND it returned false.
>
> ED > This was done under SERVLET_SPEC-127. I have asked Shing-wai to
> explain
> ED> the rationale for that change. In the meantime, I don't understand
> your
> ED> assertion Greg. If the container calls ServletInputStream.isReady()
> and
> ED> it returns false, then it doesn't make sense for the container to call
> ED >ReadListener.onDataAvailable() because *data is not available*. Right?
> ED >Please help me understand.
>
> The way I interpreted the spec before was that only after an app calls
> isReady() and
> it returns false should the container be responsible for calling
> onDataAvailable again
> - when more data is available.
That is exactly what I meant. The container will call onDataAvailable
IFF isReady() has been called AND isReady() returned false AND there is
data available to be read.
> If the app returns without having called isReady() and
> got false the container is not on the hook to call onDataAvailable again.
this is how an application can communicate back pressure to the API. If it
has read some data, but is still processing it and not ready to read any
more data, then it can return without having called isReady(). In that
case the container will not call onDataAvailable again and the container
will not read further data and back pressure will be put over TCP or HTTP2
flow control.
> I have to
> come up with a completely different interpretation with false changed to
> true. I
> agree it makes no sense to call onDataAvailable unless isReady() will
> return true, but
> this section of the spec previously made a much more important point than
> that.
I agree that the instant before onDataAvailable is called, a hyperthetical
call to isReady() would return true. But there is no requirement (and
little opportunity) for anything to call isReady() and get a true return.
In fact if isReady() has been called and returned false, it would be
dangerous for another thread to call isReady and proceed to do IO if it got
a true return, as it would be in a race with a call to onDataAvailable.
The only situation where a non-onDataAvailable dispatched thread can safely
call isReady and proceed to do IO is if a prior onDataAvailable call has
returned without calling isReady at all.
cheers
--
Greg Wilkins <gregw@webtide.com> CTO http://webtide.com