On 12 February 2018 at 18:56, Chris Hegarty <chris.hega...@oracle.com>
> On 10/02/18 07:38, James Roper wrote:
> Regarding: https://github.com/jroper/reactive-streams-servlet/blob/7a2a
> 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?
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.
Lightbend <https://www.lightbend.com/> – Build reactive apps!
Twitter: @jroper <https://twitter.com/jroper>