Async REST support
Updated 1 year, 10 months ago
| Marius Danciu | Reviewers | ||
| 401 | dpp, marius, charles, joni, atsuhiko, jorge, naftoli, kris, indrajit, alexb, dlouwers, mstarzyk, rmellgren, jhoffman, probinett, jmadsen, mhartmann, jstrachan, jgoday | ||
| None | LiftWeb-archive | ||
Some details are here: https://www.assembla.com/spaces/liftweb/tickets/401?batch=false&tickets_report_id=1&ticket_id=401&commit=Go+ยป
but I adopted a slightly different API. The way to use it is:
val continuation: LiftRules.DispatchPF = {
case Req("cont" :: rest, _, _) => {
S.respondAsync {responseFunc =>
Thread.sleep(20000) // some computation here
responseFunc(Full(XmlResponse(<async>response</async>)))
}
}
}
LiftRules.dispatch.append(continuation);
The point is that you pass to respondAsync a function that takes a single argument. This is the function that you need to call to send down the response asynchronously. Once the response is sent to client the next subsequent request will cause your function to be called again. If the container does not support the continuation idiom then locking is utilized and a thread is being held until the response is ready or timeout occurs (... you know the story).
testted with Jeyy 6, jetty 7 and with non continuations support.
Posted 1 year, 10 months ago (March 27th, 2010, 10:52 p.m.)
Actually I'll try to simplify the API a bit more ...
Review request changed
Updated 1 year, 10 months ago (March 28th, 2010, 12:21 a.m.)
-
- added Diff r2
ok .. made it simpler:
val continuation: LiftRules.DispatchPF = {
case Req("cont" :: rest, _, _) => {
S.respondAsync {
Thread.sleep(20000) // some computation here
Full(XmlResponse(<async>response</async>))
}
}
}
LiftRules.dispatch.append(continuation);
Posted 1 year, 10 months ago (March 29th, 2010, 1:21 a.m.)
Nice! Does the implementor need to create their own handler for object delta's and such?
Posted 1 year, 10 months ago (March 30th, 2010, 2:34 a.m.)
Any other opinions?
Code looks good to me, though I confess I'm not that familiar with the continuations API. I found some minor typos in doc comments and a bit of indentation oddness.
-
framework/lift-base/lift-webkit/src/main/scala/net/liftweb/http/S.scala (Diff revision 2) -
asyynchronously -> asynchronously
-
framework/lift-base/lift-webkit/src/main/scala/net/liftweb/http/S.scala (Diff revision 2) -
functino -> function
-
continuztion -> continuation
-
asyynchronously -> asynchronously
-
functino -> function
-
body should be indented
-
indented one column too many
-
body should be indented
