Main Page   Namespace List   Class Hierarchy   Compound List   Namespace Members   Compound Members  

CancelableTask Class Reference

#include <CancelableTask.h>

Inheritance diagram for CancelableTask:

Runnable Cancelable List of all members.

Public Methods

 CancelableTask ()
 Create a CancelableTask.

virtual ~CancelableTask () throw ()
 Destroy the CancelableTask.

virtual void cancel ()
virtual bool isCanceled ()
virtual void run () throw ()

Protected Methods

virtual void doRun ()=0 throw ()

Detailed Description

Author:
Eric Crahen <crahen@cse.buffalo.edu>
Date:
<2002-06-02T11:24:17-0400>
Version:
2.2.1
A CancelableTask can be used to create a task with its own Cancelable semantics. Instead of implementing the run() method as you normally would for a Runnable object, implement the doRun() method instead.

Disabling

A cancel()ed CancelableTask will not execute if is is canceled prior to being run(). If it is canceled while it is running, the thread executing the task will be interrupted. This gives the executing task a chance to respond to being canceled.

Exiting

A canceled task should exit cleanly and quickly. Depending on the task this may involve rolling back to some previous state, updating a log, etc. Its up to the specific task to decide how to best handle being canceled during execution.

See also:
cancel() , Cancelable


Member Function Documentation

virtual void cancel   [inline, virtual]
 

Cancel this task. This will be successful only once, cancel()ing multiple times will result in an exception.

A task that has been canceled will not run. A task that is executing will be interrupted.

Exceptions:
InvalidOp_Exception  thrown if the task is canceled more than once.
Postcondition:
it is possible for an interrupted task not to clear the executing thread's interrupted status (it may not check Thread::interrupted() or it may not use blocking operations). Executors will not be affected by this by design; a good way to avoid problems this may cause is to check Thread::canceled() if you plan on repeated running tasks. This allows the executing thread to distinguish between an interrupt from being cancel()ed and an interrupt() left over from a CancelableTask.

Implements Cancelable.

virtual void doRun   throw () [protected, pure virtual]
 

Specializations of this class must define this method. It is called when a CancelableTask that has not been canceled is run().

See also:
Runnable::run()

virtual bool isCanceled   [inline, virtual]
 

Check the canceled status of this task.

Returns :
bool true if the task has been canceled

Implements Cancelable.

virtual void run   throw () [inline, virtual]
 

A CancelableTask will run only if it has not been canceled prior to calling this function. If the task has not been canceled at the time this function is called, then doRun() is executed.

Implements Runnable.


The documentation for this class was generated from the following file:
Generated on Tue Aug 27 07:43:11 2002 for ZThread by doxygen1.2.17