Thanks, but any idea why my service is throwing null pointer exception below. CXF servlets in web.xml is configured with asynchronous support.
Sent from my iPad > On Feb 14, 2014, at 5:06 AM, Sergey Beryozkin <[email protected]> wrote: > > CC-ing to the users >> On 14/02/14 13:05, Sergey Beryozkin wrote: >> Hi Bhupesh >>> On 14/02/14 08:55, [email protected] wrote: >>> Hi Sergey, >>> >>> Here is my what I am trying to do and you can tell me if it makes >>> sense or not as I am new to this NIO concept. >>> >>> I have implemented a REST service running on Tomcat (7.0.23) and Jetty >>> (6.1.10) using JAXRS, servlet-api 2.5, CXF 2.7.7 and camel 2.10.0. My >>> service is an orchestrator that is mostly IO bound and talks to many >>> REST services. My requirement is to scale my service to the extreme >>> level and get milliseconds SLA. >>> >>> After reading about NIO and async support in servlet 3.0, I thought of >>> two things that can probably benefit my service. >>> 1. When the request thread takes control of handling the request, it >>> calls camel route that uses multicast pattern. I will execute the >>> camel route in async thread and return the request thread to the >>> thread pool so that it can handle other waiting requests. >>> >>> 2. During I/O with other services, I want to read the responses in a >>> non-blocking way. >>> >>> Given your experience with NIO and async processing, can you tell if I >>> am marching in the right direction? >> I've no specific NIO experience, hope it won;t disappoint you too much >> :-), well, I did write some NIO awhile back, mostly related to the File >> processing which is rather orthogonal to processing IO requests. >> >> But I believe that for you to get the most of it and of async support in >> particular *in CXF* you should have your resource methods immediately >> delegate to the executor for the container to immediately reuse the >> transport thread while the service does some work, and then when it's >> done, resume AsyncResponse >> >> Thanks, Sergey >> >>> Thanks, >>> Bhupesh >>> >>> <quote author='Sergey Beryozkin'> >>> 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
