You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cxf.apache.org by Sergey Beryozkin <sb...@gmail.com> on 2010/11/22 18:56:56 UTC

SuspendedInvocationException is lost during continuation.suspend()

Hi

I've found out, while working with CXF Continuations API recently is that

continuation.suspend()

is returning normally and no SuspendedInvocationException is thrown.

This is unexpected in that now, when continuation.suspend() is used directly
in the application code, the explicit 'return' has to be added.
This is not too bad when it is done immediately in the top-level service
object but if it happens in one of the sub-routines we are effectively have
no way of
knowing at the start of the call if it was suspended or not, unless we use
check the status explicitly :

Ex :

public void soapMethod() {
   doIt();

   if (!continuation.isPending()) {
       dontDoItIfSuspended();
   }
}

private void doIt() {
    continuation.suspend();
}

Willem - is it how the explicit continuations code has to be written now ?

thanks, Sergey

Re: SuspendedInvocationException is lost during continuation.suspend()

Posted by Daniel Kulp <dk...@apache.org>.
Just a quick note that the  new behavior more closely matches the behavior of 
the Async capabilities of the Servlet 3.0 spec.   Longer term, as we move to 
Jetty 8, we should be able to just use the Servlet 3 AsyncContext support for 
this and simplify the code a bit.

Dan



On Tuesday 23 November 2010 7:04:10 am Sergey Beryozkin wrote:
> Hi Willem
> 
> thanks for the explanation. It makes sense.
> 
> However, when a user calls, for ex,
> 
> continuation.suspend(60)
> 
> there is no need to register a handler. This is a different kind of flow
> where a handler is registered and then that handler calls
> continuation.resume(). When we do
> 
> continuation.suspend(60)
> 
> we actually expect an invocation come back to us in the resumed state with
> the runtime itself initiating a resume event. I do not need to add a
> handler. I can check if some condition has been met when the invocation
> comes back.
> 
> It is unfortunate Continuation is the interface otherwise we could add a
> method like suspendImmediately() may be.
> 
> The Jetty wiki is showing
> 
> continuation.suspend()
> 
> which is the indefinite suspend thus there's a need there to wake up the
> pending thread from the application code.
> 
> That said, having both timed suspends and async resumes at the same time
> makes sense too.
> 
> Basically, having an explicit return is not a big issue, but it can make
> the user code a bit more involved.
> 
> cheers, Sergey
> 
> On Tue, Nov 23, 2010 at 4:52 AM, Willem Jiang <wi...@gmail.com>wrote:
> > On 11/23/10 1:56 AM, Sergey Beryozkin wrote:
> >> Hi
> >> 
> >> I've found out, while working with CXF Continuations API recently is
> >> that
> >> 
> >> continuation.suspend()
> >> 
> >> is returning normally and no SuspendedInvocationException is thrown.
> >> 
> >> This is unexpected in that now, when continuation.suspend() is used
> >> directly
> >> in the application code, the explicit 'return' has to be added.
> >> This is not too bad when it is done immediately in the top-level service
> >> object but if it happens in one of the sub-routines we are effectively
> >> have
> >> no way of
> >> knowing at the start of the call if it was suspended or not, unless we
> >> use check the status explicitly :
> >> 
> >> Ex :
> >> 
> >> public void soapMethod() {
> >> 
> >>    doIt();
> >>    
> >>    if (!continuation.isPending()) {
> >>    
> >>        dontDoItIfSuspended();
> >>    
> >>    }
> >> 
> >> }
> >> 
> >> private void doIt() {
> >> 
> >>     continuation.suspend();
> >> 
> >> }
> >> 
> >> Willem - is it how the explicit continuations code has to be written now
> >> ?
> >> 
> >>  Yes, that is what I want to do in CXF 2.3.0.
> > 
> > In this way we can implement suspend resume pattern[1] easily as Jetty 7
> > does.
> > 
> > The main reason that continuation.suspend() does not return immediately
> > is letting the user have chance to setup the callback method for
> > contination resuming. In this way we can make sure the
> > continuation.resume() will never be called before the
> > continuation.suspend.
> > 
> >  thanks, Sergey
> >  
> >>  [1]
> > 
> > http://wiki.eclipse.org/Jetty/Feature/Continuations#Suspend_Resume_Patter
> > n
> > 
> > --
> > Willem
> > ----------------------------------
> > FuseSource
> > Web: http://www.fusesource.com
> > Blog:    http://willemjiang.blogspot.com (English)
> > 
> >         http://jnn.javaeye.com (Chinese)
> > 
> > Twitter: willemjiang

