<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div>Let me play with your use case, although it will be a few hours before I can get to it.</div><div><br></div><div>There are some limitations to the spec, but they are manageable. As an example the write is actually written for you in a non blocking fashion. It's basically an async deferred write. </div><div><br></div><div>The undertow http handler API is, in my opinion a much better fit for pure non-blocking / reactive applications. </div><div><br>On Apr 3, 2014, at 9:52 AM, Przemyslaw Bielicki <<a href="mailto:pbielicki@gmail.com">pbielicki@gmail.com</a>> wrote:<br><br></div><blockquote type="cite"><div><div dir="ltr"><div><div>As I showed I'm not able to read and write at the same time using non-blocking IO, as promised by Servlet 3.1. I'm able to read using non-blocking IO but my writes are blocking and I'm looking for the solution.<br>
<br>Regarding concurrent access, HTTP Upgrade promises that the upgraded protocol will be full-duplex, so I should be able to read and write concurrently but I'm not.<br></div><br>Another comment is that Servlets 3.1 is actually async ONLY from the server point of view - the client is still blocked because HTTP 1.1 is synchronous (we have to wait for HTTP 2.0 to solve this). Here Upgrade should help as it is a pure TCP, so I'm the master of my protocol and I'm no longer bound to HTTP - I can be as asynchronous as I want. Unfortunately Servlet 3.1 API does not respect this.<br>
<br></div>It looks like the specification is not meeting the promises given....<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 3, 2014 at 4:41 PM, Rémy Maucherat <span dir="ltr"><<a href="mailto:rmaucher@redhat.com" target="_blank">rmaucher@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 03/04/2014 15:21, Przemyslaw Bielicki wrote:<br>
> I tried - exactly the same results.<br>
><br>
> Another weird observation is that ServletOutputStream.isReady() is<br>
> returning true even after the connection is closed<br>
> (ServletInputStream.isFinished() is correctly returning true).<br>
><br>
> Here's the scenario that works but I can write back the data only once:<br>
> 1. In HttpUpgradeHandler I set only the ReadListener<br>
> 2. I switch the protocol and send some data<br>
> 3. ReadListener gets activated i.e. onDataAvailable() is called.<br>
> 4. I process the input data, read as much as possible and put the<br>
> input into the queue<br>
> 5. From within ReadListener I set the WriteListener<br>
> 6. WriteListener.onWritePossible() gets called and I process the data<br>
> - I clean the queue<br>
> 7. As long as I'm in WriteListener.onWritePossible()<br>
> (while.out.isReady() is constantly returning true, which is a correct<br>
> bahavior) the ReadListener is on-hold. I can send as much data as I<br>
> like but onDataAvailable() is not called<br>
> 8. Only when I leave WriteListener.onWritePossible() method the<br>
> ReadListener.onDataAvailable() is called again and I can consume the<br>
> input data again.<br>
> 9. I can process the input data again i.e. put it into the queue but<br>
> WriteListener.onWritePossible() is never called again. When I try to<br>
> reset it I get IllegalStateException<br>
><br>
> Either the specification or implementation seem not very mature....<br>
> Wildfly behavior is consistent with the one of Tomcat.<br>
><br>
> At the moment I conclude that the non-blocking write is not possible<br>
> in Servlet 3.1.<br>
><br>
> I would appreciate if someone can provide an example that actually<br>
> works or explain why the weird behavior I observe is correct (is it?)<br>
</div></div>This looks as expected (although Tomcat 8 should concurrently call<br>
read/write in upgraded mode, as a proprietary extension to be able to<br>
implement Websockets on top of Servlets 3.1, besides that Servlet 3.1 is<br>
still not concurrent, so at most one thread processing a request a given<br>
time).<br>
<br>
Non blocking IO means it allows avoiding to block on IO, it doesn't<br>
imply anything else. Servlets 3.1 is actually async IO (similar to NIO2,<br>
rather than NIO1), since non blocking IO is unusable as is.<br>
<span class="HOEnZb"><font color="#888888"><br>
Rémy<br>
</font></span><div class="HOEnZb"><div class="h5"><br>
_______________________________________________<br>
wildfly-dev mailing list<br>
<a href="mailto:wildfly-dev@lists.jboss.org">wildfly-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/wildfly-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/wildfly-dev</a><br>
</div></div></blockquote></div><br></div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>wildfly-dev mailing list</span><br><span><a href="mailto:wildfly-dev@lists.jboss.org">wildfly-dev@lists.jboss.org</a></span><br><span><a href="https://lists.jboss.org/mailman/listinfo/wildfly-dev">https://lists.jboss.org/mailman/listinfo/wildfly-dev</a></span></div></blockquote></body></html>