On Jan 23, 2008 7:04 PM, Rob Heittman <[EMAIL PROTECTED]> wrote:
> Getting full value out of asynchronous calls will clearly involve a lot of
> careful work across the RI and extensions. It would be a great opportunity
> to apply correct and modern Java concurrency patterns -- I hope Tim Peierls
> is listening -- and if done right, this would really demonstrate "why
> Restlet."
I *am* listening ... I am also torn. One of the things that attracted me to
Restlet was its simplicity: everything in terms of handle(Request,
Response). I hate to muddy those waters.
But assuming the waters are to be muddied, I like the callback approach.
When you supply a callback via handle(req, rsp, cb), you're saying that it's
OK for handle to return immediately, that you understand that handling has
not necessarily completed.
It's probably best in that case for handle to return a Future-like object
that lets you wait for completion or cancel. Then Restlets that implement
asynchronous handle could use a common default implementation of synchronous
handle like this:
/** Convert asynch handling into synch. */
void handle(Request request, Response response) {
Future<?> f = handle(request, response, nullCallback); // returns
immediately
try {
f.get(); // wait for completion
} // usual catch clauses for Future.get() go here
}
There need to be thread-safe versions of Request and Response for any of
this to work.
I should probably put these and future comments in the issue tracker, but
for which issue,
asynchronous<http://restlet.tigris.org/issues/show_bug.cgi?id=143>or
GWT <http://restlet.tigris.org/issues/show_bug.cgi?id=127>?
--tim