activemq-cpp-3.6.0
decaf::util::concurrent::FutureTask< T > Class Template Reference

A cancellable asynchronous computation. More...

#include <src/main/decaf/util/concurrent/FutureTask.h>

Inheritance diagram for decaf::util::concurrent::FutureTask< T >:

Data Structures

class  FutureTaskAdapter
 A Callable subclass that runs given task and returns given result, used to wrap either a Runnable or Callable pointer and.
class  FutureTaskSync
 Synchronization control for FutureTask.

Public Member Functions

 FutureTask (Callable< T > *callable, bool takeOwnership=true)
 Creates a FutureTask instance that will, upon running, execute the given Callable.
 FutureTask (decaf::lang::Runnable *runnable, const T &result, bool takeOwnership=true)
 Creates a FutureTask that will, upon running, execute the given Runnable, and arrange that the get method will return the given result on successful completion.
virtual ~FutureTask ()
virtual bool isCancelled () const
 Returns true if this task was canceled before it completed normally.
virtual bool isDone () const
 Returns true if this task completed.
virtual bool cancel (bool mayInterruptIfRunning)
 Attempts to cancel execution of this task.
virtual T get ()
 Waits if necessary for the computation to complete, and then retrieves its result.
virtual T get (long long timeout, const TimeUnit &unit)
 Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
FutureTask< T > * clone ()
virtual void done ()
 Protected method invoked when this task transitions to state isDone (whether normally or via cancellation).
virtual void set (const T &result)
 Sets the result of this Future to the given value unless this future has already been set or has been cancelled.
virtual void setException (const decaf::lang::Exception &error)
 Causes this future to report an ExecutionException with the given Exception as its cause, unless this Future has already been set or has been canceled.
virtual void run ()
 Run method - called by the Thread class in the context of the thread.
virtual bool runAndReset ()
 Executes the computation without setting its result, and then resets this Future to initial state, failing to do so if the computation encounters an exception or is canceled.
 FutureTask (const FutureTask< T > &source)
FutureTask< T > & operator= (const FutureTask< T > &source)
- Public Member Functions inherited from decaf::util::concurrent::RunnableFuture< T >
virtual ~RunnableFuture ()
- Public Member Functions inherited from decaf::util::concurrent::Future< T >
virtual ~Future ()
- Public Member Functions inherited from decaf::util::concurrent::FutureType
virtual ~FutureType ()
- Public Member Functions inherited from decaf::lang::Runnable
virtual ~Runnable ()

Detailed Description

template<typename T>
class decaf::util::concurrent::FutureTask< T >

A cancellable asynchronous computation.

This class provides a base implementation of Future, with methods to start and cancel a computation, query to see if the computation is complete, and retrieve the result of the computation. The result can only be retrieved when the computation has completed; the get method will block if the computation has not yet completed. Once the computation has completed, the computation cannot be restarted or canceled.

A FutureTask can be used to wrap a Callable or Runnable object. Because FutureTask implements Runnable, a FutureTask can be submitted to an Executor for execution.

In addition to serving as a stand-alone class, this class provides protected functionality that may be useful when creating customized task classes.

Since
1.0

Constructor & Destructor Documentation

template<typename T>
decaf::util::concurrent::FutureTask< T >::FutureTask ( Callable< T > *  callable,
bool  takeOwnership = true 
)
inline

Creates a FutureTask instance that will, upon running, execute the given Callable.

Parameters
callableThe callable task that will be invoked when run.
takeOwnershipBoolean value indicating if the Executor now owns the pointer to the task.
Exceptions
NullPointerExceptionif callable pointer is NULL

References NULL.

template<typename T>
decaf::util::concurrent::FutureTask< T >::FutureTask ( decaf::lang::Runnable runnable,
const T &  result,
bool  takeOwnership = true 
)
inline

Creates a FutureTask that will, upon running, execute the given Runnable, and arrange that the get method will return the given result on successful completion.

Parameters
runnableThe runnable task that the future will execute.
resultThe result to return on successful completion.
takeOwnershipBoolean value indicating if the Executor now owns the pointer to the task.
Exceptions
NullPointerExceptionif runnable is NULL.

References NULL.

template<typename T>
virtual decaf::util::concurrent::FutureTask< T >::~FutureTask ( )
inlinevirtual
template<typename T>
decaf::util::concurrent::FutureTask< T >::FutureTask ( const FutureTask< T > &  source)
inline

