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
Base class for protocol-specific operation implementations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected OperationCallback
private boolean
static final OperationStatus
Status object for canceled operations.private int
Number of clones for this operation.If the operation gets cloned, the reference is used to cascade cancellations and timeouts.private ByteBuffer
private long
private OperationException
private MemcachedNode
protected Collection
<MemcachedNode> private OperationState
static final OperationStatus
private boolean
private boolean
private long
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Add the clone from this operation.final void
cancel()
Cancel this operation.final ByteBuffer
Get the write buffer for this operation.final OperationCallback
Get the operation callback associated with this operation.int
Returns the number of times this operation has been cloned.final OperationException
Get the exception that occurred (or null if no exception occurred).Get the node that should've been handling this operation.final OperationState
getState()
Get the current state of this operation.long
Returns the timestamp from the point where the WRITE was completed.protected void
handleError
(OperationErrorType eType, String line) void
handleRead
(ByteBuffer data) Handle a raw data read.final boolean
True if an error occurred while processing this operation.abstract void
Initialize this operation.final boolean
Has this operation been cancelled?boolean
True if the operation has timed out.boolean
isTimedOut
(long ttlMillis) True if the operation has timed out.boolean
True if the operation has timed out and has not been sent.abstract void
readFromBuffer
(ByteBuffer data) Read data from the given byte buffer and dispatch to the appropriate read mechanism.protected final void
setBuffer
(ByteBuffer to) Set the write buffer for this operation.protected void
Set the callback for this instance.void
setCloneCount
(int count) Sets the clone count for this operation.void
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 final void
transitionState
(OperationState newState) Transition the state of this operation to the given state.protected void
This is called on each subclass whenever an operation was cancelled.final void
Invoked after having written all of the bytes from the supplied output buffer.final void
writing()
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 Details
-
CANCELLED
Status object for canceled operations. -
TIMED_OUT
-
state
-
cmd
-
cancelled
private boolean cancelled -
exception
-
callback
-
handlingNode
-
timedout
private volatile boolean timedout -
creationTime
private long creationTime -
timedOutUnsent
private boolean timedOutUnsent -
notMyVbucketNodes
-
writeCompleteTimestamp
private long writeCompleteTimestamp -
clones
If the operation gets cloned, the reference is used to cascade cancellations and timeouts. -
cloneCount
private volatile int cloneCountNumber of clones for this operation.
-
-
Constructor Details
-
BaseOperationImpl
public BaseOperationImpl()
-
-
Method Details
-
getCallback
Get the operation callback associated with this operation.- Specified by:
getCallback
in interfaceOperation
-
setCallback
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 interfaceOperation
-
hasErrored
public final boolean hasErrored()Description copied from interface:Operation
True if an error occurred while processing this operation.- Specified by:
hasErrored
in interfaceOperation
-
getException
Description copied from interface:Operation
Get the exception that occurred (or null if no exception occurred).- Specified by:
getException
in interfaceOperation
-
cancel
public final void cancel()Description copied from interface:Operation
Cancel this operation. -
wasCancelled
protected void wasCancelled()This is called on each subclass whenever an operation was cancelled. -
getState
Description copied from interface:Operation
Get the current state of this operation. -
getBuffer
Description copied from interface:Operation
Get the write buffer for this operation. -
setBuffer
Set the write buffer for this operation. -
transitionState
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. -
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 interfaceOperation
-
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 interfaceOperation
-
readFromBuffer
Description copied from interface:Operation
Read data from the given byte buffer and dispatch to the appropriate read mechanism.- Specified by:
readFromBuffer
in interfaceOperation
- Throws:
IOException
-
handleError
- Throws:
IOException
-
handleRead
Description copied from interface:Operation
Handle a raw data read.- Specified by:
handleRead
in interfaceOperation
-
getHandlingNode
Description copied from interface:Operation
Get the node that should've been handling this operation.- Specified by:
getHandlingNode
in interfaceOperation
-
setHandlingNode
Description copied from interface:Operation
Set a reference to the node that will be/is handling this operation.- Specified by:
setHandlingNode
in interfaceOperation
- 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. -
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 interfaceOperation
-
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 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: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 interfaceOperation
-
getWriteCompleteTimestamp
public long getWriteCompleteTimestamp()Description copied from interface:Operation
Returns the timestamp from the point where the WRITE was completed. This can be used to calculate the roundtrip time of the operation.- Specified by:
getWriteCompleteTimestamp
in interfaceOperation
-
addClone
Description copied from interface:Operation
Add the clone from this operation. -
getCloneCount
public int getCloneCount()Description copied from interface:Operation
Returns the number of times this operation has been cloned.- Specified by:
getCloneCount
in interfaceOperation
- Returns:
- the number of clones.
-
setCloneCount
public void setCloneCount(int count) Description copied from interface:Operation
Sets the clone count for this operation.- Specified by:
setCloneCount
in interfaceOperation
-