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>

public class JPPFTaskFuture<V> extends Object
Implementation of a future handled by a JPPFExecutorService.
Author:
Laurent Cohen
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected AtomicBoolean
    The cancellation status of the task represented by this future.
    protected AtomicBoolean
    The completion status of the task represented by this future.
    protected V
    The execution result.
    protected Throwable
    An exception that may be raised by the execution of the task.
    protected AtomicBoolean
    Determines whether the task execution timed out.
  • Constructor Summary

    Constructors
    Constructor
    Description
    JPPFTaskFuture(JPPFJob job, int position)
    Initialize this future with the specified parameters.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    cancel(boolean mayInterruptIfRunning)
    Attempts to cancel execution of this task.
    get()
    Waits if necessary for the computation to complete, and then retrieves its result.
    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.
    Get the job that holds the task.
    org.jppf.node.protocol.Task<?>
    Get the task associated with this future.
    boolean
    Determine whether this task was cancelled before it completed normally.
    boolean
    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 Details

    • 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
      Determines whether the task execution timed out.
    • result

      protected V result
      The execution result.
    • throwable

      protected Throwable throwable
      An exception that may be raised by the execution of the task.
  • Constructor Details

    • JPPFTaskFuture

      public JPPFTaskFuture(JPPFJob job, int position)
      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.
      Specified by:
      isDone in interface Future<V>
      Returns:
      true if the task completed.
    • get

      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.
    • 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.
    • getTask

      public org.jppf.node.protocol.Task<?> getTask()
      Get the task associated with this future.
      Returns:
      a Task instance.
    • getJob

      public JPPFJob getJob()
      Get the job that holds the task.
      Returns:
      a JPPFJob 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.
    • 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.