Package net.spy.memcached.protocol
Class BaseOperationImpl
- java.lang.Object
-
- net.spy.memcached.compat.SpyObject
-
- net.spy.memcached.protocol.BaseOperationImpl
-
- All Implemented Interfaces:
Operation
- Direct Known Subclasses:
OperationImpl,OperationImpl
public abstract class BaseOperationImpl extends SpyObject implements Operation
Base class for protocol-specific operation implementations.
-
-
Field Summary
Fields Modifier and Type Field Description protected OperationCallbackcallbackprivate booleancancelledstatic OperationStatusCANCELLEDStatus object for canceled operations.private intcloneCountNumber of clones for this operation.private java.util.List<Operation>clonesIf the operation gets cloned, the reference is used to cascade cancellations and timeouts.private java.nio.ByteBuffercmdprivate longcreationTimeprivate OperationExceptionexceptionprivate MemcachedNodehandlingNodeprotected java.util.Collection<MemcachedNode>notMyVbucketNodesprivate OperationStatestatestatic OperationStatusTIMED_OUTprivate booleantimedoutprivate booleantimedOutUnsentprivate longwriteCompleteTimestamp
-
Constructor Summary
Constructors Constructor Description BaseOperationImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddClone(Operation op)Add the clone from this operation.voidcancel()Cancel this operation.java.nio.ByteBuffergetBuffer()Get the write buffer for this operation.OperationCallbackgetCallback()Get the operation callback associated with this operation.intgetCloneCount()Returns the number of times this operation has been cloned.OperationExceptiongetException()Get the exception that occurred (or null if no exception occurred).MemcachedNodegetHandlingNode()Get the node that should've been handling this operation.OperationStategetState()Get the current state of this operation.longgetWriteCompleteTimestamp()Returns the timestamp from the point where the WRITE was completed.protected voidhandleError(OperationErrorType eType, java.lang.String line)voidhandleRead(java.nio.ByteBuffer data)Handle a raw data read.booleanhasErrored()True if an error occurred while processing this operation.abstract voidinitialize()Initialize this operation.booleanisCancelled()Has this operation been cancelled?booleanisTimedOut()True if the operation has timed out.booleanisTimedOut(long ttlMillis)True if the operation has timed out.booleanisTimedOutUnsent()True if the operation has timed out and has not been sent.abstract voidreadFromBuffer(java.nio.ByteBuffer data)Read data from the given byte buffer and dispatch to the appropriate read mechanism.protected voidsetBuffer(java.nio.ByteBuffer to)Set the write buffer for this operation.protected voidsetCallback(OperationCallback to)Set the callback for this instance.voidsetCloneCount(int count)Sets the clone count for this operation.voidsetHandlingNode(MemcachedNode to)Set a reference to the node that will be/is handling this operation.voidtimeOut()Mark this operation as one which has exceeded its timeout value.protected voidtransitionState(OperationState newState)Transition the state of this operation to the given state.protected voidwasCancelled()This is called on each subclass whenever an operation was cancelled.voidwriteComplete()Invoked after having written all of the bytes from the supplied output buffer.voidwriting()Invoked when we start writing all of the bytes from this operation to the sockets write buffer.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.spy.memcached.ops.Operation
getErrorMsg
-
-
-
-
Field Detail
-
CANCELLED
public static final OperationStatus CANCELLED
Status object for canceled operations.
-
TIMED_OUT
public static final OperationStatus TIMED_OUT
-
state
private volatile OperationState state
-
cmd
private java.nio.ByteBuffer cmd
-
cancelled
private boolean cancelled
-
exception
private OperationException exception
-
callback
protected OperationCallback callback
-
handlingNode
private volatile MemcachedNode handlingNode
-
timedout
private volatile boolean timedout
-
creationTime
private long creationTime
-
timedOutUnsent
private boolean timedOutUnsent
-
notMyVbucketNodes
protected java.util.Collection<MemcachedNode> notMyVbucketNodes
-
writeCompleteTimestamp
private long writeCompleteTimestamp
-
clones
private java.util.List<Operation> clones
If the operation gets cloned, the reference is used to cascade cancellations and timeouts.
-
cloneCount
private volatile int cloneCount
Number of clones for this operation.
-
-
Method Detail
-
getCallback
public final OperationCallback getCallback()
Get the operation callback associated with this operation.- Specified by:
getCallbackin interfaceOperation
-
setCallback
protected void setCallback(OperationCallback to)
Set the callback for this instance.
-
isCancelled
public final boolean isCancelled()
Description copied from interface:OperationHas this operation been cancelled?- Specified by:
isCancelledin interfaceOperation
-
hasErrored
public final boolean hasErrored()
Description copied from interface:OperationTrue if an error occurred while processing this operation.- Specified by:
hasErroredin interfaceOperation
-
getException
public final OperationException getException()
Description copied from interface:OperationGet the exception that occurred (or null if no exception occurred).- Specified by:
getExceptionin interfaceOperation
-
cancel
public final void cancel()
Description copied from interface:OperationCancel this 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:OperationGet the current state of this operation.
-
getBuffer
public final java.nio.ByteBuffer getBuffer()
Description copied from interface:OperationGet the write buffer for this 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:OperationInvoked when we start writing all of the bytes from this operation to the sockets write buffer.
-
writeComplete
public final void writeComplete()
Description copied from interface:OperationInvoked after having written all of the bytes from the supplied output buffer.- Specified by:
writeCompletein interfaceOperation
-
initialize
public abstract void initialize()
Description copied from interface:OperationInitialize this operation. This is used to prepare output byte buffers and stuff.- Specified by:
initializein interfaceOperation
-
readFromBuffer
public abstract void readFromBuffer(java.nio.ByteBuffer data) throws java.io.IOExceptionDescription copied from interface:OperationRead data from the given byte buffer and dispatch to the appropriate read mechanism.- Specified by:
readFromBufferin interfaceOperation- 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:OperationHandle a raw data read.- Specified by:
handleReadin interfaceOperation
-
getHandlingNode
public MemcachedNode getHandlingNode()
Description copied from interface:OperationGet the node that should've been handling this operation.- Specified by:
getHandlingNodein interfaceOperation
-
setHandlingNode
public void setHandlingNode(MemcachedNode to)
Description copied from interface:OperationSet a reference to the node that will be/is handling this operation.- Specified by:
setHandlingNodein interfaceOperation- Parameters:
to- a memcached node
-
timeOut
public void timeOut()
Description copied from interface:OperationMark this operation as one which has exceeded its timeout value.
-
isTimedOut
public boolean isTimedOut()
Description copied from interface:OperationTrue 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:
isTimedOutin interfaceOperation
-
isTimedOut
public boolean isTimedOut(long ttlMillis)
Description copied from interface:OperationTrue 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:
isTimedOutin interfaceOperation- 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:OperationTrue 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:
isTimedOutUnsentin interfaceOperation
-
getWriteCompleteTimestamp
public long getWriteCompleteTimestamp()
Description copied from interface:OperationReturns the timestamp from the point where the WRITE was completed. This can be used to calculate the roundtrip time of the operation.- Specified by:
getWriteCompleteTimestampin interfaceOperation
-
addClone
public void addClone(Operation op)
Description copied from interface:OperationAdd the clone from this operation.
-
getCloneCount
public int getCloneCount()
Description copied from interface:OperationReturns the number of times this operation has been cloned.- Specified by:
getCloneCountin interfaceOperation- Returns:
- the number of clones.
-
setCloneCount
public void setCloneCount(int count)
Description copied from interface:OperationSets the clone count for this operation.- Specified by:
setCloneCountin interfaceOperation
-
-