2014/1/8 Daniel Mikusa <dmik...@gopivotal.com>:
> On Jan 8, 2014, at 12:04 PM, Yann Simon <yann.simon...@gmail.com> wrote:
>
>> Hi,
>>
>> I am trying to write a servlet that asynchronously read data from the
>> servlet request input stream.
>> I tested my servlet with tomcat 8.0.0-RC5.
>
> If possible, you might want to try 8.0.0-RC10 or trunk and see if you're 
> getting the same behavior.
>
>>
>> the symptoms:
>> - I must synchronously read the input stream in onDataAvailable() so
>> that the upload works
>>
>> what I expected:
>> I want to be more "reactive" (buzzword of the moment) and not read the
>> input stream until I am ready (=until the previous chunk is processed)
>> I though I could return from onDataAvailable() before having read all
>> the data, read the data in another thread.
>
> Do you have a code sample?  It would help to see what you're doing.
>
>> I expected onDataAvailable() to be called again when I consumed all the data
>> (servletInputStream.isReady becomes false)
>
> Generally this sounds OK.  When you call ServletInputStream.isReady() and it 
> returns false, that should trigger the container to call onDataAvailable() 
> when more data is available to be read.  If you return from onDataAvailable() 
> and ServletInputStream.isReady() is still true the container won't call 
> onDataAvailable() again.  You'll be responsible for calling it when you're 
> ready to read more.
>
>> That way, I could implement back pressure on the browser as long as my
>> servlet has not finished its work with the actual chunk
>>
>> But if I do that, neither onDataAvailable() nor onAllDataRead() is called 
>> again.
>
> Again, a code sample would be helpful.  Debugging non-blocking IO is tricky.  
> If you can include a sample Servlet or test case, it would greatly increase 
> your chance of getting feedback.

Thanks for the quick answer!

I have a code sample, but it may be too complicated to help debugging
the problem.
It is written in Scala. Its purpose is to provide a servlet that runs
asynchronous action from Playframework (http://www.playframework.com/)

https://github.com/yanns/play2-war-plugin/blob/servlet31/project-code/core/servlet31/src/main/scala/play/core/server/servlet31/RequestHandler31.scala#L74

The line 80 (iteratee = iteratee.pureFlatFold ) use a closure that
consumes the input stream asynchronously in another thread.

I'll try to take the time to write a much simpler code sample in Java.

>
> Dan
>
>>
>> When I consume the input stream synchronously in onDataAvailable(), it
>> works as expected.
>>
>> Am I misunderstanding the asynchron IO in Tomcat 8?
>>
>> Thanks in advance for any ideas!
>> Yann
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
> For additional commands, e-mail: users-h...@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to