-- 
Daniel Kulp
dkulp@apache.org
http://dankulp.com/blog

Re: SuspendedInvocationException is lost during continuation.suspend()

Posted by Sergey Beryozkin <sb...@gmail.com>.
Hi Willem

thanks for the explanation. It makes sense.

However, when a user calls, for ex,

continuation.suspend(60)

there is no need to register a handler. This is a different kind of flow
where a handler is registered and then that handler calls
continuation.resume(). When we do

continuation.suspend(60)

we actually expect an invocation come back to us in the resumed state with
the runtime itself initiating a resume event. I do not need to add a
handler. I can check if some condition has been met when the invocation
comes back.

It is unfortunate Continuation is the interface otherwise we could add a
method like suspendImmediately() may be.

The Jetty wiki is showing

continuation.suspend()

which is the indefinite suspend thus there's a need there to wake up the
pending thread from the application code.

That said, having both timed suspends and async resumes at the same time
makes sense too.

Basically, having an explicit return is not a big issue, but it can make the
user code a bit more involved.

cheers, Sergey

On Tue, Nov 23, 2010 at 4:52 AM, Willem Jiang <wi...@gmail.com>wrote:

> On 11/23/10 1:56 AM, Sergey Beryozkin wrote:
>
>> Hi
>>
>> I've found out, while working with CXF Continuations API recently is that
>>
>> continuation.suspend()
>>
>> is returning normally and no SuspendedInvocationException is thrown.
>>
>> This is unexpected in that now, when continuation.suspend() is used
>> directly
>> in the application code, the explicit 'return' has to be added.
>> This is not too bad when it is done immediately in the top-level service
>> object but if it happens in one of the sub-routines we are effectively
>> have
>> no way of
>> knowing at the start of the call if it was suspended or not, unless we use
>> check the status explicitly :
>>
>> Ex :
>>
>> public void soapMethod() {
>>    doIt();
>>
>>    if (!continuation.isPending()) {
>>        dontDoItIfSuspended();
>>    }
>> }
>>
>> private void doIt() {
>>     continuation.suspend();
>> }
>>
>> Willem - is it how the explicit continuations code has to be written now ?
>>
>>  Yes, that is what I want to do in CXF 2.3.0.
> In this way we can implement suspend resume pattern[1] easily as Jetty 7
> does.
>
> The main reason that continuation.suspend() does not return immediately is
> letting the user have chance to setup the callback method for contination
> resuming. In this way we can make sure the continuation.resume() will never
> be called before the continuation.suspend.
>
>  thanks, Sergey
>>
>>  [1]
> http://wiki.eclipse.org/Jetty/Feature/Continuations#Suspend_Resume_Pattern
>
> --
> Willem
> ----------------------------------
> FuseSource
> Web: http://www.fusesource.com
> Blog:    http://willemjiang.blogspot.com (English)
>         http://jnn.javaeye.com (Chinese)
> Twitter: willemjiang
>

Re: SuspendedInvocationException is lost during continuation.suspend()

Posted by Willem Jiang <wi...@gmail.com>.
On 11/23/10 1:56 AM, Sergey Beryozkin wrote:
> Hi
>
> I've found out, while working with CXF Continuations API recently is that
>
> continuation.suspend()
>
> is returning normally and no SuspendedInvocationException is thrown.
>
> This is unexpected in that now, when continuation.suspend() is used directly
> in the application code, the explicit 'return' has to be added.
> This is not too bad when it is done immediately in the top-level service
> object but if it happens in one of the sub-routines we are effectively have
> no way of
> knowing at the start of the call if it was suspended or not, unless we use
> check the status explicitly :
>
> Ex :
>
> public void soapMethod() {
>     doIt();
>
>     if (!continuation.isPending()) {
>         dontDoItIfSuspended();
>     }
> }
>
> private void doIt() {
>      continuation.suspend();
> }
>
> Willem - is it how the explicit continuations code has to be written now ?
>
Yes, that is what I want to do in CXF 2.3.0.
In this way we can implement suspend resume pattern[1] easily as Jetty 7 
does.

The main reason that continuation.suspend() does not return immediately 
is letting the user have chance to setup the callback method for 
contination resuming. In this way we can make sure the 
continuation.resume() will never be called before the continuation.suspend.

> thanks, Sergey
>
[1] 
http://wiki.eclipse.org/Jetty/Feature/Continuations#Suspend_Resume_Pattern

-- 
Willem
----------------------------------
FuseSource
Web: http://www.fusesource.com
Blog:    http://willemjiang.blogspot.com (English)
          http://jnn.javaeye.com (Chinese)
Twitter: willemjiang