public abstract class BinaryProtocol extends Object
| Modifier and Type | Class and Description |
|---|---|
class |
BinaryProtocol.ClientVersion |
class |
BinaryProtocol.IncompatibleVersion |
class |
BinaryProtocol.Message
Base message class for all messages exchanged in the protocol.
|
static class |
BinaryProtocol.MessageOp
The Operations that are part of the protocol.
|
class |
BinaryProtocol.ProtocolError |
static class |
BinaryProtocol.ProtocolException
Thrown in response to an unexpected response to a request.
|
class |
BinaryProtocol.RejectMessage
The base class for reject responses to requests
|
class |
BinaryProtocol.ServerVersion |
protected class |
BinaryProtocol.SimpleMessage
Base class for simple messages.
|
| Modifier and Type | Field and Description |
|---|---|
BinaryProtocol.MessageOp |
CLIENT_VERSION |
protected int |
codeVersion |
protected int |
configuredVersion |
protected EnvironmentImpl |
envImpl |
protected Formatter |
formatter |
protected ByteBuffer |
header |
BinaryProtocol.MessageOp |
INCOMPATIBLE_VERSION |
protected Logger |
logger |
protected static int |
MESSAGE_HEADER_SIZE |
protected NameIdPair |
nameIdPair |
protected LongStat |
nBytesRead |
protected LongStat |
nBytesWritten |
protected LongStat |
nEntriesWrittenOldVersion |
protected LongStat |
nMessageBatches |
protected LongStat |
nMessagesBatched |
protected LongStat |
nMessagesRead |
protected LongStat |
nMessagesWritten |
protected LongStat |
nReadNanos |
protected LongStat |
nWriteNanos |
BinaryProtocol.MessageOp |
PROTOCOL_ERROR |
BinaryProtocol.MessageOp |
SERVER_VERSION |
protected StatGroup |
stats |
| Modifier | Constructor and Description |
|---|---|
protected |
BinaryProtocol(NameIdPair nameIdPair,
int codeVersion,
int configuredVersion,
EnvironmentImpl envImpl)
Returns a Protocol object configured that implements the specified
(supported) version.
|
| Modifier and Type | Method and Description |
|---|---|
int |
bufferWrite(WritableByteChannel channel,
ByteBuffer batchWriteBuffer,
int nMessages,
BinaryProtocol.Message message)
Buffers the serialized form of the message (if possible) for later
writes to the network.
|
void |
flushBufferedWrites(WritableByteChannel channel,
ByteBuffer batchWriteBuffer,
int nMessages)
Flush all the messages accumulated by earlier calls to bufferWrite
|
int |
getPredefinedMessageCount() |
StatGroup |
getStats(StatsConfig config) |
String |
getString(ByteBuffer buffer)
Reconstitutes the string serialized by the above method.
|
int |
getVersion()
Returns the version associated with this protocol instance.
|
protected void |
initializeMessageOps(BinaryProtocol.MessageOp[] protocolOps) |
int |
messageCount() |
void |
putString(String s,
ByteBuffer buffer) |
BinaryProtocol.Message |
read(ReadableByteChannel channel)
Read and parse an incoming message, specifying the incoming version.
|
<T extends BinaryProtocol.Message> |
read(ReadableByteChannel channel,
Class<T> cl) |
void |
resetStats() |
int |
stringSize(String s) |
void |
write(BinaryProtocol.Message message,
NamedChannel namedChannel)
Write a message out to a channel.
|
void |
write(BinaryProtocol.Message message,
WritableByteChannel channel)
Write a message out to a channel.
|
protected static final int MESSAGE_HEADER_SIZE
protected final ByteBuffer header
protected final int codeVersion
protected int configuredVersion
protected final NameIdPair nameIdPair
public final BinaryProtocol.MessageOp CLIENT_VERSION
public final BinaryProtocol.MessageOp SERVER_VERSION
public final BinaryProtocol.MessageOp INCOMPATIBLE_VERSION
public final BinaryProtocol.MessageOp PROTOCOL_ERROR
protected final StatGroup stats
protected final LongStat nReadNanos
protected final LongStat nWriteNanos
protected final LongStat nBytesRead
protected final LongStat nMessagesRead
protected final LongStat nBytesWritten
protected final LongStat nMessagesWritten
protected final LongStat nMessagesBatched
protected final LongStat nMessageBatches
protected final LongStat nEntriesWrittenOldVersion
protected final Logger logger
protected final Formatter formatter
protected final EnvironmentImpl envImpl
protected BinaryProtocol(NameIdPair nameIdPair, int codeVersion, int configuredVersion, EnvironmentImpl envImpl)
codeVersion - the version actually implemented by the protocol.configuredVersion - the version of the protocol that must be
implemented/simulated by this protocol when communicating with the
recipient.protected void initializeMessageOps(BinaryProtocol.MessageOp[] protocolOps)
public int messageCount()
public final int getPredefinedMessageCount()
public int getVersion()
public StatGroup getStats(StatsConfig config)
public void resetStats()
public int stringSize(String s)
public void putString(String s, ByteBuffer buffer)
public String getString(ByteBuffer buffer)
buffer - the buffer containing the stringpublic BinaryProtocol.Message read(ReadableByteChannel channel) throws IOException
channel - the channel to read from. Declared as a
ReadableByteChannel rather than the more obvious SocketChannel to
facilitate unit testing.IOExceptionpublic <T extends BinaryProtocol.Message> T read(ReadableByteChannel channel, Class<T> cl) throws IOException, BinaryProtocol.ProtocolException
public void write(BinaryProtocol.Message message, NamedChannel namedChannel) throws IOException
IOExceptionpublic void write(BinaryProtocol.Message message, WritableByteChannel channel) throws IOException
IOExceptionpublic int bufferWrite(WritableByteChannel channel, ByteBuffer batchWriteBuffer, int nMessages, BinaryProtocol.Message message) throws IOException
channel - the channel to which the buffer is flushed on buffer
overflows.batchWriteBuffer - the buffer accumulating the serialized messages
It's best for performance if this is a direct byte buffer, to avoid
another copy when the buffer is finally flushed.nMessages - the number of messages currently in the buffer,
including this message, that is, nMessages is always > 0 upon entry.message - the message to be buffered.IOExceptionpublic void flushBufferedWrites(WritableByteChannel channel, ByteBuffer batchWriteBuffer, int nMessages) throws IOException
channel - the channel to which the buffer is flushed.batchWriteBuffer - the buffer containing the accumulated messagesnMessages - the number of messages in the batchIOExceptionCopyright © 2024. All rights reserved.