Class OperationFuture<T>

Type Parameters:
T - Type of object returned from this future.
All Implemented Interfaces:
Future<T>, ListenableFuture<T,OperationCompletionListener>

public class OperationFuture<T> extends AbstractListenableFuture<T,OperationCompletionListener> implements Future<T>
Managed future for operations.

From an OperationFuture, application code can determine if the status of a given Operation in an asynchronous manner.

If for example we needed to update the keys "user::name", "user::friendlist" because later in the method we were going to verify the change occurred as expected interacting with the user, we can fire multiple IO operations simultaneously with this concept.

  • Field Details

  • Constructor Details

    • OperationFuture

      public OperationFuture(String k, CountDownLatch l, long opTimeout, ExecutorService service)
      Create an OperationFuture for a given async operation. This is intended for internal use only.
      Parameters:
      k - the key for the operation
      l - the latch to be used counting down the OperationFuture
      opTimeout - the timeout within which the operation needs to be done
    • OperationFuture

      public OperationFuture(String k, CountDownLatch l, AtomicReference<T> oref, long opTimeout, ExecutorService service)
      Create an OperationFuture for a given async operation. This is intended for internal use only.
      Parameters:
      k - the key for the operation
      l - the latch to be used counting down the OperationFuture
      oref - an AtomicReference associated with the operation
      opTimeout - the timeout within which the operation needs to be done
  • Method Details

    • cancel

      public boolean cancel(boolean ign)
      Deprecated.
      Cancel this operation, if possible.
      Specified by:
      cancel in interface Future<T>
      Parameters:
      ign - not used
      Returns:
      true if the operation has not yet been written to the network
    • cancel

      public boolean cancel()
      Cancel this operation, if possible.
      Returns:
      true if the operation has not yet been written to the network
    • get

      Get the results of the given operation. As with the Future interface, this call will block until the results of the future operation has been received.
      Specified by:
      get in interface Future<T>
      Returns:
      the operation results of this OperationFuture
      Throws:
      InterruptedException
      ExecutionException
    • get

      public T get(long duration, TimeUnit units) throws InterruptedException, TimeoutException, ExecutionException
      Get the results of the given operation. As with the Future interface, this call will block until the results of the future operation has been received.
      Specified by:
      get in interface Future<T>
      Parameters:
      duration - amount of time to wait
      units - unit of time to wait
      Returns:
      the operation results of this OperationFuture
      Throws:
      InterruptedException
      TimeoutException
      ExecutionException
    • getKey

      public String getKey()
      Get the key for this operation.
      Returns:
      the key for this operation
    • setCas

      public void setCas(long inCas)
      Set the key for this operation.
      Parameters:
      inCas - the CAS value
    • getCas

      public Long getCas()
      Get the CAS for this operation. The interrupted status of the current thread is cleared by this method. Inspect the returned OperationStatus to check whether an interruption has taken place.
      Returns:
      the CAS for this operation or null if unsuccessful.
      Throws:
      UnsupportedOperationException - If this is for an ASCII protocol configured client.
    • getStatus

      public OperationStatus getStatus()
      Get the current status of this operation. Note that the operation status may change as the operation is tried and potentially retried against the servers specified by the NodeLocator. The interrupted status of the current thread is cleared by this method. Inspect the returned OperationStatus to check whether an interruption has taken place.
      Returns:
      OperationStatus
    • set

      public void set(T o, OperationStatus s)
      Set the Operation associated with this OperationFuture. This is intended for internal use only.
      Parameters:
      o - the Operation object itself
      s - the OperationStatus associated with this operation
    • setOperation

      public void setOperation(Operation to)
      Set the Operation associated with this OperationFuture. This is intended for internal use only.
      Parameters:
      to - the Operation to set this OperationFuture to be tracking
    • isCancelled

      public boolean isCancelled()
      Whether or not the Operation associated with this OperationFuture has been canceled. One scenario in which this can occur is if the connection is lost and the Operation has been sent over the network. In this case, the operation may or may not have reached the server before the connection was dropped.
      Specified by:
      isCancelled in interface Future<T>
      Returns:
      true if the Operation has been canceled
    • isDone

      public boolean isDone()
      Whether or not the Operation is done and result can be retrieved with get(). The most common way to wait for this OperationFuture is to use the get() method which will block. This method allows one to check if it's complete without blocking.
      Specified by:
      isDone in interface Future<T>
      Returns:
      true if the Operation is done
    • addListener

      public OperationFuture<T> addListener(OperationCompletionListener listener)
      Description copied from interface: ListenableFuture
      Add a listener to the future, which will be executed once the operation completes.
      Specified by:
      addListener in interface ListenableFuture<T,OperationCompletionListener>
      Parameters:
      listener - the listener which will be executed.
      Returns:
      the current future to allow for object-chaining.
    • removeListener

      public OperationFuture<T> removeListener(OperationCompletionListener listener)
      Description copied from interface: ListenableFuture
      Remove a previously added listener from the future.
      Specified by:
      removeListener in interface ListenableFuture<T,OperationCompletionListener>
      Parameters:
      listener - the previously added listener.
      Returns:
      the current future to allow for object-chaining.
    • signalComplete

      public void signalComplete()
      Signals that this future is complete.