com.sleepycat.je.rep.utilint
Class BinaryProtocol

java.lang.Object
  extended by com.sleepycat.je.rep.utilint.BinaryProtocol
Direct Known Subclasses:
BinaryNodeStateProtocol, Protocol, Protocol, Protocol

public abstract class BinaryProtocol
extends Object

Supplies the basic infrastructure for BinaryProtocols used to exchange messages by the replications stream and during network based restore operations. Note that this class and its subclasses are not synchronized. There must be one instance of this class per thread of control. IMPORTANT: Please avoid all uses of ByteBuffer.get/put when serializing message fields of types: long, int and short to avoid byte order issues. Use LogUtils.read/write methods instead, since they use a single canonical byte-independent representation.


Nested Class Summary
 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.
(package private)  class BinaryProtocol.ProtocolVersion
          Version broadcasts the sending node's protocol version.
 class BinaryProtocol.RejectMessage
          The base class for reject responses to requests
 class BinaryProtocol.ServerVersion
           
protected  class BinaryProtocol.SimpleMessage
          Base class for simple messages.
(package private) static interface BinaryProtocol.WireFormatable
           
 
Field Summary
 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 nMessagesRead
           
protected  LongStat nMessagesWritten
           
protected  LongStat nReadNanos
           
protected  LongStat nWriteNanos
           
 BinaryProtocol.MessageOp PROTOCOL_ERROR
           
 BinaryProtocol.MessageOp SERVER_VERSION
           
protected  StatGroup stats
           
 
Constructor Summary
protected BinaryProtocol(NameIdPair nameIdPair, int codeVersion, int configuredVersion, EnvironmentImpl envImpl)
          Returns a Protocol object configured that implements the specified (supported) version.
 
Method Summary
 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>
T
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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MESSAGE_HEADER_SIZE

protected static final int MESSAGE_HEADER_SIZE
See Also:
Constant Field Values

header

protected final ByteBuffer header

codeVersion

protected final int codeVersion

configuredVersion

protected int configuredVersion

nameIdPair

protected final NameIdPair nameIdPair

CLIENT_VERSION

public final BinaryProtocol.MessageOp CLIENT_VERSION

SERVER_VERSION

public final BinaryProtocol.MessageOp SERVER_VERSION

INCOMPATIBLE_VERSION

public final BinaryProtocol.MessageOp INCOMPATIBLE_VERSION

PROTOCOL_ERROR

public final BinaryProtocol.MessageOp PROTOCOL_ERROR

stats

protected final StatGroup stats

nReadNanos

protected final LongStat nReadNanos

nWriteNanos

protected final LongStat nWriteNanos

nBytesRead

protected final LongStat nBytesRead

nMessagesRead

protected final LongStat nMessagesRead

nBytesWritten

protected final LongStat nBytesWritten

nMessagesWritten

protected final LongStat nMessagesWritten

logger

protected final Logger logger

formatter

protected final Formatter formatter

envImpl

protected final EnvironmentImpl envImpl
Constructor Detail

BinaryProtocol

protected BinaryProtocol(NameIdPair nameIdPair,
                         int codeVersion,
                         int configuredVersion,
                         EnvironmentImpl envImpl)
Returns a Protocol object configured that implements the specified (supported) version.

Parameters:
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.
Method Detail

initializeMessageOps

protected void initializeMessageOps(BinaryProtocol.MessageOp[] protocolOps)

messageCount

public int messageCount()

getPredefinedMessageCount

public final int getPredefinedMessageCount()

getVersion

public int getVersion()
Returns the version associated with this protocol instance. Request message generated by this instance conform to this version and responses are expected to conform to this version as well.

Returns:
the version that is actually being used.

getStats

public StatGroup getStats(StatsConfig config)

resetStats

public void resetStats()

stringSize

public int stringSize(String s)

putString

public void putString(String s,
                      ByteBuffer buffer)

getString

public String getString(ByteBuffer buffer)
Reconstitutes the string serialized by the above method.

Parameters:
buffer - the buffer containing the string
Returns:
the de-serialized string

read

public BinaryProtocol.Message read(ReadableByteChannel channel)
                            throws IOException
Read and parse an incoming message, specifying the incoming version.

Parameters:
channel - the channel to read from. Declared as a ReadableByteChannel rather than the more obvious SocketChannel to facilitate unit testing.
Throws:
IOException

read

public <T extends BinaryProtocol.Message> T read(ReadableByteChannel channel,
                                                 Class<T> cl)
                                      throws IOException,
                                             BinaryProtocol.ProtocolException
Throws:
IOException
BinaryProtocol.ProtocolException

write

public void write(BinaryProtocol.Message message,
                  NamedChannel namedChannel)
           throws IOException
Write a message out to a channel.

Throws:
IOException

write

public void write(BinaryProtocol.Message message,
                  WritableByteChannel channel)
           throws IOException
Write a message out to a channel.

Throws:
IOException


Copyright (c) 2004-2012 Oracle. All rights reserved.