net.spy.memcached.protocol
Class BaseOperationImpl

java.lang.Object
  extended by net.spy.memcached.compat.SpyObject
      extended by net.spy.memcached.protocol.BaseOperationImpl
All Implemented Interfaces:
Operation
Direct Known Subclasses:
ConcatenationOperationImpl, GetAndTouchOperationImpl, GetAndTouchOperationImpl, GetlOperationImpl, GetsOperationImpl, OptimizedSetImpl, SASLBaseOperationImpl, StatsOperationImpl, TapOperationImpl, TouchOperationImpl

public abstract class BaseOperationImpl
extends SpyObject
implements Operation

Base class for protocol-specific operation implementations.


Field Summary
protected  OperationCallback callback
           
static OperationStatus CANCELLED
          Status object for canceled operations.
protected  java.util.Collection<MemcachedNode> notMyVbucketNodes
           
static OperationStatus TIMED_OUT
           
 
Constructor Summary
BaseOperationImpl()
           
 
Method Summary
 void cancel()
          Cancel this operation.
 java.nio.ByteBuffer getBuffer()
          Get the write buffer for this operation.
 OperationCallback getCallback()
          Get the operation callback associated with this operation.
 OperationException getException()
          Get the exception that occurred (or null if no exception occurred).
 MemcachedNode getHandlingNode()
          Get the node that should've been handling this operation.
 OperationState getState()
          Get the current state of this operation.
protected  void handleError(OperationErrorType eType, java.lang.String line)
           
 void handleRead(java.nio.ByteBuffer data)
          Handle a raw data read.
 boolean hasErrored()
          True if an error occurred while processing this operation.
abstract  void initialize()
          Initialize this operation.
 boolean isCancelled()
          Has this operation been cancelled?
 boolean isTimedOut()
          True if the operation has timed out.
 boolean isTimedOut(long ttlMillis)
          True if the operation has timed out.
 boolean isTimedOutUnsent()
          True if the operation has timed out and has not been sent.
abstract  void readFromBuffer(java.nio.ByteBuffer data)
          Read data from the given byte buffer and dispatch to the appropriate read mechanism.
protected  void setBuffer(java.nio.ByteBuffer to)
          Set the write buffer for this operation.
protected  void setCallback(OperationCallback to)
          Set the callback for this instance.
 void setHandlingNode(MemcachedNode to)
          Set a reference to the node that will be/is handling this operation.
 void timeOut()
          Mark this operation as one which has exceeded its timeout value.
protected  void transitionState(OperationState newState)
          Transition the state of this operation to the given state.
protected  void wasCancelled()
          This is called on each subclass whenever an operation was cancelled.
 void writeComplete()
          Invoked after having written all of the bytes from the supplied output buffer.
 void writing()
          Invoked when we start writing all of the bytes from this operation to the sockets write buffer.
 
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

CANCELLED

public static final OperationStatus CANCELLED
Status object for canceled operations.


TIMED_OUT

public static final OperationStatus TIMED_OUT

callback

protected OperationCallback callback

notMyVbucketNodes

protected java.util.Collection<MemcachedNode> notMyVbucketNodes
Constructor Detail

BaseOperationImpl

public BaseOperationImpl()
Method Detail

getCallback

public final OperationCallback getCallback()
Get the operation callback associated with this operation.

Specified by:
getCallback in interface Operation

setCallback

protected void setCallback(OperationCallback to)
Set the callback for this instance.


isCancelled

public final boolean isCancelled()
Description copied from interface: Operation
Has this operation been cancelled?

Specified by:
isCancelled in interface Operation

hasErrored

public final boolean hasErrored()
Description copied from interface: Operation
True if an error occurred while processing this operation.

Specified by:
hasErrored in interface Operation

getException

public final OperationException getException()
Description copied from interface: Operation
Get the exception that occurred (or null if no exception occurred).

Specified by:
getException in interface Operation

cancel

public final void cancel()
Description copied from interface: Operation
Cancel this operation.

Specified by:
cancel in interface Operation

wasCancelled

protected void wasCancelled()
This is called on each subclass whenever an operation was cancelled.


getState

public final OperationState getState()
Description copied from interface: Operation
Get the current state of this operation.

Specified by:
getState in interface Operation

getBuffer

public final java.nio.ByteBuffer getBuffer()
Description copied from interface: Operation
Get the write buffer for this operation.

Specified by:
getBuffer in interface Operation

setBuffer

protected final void setBuffer(java.nio.ByteBuffer to)
Set the write buffer for this operation.


transitionState

protected final void transitionState(OperationState newState)
Transition the state of this operation to the given state.


writing

public final void writing()
Description copied from interface: Operation
Invoked when we start writing all of the bytes from this operation to the sockets write buffer.

Specified by:
writing in interface Operation

writeComplete

public final void writeComplete()
Description copied from interface: Operation
Invoked after having written all of the bytes from the supplied output buffer.

Specified by:
writeComplete in interface Operation

initialize

public abstract void initialize()
Description copied from interface: Operation
Initialize this operation. This is used to prepare output byte buffers and stuff.

Specified by:
initialize in interface Operation

readFromBuffer

public abstract void readFromBuffer(java.nio.ByteBuffer data)
                             throws java.io.IOException
Description copied from interface: Operation
Read data from the given byte buffer and dispatch to the appropriate read mechanism.

Specified by:
readFromBuffer in interface Operation
Throws:
java.io.IOException

handleError

protected void handleError(OperationErrorType eType,
                           java.lang.String line)
                    throws java.io.IOException
Throws:
java.io.IOException

handleRead

public void handleRead(java.nio.ByteBuffer data)
Description copied from interface: Operation
Handle a raw data read.

Specified by:
handleRead in interface Operation

getHandlingNode

public MemcachedNode getHandlingNode()
Description copied from interface: Operation
Get the node that should've been handling this operation.

Specified by:
getHandlingNode in interface Operation

setHandlingNode

public void setHandlingNode(MemcachedNode to)
Description copied from interface: Operation
Set a reference to the node that will be/is handling this operation.

Specified by:
setHandlingNode in interface Operation
Parameters:
to - a memcached node

timeOut

public void timeOut()
Description copied from interface: Operation
Mark this operation as one which has exceeded its timeout value.

Specified by:
timeOut in interface Operation

isTimedOut

public boolean isTimedOut()
Description copied from interface: Operation
True if the operation has timed out.

A timed out operation may or may not have been sent to the server already, but it exceeded either the specified or the default timeout value.

Specified by:
isTimedOut in interface Operation

isTimedOut

public boolean isTimedOut(long ttlMillis)
Description copied from interface: Operation
True if the operation has timed out. The ttl allows the caller to specify how long the operation should have been given since its creation, returning true if the operation has exceeded that time period.

A timed out operation may or may not have been sent to the server already, but it exceeded either the specified or the default timeout value.

In the rare case this may be called with a longer timeout value after having been called with a shorter value that caused the operation to be timed out, an IllegalArgumentException may be thrown.

Specified by:
isTimedOut in interface Operation
Parameters:
ttlMillis - the max amount of time an operation may have existed since its creation in milliseconds.

isTimedOutUnsent

public boolean isTimedOutUnsent()
Description copied from interface: Operation
True if the operation has timed out and has not been sent. If the client has timed out this operation and knows it has not been written to the network, this will be true.

Specified by:
isTimedOutUnsent in interface Operation


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