Hi
I'd like to continue the discussion on how to handle Jetty continuations[1] in
CXF[2] here.
In short the requirement is for CXF to be able to handle the application code
(ServiceMix JBI consumers served by ServiceMix CXF BindingComponent in this
case) doing explicit continuations.
Ex. CXF receives a request on a Jetty thread, creates an exchange and sends it
further along to the consumer. Consumer is about to do some work so it spawns
some activity or checks for some event and then does continuation.suspend().
This results in a specific Runtime exception being thrown.
The challenge is how to 'suspend' the interception chain, let this exception
propagate down to the Jetty stack so that it can free the thread and put this
pending request in its internal queue, and then resume it when a consumer code
decides to do continuation.resume().
See [3] for a more detailed description of the issues.
Dan, here're some comments :
1. "something would need to be done to allow the "suspend" exception thing to
propogate up,
but without taking a jetty dependency into the core."
I guess the basic thing we can do is to check the class name of the exception
(like exception.getClass().equals("JettyException")), and if it matches the
expected name then we can wrap up this exception in a SuspendedFault exception,
to be recognized by the rest of CXF runtime
2. Now, if the above can be figured out, the next problem arises: when
the "trigger" to wake up the continuation occurs
I think we can can do in JettyDestination omething similar to what is done in
SMX. When getting a SuspendedFault exception, we can extract from it the
original continuation instance or else we can do
ContinuationSupport.getContinuation(request) which should return us the
instance. At this point we can use it as a ket to store the current exchange
plus all the other info we may need.
When the user/application code does continuation.resume(), the Jetty thread
will come back and we will use the ContinuationSupport.getContinuation(request)
to get us the active continuation and use it to extract the suspended exchange
and proceed from there, say we'll call PhaseInterceptorPhase.resume(), etc,
something along the lines you suggested
3. Basically, to do this "right", we'd need to audit pretty much everything to
make sure nothing is stored on the stack and is "resumable". Once that is
done, the rest is relatively easy.
Yea - probably can be the quite challenging
Thoughts ?
Cheers, Sergey
[1] http://docs.codehaus.org/display/JETTY/Continuations
[2] https://issues.apache.org/jira/browse/CXF-1835
[3]
https://issues.apache.org/jira/browse/CXF-1835?focusedCommentId=12642361#action_12642361