Class ExecutionService.DistributedFuture<V>

java.lang.Object
org.jgroups.blocks.executor.ExecutionService.DistributedFuture<V>
Type Parameters:
V -
All Implemented Interfaces:
Runnable, Future<V>, RunnableFuture<V>, ExecutorNotification, NotifyingFuture<V>
Enclosing class:
ExecutionService

public static class ExecutionService.DistributedFuture<V> extends Object implements RunnableFuture<V>, ExecutorNotification, NotifyingFuture<V>
This is basically a copy of the FutureTask in java.util.concurrent but added serializable to it. Also added in the NotifyingFuture so that the channel can update the future when the value is calculated.
Author:
wburns
  • Field Details

  • Constructor Details

    • DistributedFuture

      public DistributedFuture(JChannel channel, Lock unfinishedLock, Condition condition, Set<Future<?>> futuresToFinish, Callable<V> callable)
      Creates a FutureTask that will upon running, execute the given Callable.
      Parameters:
      channel - The channel that messages are sent down
      unfinishedLock - The lock which protects the futuresToFinish set object.
      condition - The condition to signal when this future finishes
      futuresToFinish - The set to remove this future from when it is finished.
      callable - The callable to actually run on the server side
    • DistributedFuture

      public DistributedFuture(JChannel channel, Lock unfinishedLock, Condition condition, Set<Future<?>> futuresToFinish, Runnable runnable, V result)
      Creates a FutureTask that will upon running, execute the given Runnable, and arrange that get will return the given result on successful completion.
      Parameters:
      channel - The channel that messages are sent down
      unfinishedLock - The lock which protects the futuresToFinish set object.
      condition - The condition to signal when this future finishes
      futuresToFinish - The set to remove this future from when it is finished.
      runnable - the runnable task
      result - the result to return on successful completion. If you don't need a particular result, consider using constructions of the form: Future<?> f = new FutureTask<Object>(runnable, null)
      Throws:
      NullPointerException - if runnable is null
  • Method Details

    • toString

      public String toString()
      Overrides:
      toString in class Object
    • getCallable

      public Callable<V> getCallable()
    • isCancelled

      public boolean isCancelled()
      Specified by:
      isCancelled in interface Future<V>
    • isDone

      public boolean isDone()
      Specified by:
      isDone in interface Future<V>
    • cancel

      public boolean cancel(boolean mayInterruptIfRunning)
      Specified by:
      cancel in interface Future<V>
    • get

      Specified by:
      get in interface Future<V>
    • get

      public V get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException
      Specified by:
      get in interface Future<V>
    • done

      protected void done()
      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 cancelled.
    • setListener

      public NotifyingFuture<V> setListener(FutureListener<V> listener)
      Description copied from interface: NotifyingFuture
      Attaches a listener and returns the same future instance, to allow for 'building' futures.
      Specified by:
      setListener in interface NotifyingFuture<V>
      Parameters:
      listener - listener to attach
      Returns:
      the same future instance
    • set

      protected void set(V v)
      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:
      v - the value
    • setException

      protected void setException(Throwable t)
      Causes this future to report an ExecutionException with the given throwable as its cause, unless this Future has already been set or has been cancelled. This method is invoked internally by the run method upon failure of the computation.
      Parameters:
      t - the cause of failure
    • run

      public void run()
      Sets this Future to the result of its computation unless it has been cancelled.
      Specified by:
      run in interface Runnable
      Specified by:
      run in interface RunnableFuture<V>
    • runAndReset

      protected boolean 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 cancelled. This is designed for use with tasks that intrinsically execute more than once.
      Returns:
      true if successfully run and reset
    • resultReturned

      public void resultReturned(Object obj)
      Specified by:
      resultReturned in interface ExecutorNotification
    • throwableEncountered

      public void throwableEncountered(Throwable t)
      Specified by:
      throwableEncountered in interface ExecutorNotification
    • interrupted

      public void interrupted(Runnable runnable)
      Specified by:
      interrupted in interface ExecutorNotification