On 12 February 2018 at 18:56, Chris Hegarty <chris.hega...@oracle.com>

> James,
> On 10/02/18 07:38, James Roper wrote:
>> ...
>> https://developer.lightbend.com/blog/2018-02-06-reactive-str
>> eams-ee4j/index.html
> Regarding: https://github.com/jroper/reactive-streams-servlet/blob/7a2a
> 651b706bb0612f6d11311e442f82ce307ed2/reactive-streams-servle
> t/src/main/java/org/reactivestreams/servlet/RequestPublisher.java
> If I'm not mistaken, this appears to be mainly an adapter
> from Publisher of InputStream to Publisher of ByteBuffer.
> Did you overlook HttpRequest.BodyPublisher
> fromInputStream​(Supplier<? extends InputStream> streamSupplier)?
> Or did you run into some issue with it?

Hi Chris,

Not quite. RequestPublisher is an adapter of ServletInputStream to
Publisher, and the big difference here is that ServletInputStream has a
mechanism (introduced in Servlet 3.1) for doing non blocking IO, which is
handled by registering a ReadListener, which is not part of the InputStream
interface, but is part of the ServletInputStream interface.  Using this,
you use ServletInputStream.isReady to see if the stream is ready to return
data from ServletInputStream.read without blocking. If it is, you invoke
read, otherwise, you wait until ReadListener.onDataAvailable() is invoked,
and then you can invoke ServletInputStream.read without blocking again.

So the HttpRequest.BodyPublisher.fromInputStream, I presume, does blocking
IO on the InputStream (since InputStream only supports blocking IO), using
the blocking InputStream.read call, while RequestPublisher does non
blocking IO on ServletInputStream.



> -Chris.

*James Roper*
*Senior Octonaut*

Lightbend <https://www.lightbend.com/> – Build reactive apps!
Twitter: @jroper <https://twitter.com/jroper>

Reply via email to