Re: [jetty-user] questions on the asynch nio and does framework support it
Jesse McConnell <[email protected]> Fri, 9 Sep 2011 10:20:27 -0500
| Newsgroups | gmane.comp.java.jetty.support |
|---|---|
| Message-ID | <CAPHPUsJf=S-j7dT8L=MSLU=JpOTH0GiGaEdQn2jF1WqoqExGiw@mail.gmail.com> |
Yes you should be able to do something like this if I follow your line of thinking, take a look at jetty continuations for servlet 2.5 and these sorts of async behaviors are built into servlet 3.0 http://wiki.eclipse.org/Jetty/Feature/Continuations cheers and good luck :) jesse -- jesse mcconnell [email protected] http://webtide.com / http://intalio.com (the folks behind jetty and cometd) On Fri, Sep 9, 2011 at 10:11, Dean Hiller <[email protected]> wrote: > We would like to do something like the below. Is this possible with jetty > and the nio implementation? > > doGet(ServletReq req, ServletResp servletResponse) { > noSqlDatabase.asynchRead(keys, new CallbackForRead(servletResponse)); > } > > CallbackForRead implements NoSqlReadCallback { > private ServletResponse resp; > public CallbackForRead(ServletResponse r) { resp = r; } > public void dataRead(Data data) { > String response = formResponse(data); > resp.write(response); > } > } > > NOTE: The jetty thread that fed us the request RETURNS while we wait for a > response from the nosql database or any external system for that matter. > When we are fed back the response of data, we are on a different thread but > want to feed the servlet response back into the ServletResponse object(ie. > the socket for the client is still open even though the thread returned). > > Why? Well, it turns out we can use 10x less servers in this model because > existing threads can be used which eliminates alot of cost as we can use 1 > server instead of 10. The 10x number varies greatly depending on the > network latency to the back end system whether database or DNS....the more > latency the 10x number can increase even more significantly but 1 computer > instead of 10 is already a really nice savings $$$$$. > > thanks, > Dean > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email