Class OperationImpl
- java.lang.Object
-
- net.spy.memcached.compat.SpyObject
-
- net.spy.memcached.protocol.BaseOperationImpl
-
- net.spy.memcached.protocol.binary.OperationImpl
-
- All Implemented Interfaces:
Operation
- Direct Known Subclasses:
FlushOperationImpl
,MultiKeyOperationImpl
,NoopOperationImpl
,SASLBaseOperationImpl
,SASLMechsOperationImpl
,SingleKeyOperationImpl
,StatsOperationImpl
,TapOperationImpl
,VersionOperationImpl
public abstract class OperationImpl extends BaseOperationImpl implements Operation
Base class for binary operations.
-
-
Field Summary
Fields Modifier and Type Field Description private byte
cmd
protected static byte
DUMMY_OPCODE
protected static byte[]
EMPTY_BYTES
protected static int
ERR_2BIG
protected static int
ERR_BUSY
protected static int
ERR_DELTA_BADVAL
protected static int
ERR_EXISTS
protected static int
ERR_INTERNAL
protected static int
ERR_INVAL
protected static int
ERR_NO_MEM
protected static int
ERR_NOT_FOUND
protected static int
ERR_NOT_MY_VBUCKET
protected static int
ERR_NOT_STORED
protected static int
ERR_NOT_SUPPORTED
protected static int
ERR_TEMP_FAIL
protected static int
ERR_UNKNOWN_COMMAND
protected int
errorCode
private byte[]
errorMsg
private byte[]
header
private int
headerOffset
protected int
keyLen
protected static int
MIN_RECV_PACKET
protected int
opaque
private byte[]
payload
private int
payloadOffset
protected static byte
REQ_MAGIC
protected static byte
RES_MAGIC
protected long
responseCas
protected byte
responseCmd
protected int
responseOpaque
private static java.util.concurrent.atomic.AtomicInteger
SEQ_NUMBER
protected static OperationStatus
STATUS_OK
protected static int
SUCCESS
Error code for operations.protected short
vbucket
-
Fields inherited from class net.spy.memcached.protocol.BaseOperationImpl
callback, CANCELLED, notMyVbucketNodes, TIMED_OUT
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OperationImpl(byte c, int o, OperationCallback cb)
Construct with opaque.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addExtraHeaders(java.nio.ByteBuffer bb, java.lang.Object... extraHeaders)
Add the extra headers to the writeByteBuffer
.private int
calculateExtraLength(java.lang.Object... extraHeaders)
Calculate the length of all extra headers.(package private) static int
decodeByte(byte[] data, int i)
(package private) static int
decodeInt(byte[] data, int i)
(package private) static long
decodeLong(byte[] data, int i)
protected void
decodePayload(byte[] pl)
Decode the given payload for this command.(package private) static int
decodeShort(byte[] data, int i)
(package private) static long
decodeUnsignedInt(byte[] data, int i)
protected void
finishedPayload(byte[] pl)
(package private) static int
generateOpaque()
Generate an opaque ID.byte[]
getErrorMsg()
Returns the raw bytes of the error message content.protected OperationStatus
getStatusForErrorCode(int errCode, byte[] errPl)
Get the OperationStatus object for the given error code.protected boolean
opaqueIsValid()
Validate an opaque value from the header.private void
parseHeaderFromBuffer()
Parse the header info out of the buffer.protected void
prepareBuffer(java.lang.String key, long cas, byte[] val, java.lang.Object... extraHeaders)
Prepare the buffer for sending.void
readFromBuffer(java.nio.ByteBuffer buffer)
Read from the incomingByteBuffer
.private void
readHeaderFromBuffer(java.nio.ByteBuffer buffer)
Read the header bytes from the incomingByteBuffer
.private void
readPayloadFromBuffer(java.nio.ByteBuffer buffer)
Read the payload from the buffer.protected void
resetInput()
java.lang.String
toString()
-
Methods inherited from class net.spy.memcached.protocol.BaseOperationImpl
addClone, cancel, getBuffer, getCallback, getCloneCount, getException, getHandlingNode, getState, getWriteCompleteTimestamp, handleError, handleRead, hasErrored, initialize, isCancelled, isTimedOut, isTimedOut, isTimedOutUnsent, setBuffer, setCallback, setCloneCount, setHandlingNode, timeOut, transitionState, wasCancelled, writeComplete, writing
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.spy.memcached.ops.Operation
addClone, cancel, getBuffer, getCallback, getCloneCount, getException, getHandlingNode, getState, getWriteCompleteTimestamp, handleRead, hasErrored, initialize, isCancelled, isTimedOut, isTimedOut, isTimedOutUnsent, setCloneCount, setHandlingNode, timeOut, writeComplete, writing
-
-
-
-
Field Detail
-
REQ_MAGIC
protected static final byte REQ_MAGIC
- See Also:
- Constant Field Values
-
RES_MAGIC
protected static final byte RES_MAGIC
- See Also:
- Constant Field Values
-
DUMMY_OPCODE
protected static final byte DUMMY_OPCODE
- See Also:
- Constant Field Values
-
MIN_RECV_PACKET
protected static final int MIN_RECV_PACKET
- See Also:
- Constant Field Values
-
SUCCESS
protected static final int SUCCESS
Error code for operations.- See Also:
- Constant Field Values
-
ERR_NOT_FOUND
protected static final int ERR_NOT_FOUND
- See Also:
- Constant Field Values
-
ERR_EXISTS
protected static final int ERR_EXISTS
- See Also:
- Constant Field Values
-
ERR_2BIG
protected static final int ERR_2BIG
- See Also:
- Constant Field Values
-
ERR_INVAL
protected static final int ERR_INVAL
- See Also:
- Constant Field Values
-
ERR_NOT_STORED
protected static final int ERR_NOT_STORED
- See Also:
- Constant Field Values
-
ERR_DELTA_BADVAL
protected static final int ERR_DELTA_BADVAL
- See Also:
- Constant Field Values
-
ERR_NOT_MY_VBUCKET
protected static final int ERR_NOT_MY_VBUCKET
- See Also:
- Constant Field Values
-
ERR_UNKNOWN_COMMAND
protected static final int ERR_UNKNOWN_COMMAND
- See Also:
- Constant Field Values
-
ERR_NO_MEM
protected static final int ERR_NO_MEM
- See Also:
- Constant Field Values
-
ERR_NOT_SUPPORTED
protected static final int ERR_NOT_SUPPORTED
- See Also:
- Constant Field Values
-
ERR_INTERNAL
protected static final int ERR_INTERNAL
- See Also:
- Constant Field Values
-
ERR_BUSY
protected static final int ERR_BUSY
- See Also:
- Constant Field Values
-
ERR_TEMP_FAIL
protected static final int ERR_TEMP_FAIL
- See Also:
- Constant Field Values
-
EMPTY_BYTES
protected static final byte[] EMPTY_BYTES
-
STATUS_OK
protected static final OperationStatus STATUS_OK
-
SEQ_NUMBER
private static final java.util.concurrent.atomic.AtomicInteger SEQ_NUMBER
-
cmd
private final byte cmd
-
vbucket
protected short vbucket
-
opaque
protected final int opaque
-
header
private final byte[] header
-
headerOffset
private int headerOffset
-
payload
private byte[] payload
-
errorMsg
private byte[] errorMsg
-
keyLen
protected int keyLen
-
responseCmd
protected byte responseCmd
-
errorCode
protected int errorCode
-
responseOpaque
protected int responseOpaque
-
responseCas
protected long responseCas
-
payloadOffset
private int payloadOffset
-
-
Constructor Detail
-
OperationImpl
protected OperationImpl(byte c, int o, OperationCallback cb)
Construct with opaque.- Parameters:
o
- the opaque value.cb
-
-
-
Method Detail
-
resetInput
protected void resetInput()
-
readFromBuffer
public void readFromBuffer(java.nio.ByteBuffer buffer) throws java.io.IOException
Read from the incomingByteBuffer
. Reading from the buffer is done in stages, depending on how much data can be read at once. First, the header is read and then parsed (24 bytes, indicated byMIN_RECV_PACKET
). Then, the payload is read (if one is available for this operation and can be loaded fully).- Specified by:
readFromBuffer
in interfaceOperation
- Specified by:
readFromBuffer
in classBaseOperationImpl
- Parameters:
buffer
- the buffer to read from.- Throws:
java.io.IOException
- if an error happened during parsing/reading.
-
readHeaderFromBuffer
private void readHeaderFromBuffer(java.nio.ByteBuffer buffer)
Read the header bytes from the incomingByteBuffer
.- Parameters:
buffer
- the buffer to read from.
-
parseHeaderFromBuffer
private void parseHeaderFromBuffer()
Parse the header info out of the buffer.
-
readPayloadFromBuffer
private void readPayloadFromBuffer(java.nio.ByteBuffer buffer) throws java.io.IOException
Read the payload from the buffer.- Parameters:
buffer
- the buffer to read from.- Throws:
java.io.IOException
- if an error occures during payload finishing.
-
finishedPayload
protected void finishedPayload(byte[] pl) throws java.io.IOException
- Throws:
java.io.IOException
-
getStatusForErrorCode
protected OperationStatus getStatusForErrorCode(int errCode, byte[] errPl) throws java.io.IOException
Get the OperationStatus object for the given error code.- Parameters:
errCode
- the error code- Returns:
- the status to return, or null if this is an exceptional case
- Throws:
java.io.IOException
-
decodePayload
protected void decodePayload(byte[] pl)
Decode the given payload for this command.- Parameters:
pl
- the payload.
-
opaqueIsValid
protected boolean opaqueIsValid()
Validate an opaque value from the header. This may be overridden from a subclass where the opaque isn't expected to always be the same as the request opaque.
-
decodeShort
static int decodeShort(byte[] data, int i)
-
decodeByte
static int decodeByte(byte[] data, int i)
-
decodeInt
static int decodeInt(byte[] data, int i)
-
decodeUnsignedInt
static long decodeUnsignedInt(byte[] data, int i)
-
decodeLong
static long decodeLong(byte[] data, int i)
-
prepareBuffer
protected void prepareBuffer(java.lang.String key, long cas, byte[] val, java.lang.Object... extraHeaders)
Prepare the buffer for sending.- Parameters:
key
- the key (for keyed ops).cas
- the cas value.val
- the data payload.extraHeaders
- any additional headers that need to be sent.
-
addExtraHeaders
private void addExtraHeaders(java.nio.ByteBuffer bb, java.lang.Object... extraHeaders)
Add the extra headers to the writeByteBuffer
.- Parameters:
bb
- the buffer where to append.extraHeaders
- the headers to append.
-
calculateExtraLength
private int calculateExtraLength(java.lang.Object... extraHeaders)
Calculate the length of all extra headers.- Parameters:
extraHeaders
- the list of extra headers to count.- Returns:
- the length of the extra headers.
-
generateOpaque
static int generateOpaque()
Generate an opaque ID.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getErrorMsg
public byte[] getErrorMsg()
Description copied from interface:Operation
Returns the raw bytes of the error message content.- Specified by:
getErrorMsg
in interfaceOperation
- Returns:
- the raw error message content.
-
-