One other comment, right now, given the way you wrote the code, no any specific improvement will be achieved

The JAX-RS runtime actually suspends the invocation immediately after the async method returns, so if you effectively block and resume immediately then it won't make a difference.

So try to do it the way is is documented or shown in the tests where you delegate the execution to a thread pool, and then resume async response when it is actually ready.

I'm not sure it makes sense to suspend before the method is entered by the current transport thread, the container won't free it before it returns from the method anyway...

I can only imagine it being effective if we combine it with the custom executors (can be configured on jaxrs/jaxws endpoints), where the invoking thread blocks when delegating to the custom executor, and where somehow this blocking thread is released when the continuation is suspended before the method is invoked, without awaiting for the return of the executor thread. This seems a bit hairy but might be worth exploring

Cheers, Sergey



On 13/02/14 10:08, Sergey Beryozkin wrote:
Hi, I guess you have not enabled the async support at the servlet level


Cheers, Sergey
On 13/02/14 09:37, Bhupesh Tuteja wrote:
Hi Sergey,

I tried this and getting following exception. It cannot get the
continuation
provider.

ERROR:2014-02-13 01:27:06.420:btpool0-0:"Exception handled at
ExceptionMapperProvider:
null":java.lang.NullPointerException:null:java.lang.NullPointerException
    at
org.apache.cxf.jaxrs.impl.AsyncResponseImpl.initContinuation(AsyncResponseImpl.java:240)

    at
org.apache.cxf.jaxrs.impl.AsyncResponseImpl.<init>(AsyncResponseImpl.java:58)

    at
org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameter(JAXRSUtils.java:767)

    at
org.apache.cxf.jaxrs.utils.JAXRSUtils.processParameters(JAXRSUtils.java:741)

    at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.processRequest(JAXRSInInterceptor.java:263)

    at
org.apache.cxf.jaxrs.interceptor.JAXRSInInterceptor.handleMessage(JAXRSInInterceptor.java:103)

    at
org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:272)

    at
org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)

    at
org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:239)

    at
org.apache.cxf.transport.servlet.ServletController.invokeDestination(ServletController.java:248)

    at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:222)

    at
org.apache.cxf.transport.servlet.ServletController.invoke(ServletController.java:153)

    at
org.apache.cxf.transport.servlet.CXFNonSpringServlet.invoke(CXFNonSpringServlet.java:167)

    at
org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:286)

    at
org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:206)

    at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
    at
org.apache.cxf.transport.servlet.AbstractHTTPServlet.service(AbstractHTTPServlet.java:262)

    at
org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
    at
org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
    at
org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)

    at
org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
    at
org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:726)
    at
org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
    at
org.mortbay.jetty.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:206)

    at
org.mortbay.jetty.handler.HandlerCollection.handle(HandlerCollection.java:114)

    at
org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:324)
    at
org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
    at
org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)

    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:648)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
    at
org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)

    at
org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)



My code snippet looks like this.

public void postSomething(final AsyncResponse async) {

        async.setTimeout(1, TimeUnit.MILLISECONDS);
        async.setTimeoutHandler(new TimeoutHandler() {

            @Override
            public void handleTimeout(AsyncResponse asyncResponse) {

                                         //I have put my service impl
code
here

                                        Collection<XYZ> response = get
response();
                       async.resume(response);
                }

            }
        });
    }





--
View this message in context:
http://cxf.547215.n5.nabble.com/Server-Side-Asynchronous-processing-support-via-CXF-NIO-support-tp5739791p5739911.html

Sent from the cxf-user mailing list archive at Nabble.com.




--
Sergey Beryozkin

Talend Community Coders
http://coders.talend.com/

Blog: http://sberyozkin.blogspot.com

Reply via email to