net.spy.memcached.internal
Class OperationFuture<T>

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.internal.OperationFuture<T>
Type Parameters:
T - Type of object returned from this future.
All Implemented Interfaces:
java.util.concurrent.Future<T>

public class OperationFuture<T>
extends SpyObject
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 Summary
protected  OperationStatus status
           
 
Constructor Summary
OperationFuture(java.lang.String k, java.util.concurrent.CountDownLatch l, java.util.concurrent.atomic.AtomicReference<T> oref, long opTimeout)
          Create an OperationFuture for a given async operation.
OperationFuture(java.lang.String k, java.util.concurrent.CountDownLatch l, long opTimeout)
          Create an OperationFuture for a given async operation.
 
Method Summary
 boolean cancel()
          Cancel this operation, if possible.
 boolean cancel(boolean ign)
          Deprecated.  
 T get()
          Get the results of the given operation.
 T get(long duration, java.util.concurrent.TimeUnit units)
          Get the results of the given operation.
 long getCas()
          Get the CAS for this operation.
 java.lang.String getKey()
          Get the key for this operation.
 OperationStatus getStatus()
          Get the current status of this operation.
 boolean isCancelled()
          Whether or not the Operation associated with this OperationFuture has been canceled.
 boolean isDone()
          Whether or not the Operation is done and result can be retrieved with get().
 void set(T o, OperationStatus s)
          Set the Operation associated with this OperationFuture.
 void setCas(long inCas)
          Set the key for this operation.
 void setOperation(Operation to)
          Set the Operation associated with this OperationFuture.
 
Methods inherited from class net.spy.memcached.compat.SpyObject
getLogger
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

status

protected OperationStatus status
Constructor Detail

OperationFuture

public OperationFuture(java.lang.String k,
                       java.util.concurrent.CountDownLatch l,
                       long opTimeout)
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)
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 long getCas()
Get the CAS for this operation. If this is for an ASCII protocol configured client, the exception Un

Returns:
the CAS for this operation or null if unsuccessful.

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.

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


Copyright © 2006-2009 Dustin Sallings, 2009-2012 Couchbase, Inc.