org.jppf.client.concurrent
Class JPPFTaskFuture<V>

java.lang.Object
  extended by org.jppf.client.concurrent.JPPFTaskFuture<V>
Type Parameters:
V - the type of the result for the future.
All Implemented Interfaces:
Future<V>

public class JPPFTaskFuture<V>
extends Object

Implementation of a future handled by a JPPFExecutorService.

Author:
Laurent Cohen

Field Summary
protected  AtomicBoolean cancelled
          The cancellation status of the task represented by this future.
protected  AtomicBoolean done
          The completion status of the task represented by this future.
protected  Exception exception
          An exception that may be rasied by the execution of the task.
protected  V result
          The execution result.
protected  AtomicBoolean timedout
          TDetrmines whether the task execution timed out.
 
Constructor Summary
JPPFTaskFuture(org.jppf.client.concurrent.FutureResultCollector collector, int position)
          Initialize this future with the specified parameters.
 
Method Summary
 boolean cancel(boolean mayInterruptIfRunning)
          Attempts to cancel execution of this task.
 V get()
          Waits if necessary for the computation to complete, and then retrieves its result.
 V get(long timeout, TimeUnit unit)
          Waits if necessary for at most the given time for the computation to complete, and then retrieves its result, if available.
 JPPFTask getTask()
          Get the task associated with this future.
 boolean isCancelled()
          Determine whether this task was cancelled before it completed normally.
 boolean isDone()
          Returns true if this task completed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

done

protected AtomicBoolean done
The completion status of the task represented by this future.


cancelled

protected AtomicBoolean cancelled
The cancellation status of the task represented by this future.


timedout

protected AtomicBoolean timedout
TDetrmines whether the task execution timed out.


result

protected V result
The execution result.


exception

protected Exception exception
An exception that may be rasied by the execution of the task.

Constructor Detail

JPPFTaskFuture

public JPPFTaskFuture(org.jppf.client.concurrent.FutureResultCollector collector,
                      int position)
Initialize this future with the specified parameters.

Parameters:
collector - the collector that receives the results from the server.
position - the position of the task in the job.
Method Detail

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.

Specified by:
isDone in interface Future<V>
Returns:
true if the task completed.
See Also:
AbstractJPPFFuture.isDone()

get

public V get()
      throws InterruptedException,
             ExecutionException
Waits if necessary for the computation to complete, and then retrieves its result.

Specified by:
get in interface Future<V>
Returns:
the computed result.
Throws:
InterruptedException - if the current thread was interrupted while waiting.
ExecutionException - if the computation threw an exception.
See Also:
Future.get()

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:
get in interface Future<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.
See Also:
Future.get(long, java.util.concurrent.TimeUnit)

getTask

public JPPFTask getTask()
Get the task associated with this future.

Returns:
a JPPFTask instance.

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.

Specified by:
cancel in interface Future<V>
Parameters:
mayInterruptIfRunning - true if the thread executing this task should be interrupted; otherwise, in-progress tasks are allowed to complete.
Returns:
this method always returns false.
See Also:
Future.cancel(boolean)

isCancelled

public boolean isCancelled()
Determine whether this task was cancelled before it completed normally.

Specified by:
isCancelled in interface Future<V>
Returns:
true if this task was cancelled before it completed normally.
See Also:
Future.isCancelled()


Copyright © 2005-2010 JPPF Team.