You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Eng-list <en...@Xiotech.com> on 2005/12/13 00:10:13 UTC

Need way to cancel an operation

Hi,
 
I have a Java client application that performs an operation in a Java
SwingWorker thread.  From the GUI thread I want to allow the user to
cancel the operation if the cancel button is pressed.  I don't see a way
to send down a cancel command by way of Stub, AxisEngine, Service, ...
How can a cancel operation be performed?
 
Thanks in advance,
 
-Kevin

Re: Need way to cancel an operation

Posted by Wade Chandler <hw...@yahoo.com>.
--- Eng-list <en...@Xiotech.com> wrote:

> Hi,
>  
> I have a Java client application that performs an
> operation in a Java
> SwingWorker thread.  From the GUI thread I want to
> allow the user to
> cancel the operation if the cancel button is
> pressed.  I don't see a way
> to send down a cancel command by way of Stub,
> AxisEngine, Service, ...
> How can a cancel operation be performed?
>  
> Thanks in advance,
>  
> -Kevin
> 

I have had the same problem.  I ended up using a big
no no for now: Thread.stop() and making calls from a
separate thread in the client.  To be able to do this
clean you would have to copy HTTPSender (I'm assuming
you're using http calls), hack Axis to use this class,
and have checks all through out the class.  I didn't
even bother getting into which classes I would want to
access, but I'm thinking Boolean cancelled =
call.getMessageContext().getProperty(CancellableHTTPSender.PROP_CANCELLED);
cancelled.booleanValue(); would do the trick...notice
the non-existent CancellableHTTPSender (could create
this).  Then from inside of there you would have to
constantly check the MessageContext for the property
and bounce out of the code.  Look in HTTPSender...it
really would not be that hard to do.  

A better way would be to add a property to
MessageContext
setCancelled(boolean),isCancelled()...maybe add it to
the interface, and then all the other classes could
use it [check the value from inside of HTTPSender and
kick out if it's cancelled].  This really needs to be
something included in Axis.  I mean, you start
streaming out the request from the client...you can
easily cancel  here or you are reading the response ..
can cancel there...or you are waiting on the response
to start streaming back from the
URLConnectionStream....interrupt the current thread to
make it throw out an exception from here to get out of
the blocking method [I think an interrupt on the
current thread will break a blocking method
call..depends on how it is polling]  That's just an
off the top of my head type of thing though.  It's
more complicated and needs thought through.  Like, if
there is processing on the "backend" you might or
might not want to cancel this processing depending on
how your web service operates.  So, there are issues
involved, and sometimes you can't just make the client
fall off the map and leave the server running it's
process, but in most cases you should be able to and
if it's a complicated backend cancel thing maybe we
could just leave that up to the web service author.

Wade