Package org.jppf.client.concurrent
Class JPPFTaskFuture<V>
java.lang.Object
org.jppf.client.concurrent.JPPFTaskFuture<V>
- Type Parameters:
V- the type of the result for the future.
- All Implemented Interfaces:
Future<V>
Implementation of a future handled by a
JPPFExecutorService.- Author:
- Laurent Cohen
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected AtomicBooleanThe cancellation status of the task represented by this future.protected AtomicBooleanThe completion status of the task represented by this future.protected VThe execution result.protected ThrowableAn exception that may be raised by the execution of the task.protected AtomicBooleanDetermines whether the task execution timed out. -
Constructor Summary
ConstructorsConstructorDescriptionJPPFTaskFuture(JPPFJob job, int position) Initialize this future with the specified parameters. -
Method Summary
Modifier and TypeMethodDescriptionbooleancancel(boolean mayInterruptIfRunning) Attempts to cancel execution of this task.get()Waits if necessary for the computation to complete, and then retrieves its result.Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.getJob()Get the job that holds the task.org.jppf.node.protocol.Task<?>getTask()Get the task associated with this future.booleanDetermine whether this task was cancelled before it completed normally.booleanisDone()Returns true if this task completed.
-
Field Details
-
done
The completion status of the task represented by this future. -
cancelled
The cancellation status of the task represented by this future. -
timedout
Determines whether the task execution timed out. -
result
The execution result. -
throwable
An exception that may be raised by the execution of the task.
-
-
Constructor Details
-
JPPFTaskFuture
Initialize this future with the specified parameters.- Parameters:
job- the collector that receives the results from the server.position- the position of the task in the job.
-
-
Method Details
-
isDone
public boolean isDone()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. -
get
Waits if necessary for the computation to complete, and then retrieves its result.- Specified by:
getin interfaceFuture<V>- Returns:
- the computed result.
- Throws:
InterruptedException- if the current thread was interrupted while waiting.ExecutionException- if the computation threw an exception.
-
get
public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.- Specified by:
getin interfaceFuture<V>- Parameters:
timeout- the maximum time to wait.unit- the time unit of the timeout argument.- Returns:
- the computed result.
- Throws:
InterruptedException- if the current thread was interrupted while waiting.ExecutionException- if the computation threw an exception.TimeoutException- if the wait timed out.
-
getTask
public org.jppf.node.protocol.Task<?> getTask()Get the task associated with this future.- Returns:
- a
Taskinstance.
-
getJob
Get the job that holds the task.- Returns:
- a
JPPFJobinstance.
-
cancel
public boolean cancel(boolean mayInterruptIfRunning) Attempts to cancel execution of this task. This attempt will fail if the task has already completed, already been cancelled, or could not be cancelled for some other reason. If successful, and this task has not started when cancel is called, this task should never run. -
isCancelled
public boolean isCancelled()Determine whether this task was cancelled before it completed normally.- Specified by:
isCancelledin interfaceFuture<V>- Returns:
- true if this task was cancelled before it completed normally.
-