[jetty-user] questions on the asynch nio and does framework support it
Dean Hiller <[email protected]> Fri, 9 Sep 2011 09:11:31 -0600
| Newsgroups | gmane.comp.java.jetty.support |
|---|---|
| Message-ID | <CAAtG5j6RAeMZD7gakbskzZSb-JAc_f43jc2_yUvGt2k-PW4UXA@mail.gmail.com> |
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