Member Function Documentation

template<typename T>
virtual bool decaf::util::concurrent::FutureTask< T >::cancel ( bool  mayInterruptIfRunning)
inlinevirtual

Attempts to cancel execution of this task.

This attempt will fail if the task has already completed, has already been canceled, or could not be canceled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. If the task has already started, then the mayInterruptIfRunning parameter determines whether the thread executing this task should be interrupted in an attempt to stop the task.

After this method returns, subsequent calls to isDone() will always return true. Subsequent calls to isCancelled() will always return true if this method returned true.

Parameters
mayInterruptIfRunningTrue if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete.
Returns
false if the task could not be canceled, typically because it has already completed normally; true otherwise

Implements decaf::util::concurrent::FutureType.

template<typename T>
FutureTask<T>* decaf::util::concurrent::FutureTask< T >::clone ( )
inline
template<typename T>
virtual void decaf::util::concurrent::FutureTask< T >::done ( )
inlinevirtual

Protected method invoked when this task transitions to state isDone (whether normally or via cancellation).

The default implementation does nothing. Subclasses may override this method to invoke completion callbacks or perform bookkeeping. Note that you can query status inside the implementation of this method to determine whether this task has been canceled.

template<typename T>
virtual T decaf::util::concurrent::FutureTask< T >::get ( )
inlinevirtual

Waits if necessary for the computation to complete, and then retrieves its result.

Returns
the computed result.
Exceptions
CancellationExceptionif the computation was canceled
ExecutionExceptionif the computation threw an exception
InterruptedExceptionif the current thread was interrupted while waiting

Implements decaf::util::concurrent::Future< T >.

template<typename T>
virtual T decaf::util::concurrent::FutureTask< T >::get ( long long  timeout,
const TimeUnit unit 
)
inlinevirtual

Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.

Parameters
timeoutThe maximum time to wait for this Future to finish.
unitThe time unit of the timeout argument.
Returns
the computed result
Exceptions
CancellationExceptionif the computation was canceled
ExecutionExceptionif the computation threw an exception
InterruptedExceptionif the current thread was interrupted while waiting
TimeoutExceptionif the wait timed out before the future completed.

Implements decaf::util::concurrent::Future< T >.

template<typename T>
virtual bool decaf::util::concurrent::FutureTask< T >::isCancelled ( ) const
inlinevirtual

Returns true if this task was canceled before it completed normally.

Returns
true if this task was canceled before it completed

Implements decaf::util::concurrent::FutureType.

template<typename T>
virtual bool decaf::util::concurrent::FutureTask< T >::isDone ( ) const
inlinevirtual

Returns true if this task completed.

Completion may be due to normal termination, an exception, or cancellation – in all of these cases, this method will return true.

Returns
true if this task completed

Implements decaf::util::concurrent::FutureType.

template<typename T>
FutureTask<T>& decaf::util::concurrent::FutureTask< T >::operator= ( const FutureTask< T > &  source)
inline
template<typename T>
virtual void decaf::util::concurrent::FutureTask< T >::run ( )
inlinevirtual

Run method - called by the Thread class in the context of the thread.

Implements decaf::lang::Runnable.

template<typename T>
virtual bool decaf::util::concurrent::FutureTask< T >::runAndReset ( )
inlinevirtual

Executes the computation without setting its result, and then resets this Future to initial state, failing to do so if the computation encounters an exception or is canceled.

This is designed for use with tasks that intrinsically execute more than once.

Returns
true if successfully run and reset
template<typename T>
virtual void decaf::util::concurrent::FutureTask< T >::set ( const T &  result)
inlinevirtual

Sets the result of this Future to the given value unless this future has already been set or has been cancelled.

This method is invoked internally by the run method upon successful completion of the computation.

Parameters
vThe value to return as the result of this Future.
template<typename T>
virtual void decaf::util::concurrent::FutureTask< T >::setException ( const decaf::lang::Exception error)
inlinevirtual

Causes this future to report an ExecutionException with the given Exception as its cause, unless this Future has already been set or has been canceled.

This method is invoked internally by the run method upon failure of the computation.

Parameters
errorThe cause of failure that is thrown from run.

The documentation for this class was generated from the following file: