tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel Mikusa <dmik...@gopivotal.com>
Subject Tomcat 8 / Non Blocking IO
Date Wed, 07 Aug 2013 15:14:16 GMT
I have a questions regarding the Non Blocking API introduced in Tomcat 8.

I'm looking at the TestNonBlockingAPI test as an example, specifically the NBReadServlet class.

@WebServlet(asyncSupported = true)
public class NBReadServlet extends TesterServlet {
    private static final long serialVersionUID = 1L;
    public volatile TestReadListener listener;
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
        // step 1 - start async
        AsyncContext actx = req.startAsync();
        actx.setTimeout(Long.MAX_VALUE);
        actx.addListener(new AsyncListener() {
            // removed for brevity 
        });
        // step 2 - notify on read
        ServletInputStream in = req.getInputStream();
        listener = new TestReadListener(actx);
        in.setReadListener(listener);

        listener.onDataAvailable();
    }
}

My question is why does the test call "listener.onDataAvailable()" at the end?

In regards to the "onDataAvailable()" method, Section 3.7 of the spec says…

"The onDataAvailable method is invoked on the ReadListener when data is available to read
from the incoming request stream. The container will invoke the method the first time when
data is available to read. The container will subsequently invoke the onDataAvailable method
if and only if isReady method on ServletInputStream, described below, returns false."

...which leads me to believe that the container should be calling onDataAvailable and not
the servlet.

As a side note, my test works if I call "onDataAvailable()" from my test servlet.  Otherwise
it fails and times out.

Thanks

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


Mime
View raw message