activemq-cpp-3.6.0
|
A cancellable asynchronous computation. More...
#include <src/main/decaf/util/concurrent/FutureTask.h>
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 () |
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.
|
inline |
Creates a FutureTask instance that will, upon running, execute the given Callable.
callable | The callable task that will be invoked when run. |
takeOwnership | Boolean value indicating if the Executor now owns the pointer to the task. |
NullPointerException | if callable pointer is NULL |
References NULL.
|
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.
runnable | The runnable task that the future will execute. |
result | The result to return on successful completion. |
takeOwnership | Boolean value indicating if the Executor now owns the pointer to the task. |
NullPointerException | if runnable is NULL. |
References NULL.
|
inlinevirtual |
|
inline |
|
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.
mayInterruptIfRunning | True if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete. |
Implements decaf::util::concurrent::FutureType.
|
inline |
|
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.
|
inlinevirtual |
Waits if necessary for the computation to complete, and then retrieves its result.
CancellationException | if the computation was canceled |
ExecutionException | if the computation threw an exception |
InterruptedException | if the current thread was interrupted while waiting |
Implements decaf::util::concurrent::Future< T >.
|
inlinevirtual |
Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
timeout | The maximum time to wait for this Future to finish. |
unit | The time unit of the timeout argument. |
CancellationException | if the computation was canceled |
ExecutionException | if the computation threw an exception |
InterruptedException | if the current thread was interrupted while waiting |
TimeoutException | if the wait timed out before the future completed. |
Implements decaf::util::concurrent::Future< T >.
|
inlinevirtual |
Returns true if this task was canceled before it completed normally.
Implements decaf::util::concurrent::FutureType.
|
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.
Implements decaf::util::concurrent::FutureType.
|
inline |
|
inlinevirtual |
Run method - called by the Thread class in the context of the thread.
Implements decaf::lang::Runnable.
|
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.
|
inlinevirtual |
|
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.
error | The cause of failure that is thrown from run. |