Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-dev] Continuation considerations - the exception?


All,

I don't know if you've yet had a chance to consider the changes to the continuation APIs in
Jetty-7 - but I encourage you to do so, specially as I'd appreciate some feedback on some of
the architectural changes that I'm putting through.


In jetty-6 one of the contentious features of continuations were that they threw
and exception when suspend was call.  This RetryException (now extending ThreadDeath)
was a very good way to exit the calling chain of filters and servlets.  However
it does encourage a race condition in code like:

     Continuation continuation = ContinuationSupport.getContinuation(request,null);
     myAsyncService.register(continuation);
     continuation.suspend();  // exception thrown


The race is possible if the async event happens between the execution of the register
and the suspend! making it possible for a resume to be attempted before the request
is suspended.  To avoid this, synchronization and/or fancy finally blocks are needed.


With jetty-7 continuations, these have been brought more in line with the proposed
async API of servlet 3.0. Suspend no longer throws an exception, but simply changes
the state of the request.   So the above code needs to be rewritten:

     Continuation continuation = ContinuationSupport.getContinuation(request,null);
     continuation.suspend();
     myAsyncService.register(continuation);
     return;

This avoids the race (and much of the criticism that centred on the  exception).


However, for many existing frameworks, return is not a sufficient mechanism to
return the request to the container without something trying to commit the
response.    For servlet 3.0 this is not such an issue, because every filter
and servlet in the calling chain needs to be flagged as supporting async
and thus needs to be aware that an async request should not be committed.

But Jetty-7 continuations are designed to work with jetty-6, jetty-7, any
3.0 container plus any 2.5 container (with blocking).   Thus I'm currently
pondering if we should optionally support the throwing of an ContinuationException
as follows:

     Continuation continuation = ContinuationSupport.getContinuation(request,null);
     continuation.suspend();
     myAsyncService.register(continuation);
     continuation.return(); // throws a ContinuationException

Is this understandable code?

thoughts comments?




























Back to the top