Class OperationFuture<T>

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

    public class OperationFuture<T>
    extends AbstractListenableFuture<T,​OperationCompletionListener>
    implements java.util.concurrent.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 Detail

      • latch

        private final java.util.concurrent.CountDownLatch latch
      • objRef

        private final java.util.concurrent.atomic.AtomicReference<T> objRef
      • timeout

        private final long timeout
      • key

        private final java.lang.String key
      • cas

        private java.lang.Long cas
    • Constructor Detail

      • OperationFuture

        public OperationFuture​(java.lang.String k,
                               java.util.concurrent.CountDownLatch l,
                               long opTimeout,
                               java.util.concurrent.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​(java.lang.String k,
                               java.util.concurrent.CountDownLatch l,
                               java.util.concurrent.atomic.AtomicReference<T> oref,
                               long opTimeout,
                               java.util.concurrent.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 Detail

      • cancel

        public boolean cancel​(boolean ign)
        Deprecated.
        Cancel this operation, if possible.
        Specified by:
        cancel in interface java.util.concurrent.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

        public T get()
              throws java.lang.InterruptedException,
                     java.util.concurrent.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 java.util.concurrent.Future<T>
        Returns:
        the operation results of this OperationFuture
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • get

        public T get​(long duration,
                     java.util.concurrent.TimeUnit units)
              throws java.lang.InterruptedException,
                     java.util.concurrent.TimeoutException,
                     java.util.concurrent.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 java.util.concurrent.Future<T>
        Parameters:
        duration - amount of time to wait
        units - unit of time to wait
        Returns:
        the operation results of this OperationFuture
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.TimeoutException
        java.util.concurrent.ExecutionException
      • getKey

        public java.lang.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 java.lang.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:
        java.lang.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 java.util.concurrent.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 java.util.concurrent.Future<T>
        Returns:
        true if the Operation is done
      • signalComplete

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