org.jgroups.blocks.executor

## Class ExecutionService.DistributedFuture<V>

- java.lang.Object
- - org.jgroups.blocks.executor.ExecutionService.DistributedFuture<V>

- Type Parameters:
    `V` -
  All Implemented Interfaces:
    java.lang.Runnable, java.util.concurrent.Future<V>, java.util.concurrent.RunnableFuture<V>, ExecutorNotification, NotifyingFuture<V>
  Enclosing class:
    ExecutionService

      public static class ExecutionService.DistributedFuture<V>
      extends java.lang.Object
      implements java.util.concurrent.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

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `protected static class` | `ExecutionService.DistributedFuture.Sync<V>` Synchronization control for FutureTask.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected ExecutionService.DistributedFuture.Sync<V>` | `sync` Synchronization control for FutureTask

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExecutionService.DistributedFuture(JChannel channel, java.util.concurrent.locks.Lock unfinishedLock, java.util.concurrent.locks.Condition condition, java.util.Set<java.util.concurrent.Future<?>> futuresToFinish, java.util.concurrent.Callable<V> callable)` Creates a `FutureTask` that will upon running, execute the given `Callable`.
    `ExecutionService.DistributedFuture(JChannel channel, java.util.concurrent.locks.Lock unfinishedLock, java.util.concurrent.locks.Condition condition, java.util.Set<java.util.concurrent.Future<?>> futuresToFinish, java.lang.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.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `cancel(boolean mayInterruptIfRunning)`
    `protected void` | `done()` Protected method invoked when this task transitions to state `isDone` (whether normally or via cancellation).
    `V` | `get()`
    `V` | `get(long timeout, java.util.concurrent.TimeUnit unit)`
    `java.util.concurrent.Callable<V>` | `getCallable()`
    `void` | `interrupted(java.lang.Runnable runnable)`
    `boolean` | `isCancelled()`
    `boolean` | `isDone()`
    `void` | `resultReturned(java.lang.Object obj)`
    `void` | `run()` Sets this Future to the result of its computation unless it has been cancelled.
    `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.
    `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.
    `protected void` | `setException(java.lang.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.
    `NotifyingFuture<V>` | `setListener(FutureListener<V> listener)` Attaches a listener and returns the same future instance, to allow for 'building' futures.
    `void` | `throwableEncountered(java.lang.Throwable t)`
    `java.lang.String` | `toString()`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Field Detail

    - #### sync

          protected final ExecutionService.DistributedFuture.Sync<V> sync

      Synchronization control for FutureTask

  - ### Constructor Detail

    - #### ExecutionService.DistributedFuture

          public ExecutionService.DistributedFuture(JChannel channel,
                                            java.util.concurrent.locks.Lock unfinishedLock,
                                            java.util.concurrent.locks.Condition condition,
                                            java.util.Set<java.util.concurrent.Future<?>> futuresToFinish,
                                            java.util.concurrent.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

    - #### ExecutionService.DistributedFuture

          public ExecutionService.DistributedFuture(JChannel channel,
                                            java.util.concurrent.locks.Lock unfinishedLock,
                                            java.util.concurrent.locks.Condition condition,
                                            java.util.Set<java.util.concurrent.Future<?>> futuresToFinish,
                                            java.lang.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:
        `java.lang.NullPointerException` - if runnable is null

  - ### Method Detail

    - #### toString

          public java.lang.String toString()

      Overrides:
        `toString` in class `java.lang.Object`

    - #### getCallable

          public java.util.concurrent.Callable<V> getCallable()

    - #### isCancelled

          public boolean isCancelled()

      Specified by:
        `isCancelled` in interface `java.util.concurrent.Future<V>`

    - #### isDone

          public boolean isDone()

      Specified by:
        `isDone` in interface `java.util.concurrent.Future<V>`

    - #### cancel

          public boolean cancel(boolean mayInterruptIfRunning)

      Specified by:
        `cancel` in interface `java.util.concurrent.Future<V>`

    - #### get

          public V get()
                throws java.lang.InterruptedException,
                       java.util.concurrent.ExecutionException

      Specified by:
        `get` in interface `java.util.concurrent.Future<V>`
      Throws:
        `java.util.concurrent.CancellationException`
        `java.lang.InterruptedException`
        `java.util.concurrent.ExecutionException`

    - #### get

          public V get(long timeout,
              java.util.concurrent.TimeUnit unit)
                throws java.lang.InterruptedException,
                       java.util.concurrent.ExecutionException,
                       java.util.concurrent.TimeoutException

      Specified by:
        `get` in interface `java.util.concurrent.Future<V>`
      Throws:
        `java.util.concurrent.CancellationException`
        `java.lang.InterruptedException`
        `java.util.concurrent.ExecutionException`
        `java.util.concurrent.TimeoutException`

    - #### 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(java.lang.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 `java.lang.Runnable`
      Specified by:
        `run` in interface `java.util.concurrent.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(java.lang.Object obj)

      Specified by:
        `resultReturned` in interface `ExecutorNotification`

    - #### throwableEncountered

          public void throwableEncountered(java.lang.Throwable t)

      Specified by:
        `throwableEncountered` in interface `ExecutorNotification`

    - #### interrupted

          public void interrupted(java.lang.Runnable runnable)

      Specified by:
        `interrupted` in interface `ExecutorNotification`

Copyright © 1998-2009 Bela Ban / Red Hat. All Rights Reserved.