com.sleepycat.je.rep.impl
Class TextProtocol

java.lang.Object
  extended by com.sleepycat.je.rep.impl.TextProtocol
Direct Known Subclasses:
NodeStateProtocol, Protocol, Protocol, RepGroupProtocol

public abstract class TextProtocol
extends Object

SimpleProtocol provides the support for implementing simple low performance protocols involving replication nodes. The protocol is primarily text based, and checks group membership and version matches with every message favoring flexibility over performance. The base class is primarily responsible for the message formatting and message envelope validation. The subclasses define the specific messages that constitute the protocol and the request/response semantics. Every message has the format: |||| is the version of the protocol in use. identifies a group participating in an election. It avoids accidental cross-talk across groups holding concurrent elections. identifies the originator of the message within the group. the operation identified by the specific message. the payload associated with the particular operation.


Nested Class Summary
 class TextProtocol.Fail
           
static class TextProtocol.InvalidMessageException
          Used to indicate a message format or invalid content exception.
 class TextProtocol.Message
          Base message class for all messages exchanged in the protocol.
static class TextProtocol.MessageError
           
 class TextProtocol.MessageExchange
          Use to parallelize message exchanges via Futures.
static class TextProtocol.MessageOp
          The Operations that are part of the protocol.
 class TextProtocol.OK
           
 class TextProtocol.ProtocolError
           
 class TextProtocol.RequestMessage
          Base class for all Request messages
 class TextProtocol.ResponseMessage
          Base classes for response messages.
protected static class TextProtocol.StringFormatable
           
static class TextProtocol.TOKENS
          Represents the tokens on a message line.
protected static interface TextProtocol.WireFormatable
           
 
Field Summary
protected  EnvironmentImpl envImpl
           
 TextProtocol.MessageOp FAIL_RESP
           
protected  Formatter formatter
           
protected  Logger logger
           
protected  String messageNocheckSuffix
           
 TextProtocol.MessageOp OK_RESP
           
 TextProtocol.MessageOp PROTOCOL_ERROR
           
static String SEPARATOR
           
static String SEPARATOR_REGEXP
           
 
Constructor Summary
TextProtocol(String version, String groupName, NameIdPair nameIdPair, EnvironmentImpl envImpl)
          Creates an instance of the Protocol.
 
Method Summary
 int getMajorVersionNumber(String version)
          Returns the Integer number which represents a Protocol version.
 int getOpenTimeout()
           
 int getReadTimeout()
           
 TextProtocol.RequestMessage getRequestMessage(SocketChannel channel)
          Reads the channel and returns a read request.
protected  void initializeMessageOps(TextProtocol.MessageOp[] protocolOps)
          The messages as defined by the subclass.
 int messageCount()
           
 TextProtocol.Message parse(String line)
          Parses a line into a Request/Response message.
 TextProtocol.RequestMessage parseRequest(String requestLine)
          Converts a request line into a requestMessage.
(package private)  TextProtocol.ResponseMessage parseResponse(String responseLine)
          Converts a response line into a ResponseMessage.
 TextProtocol.ResponseMessage process(Object requestProcessor, TextProtocol.RequestMessage requestMessage)
           
protected  void setTimeouts(RepImpl repImpl, DurationConfigParam openTimeoutConfig, DurationConfigParam readTimeoutConfig)
          Set the network timeouts associated with uses of this protocol instance.
 void updateNodeIds(Set<Integer> newMemberIds)
          Updates the current set of nodes that constitutes the group.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

messageNocheckSuffix

protected final String messageNocheckSuffix

SEPARATOR

public static final String SEPARATOR
See Also:
Constant Field Values

SEPARATOR_REGEXP

public static final String SEPARATOR_REGEXP
See Also:
Constant Field Values

PROTOCOL_ERROR

public final TextProtocol.MessageOp PROTOCOL_ERROR

OK_RESP

public final TextProtocol.MessageOp OK_RESP

FAIL_RESP

public final TextProtocol.MessageOp FAIL_RESP

logger

protected final Logger logger

formatter

protected final Formatter formatter

envImpl

protected final EnvironmentImpl envImpl
Constructor Detail

TextProtocol

public TextProtocol(String version,
                    String groupName,
                    NameIdPair nameIdPair,
                    EnvironmentImpl envImpl)
Creates an instance of the Protocol.

Parameters:
nameIdPair - a unique identifier for this node
envImpl - for logging, may be null
Method Detail

setTimeouts

protected void setTimeouts(RepImpl repImpl,
                           DurationConfigParam openTimeoutConfig,
                           DurationConfigParam readTimeoutConfig)
Set the network timeouts associated with uses of this protocol instance.


initializeMessageOps

protected void initializeMessageOps(TextProtocol.MessageOp[] protocolOps)
The messages as defined by the subclass. Note that PROTOCOL_ERROR is a pre-defined message that is defined by this class. The initialization is not considered until this method after been invoked typically in the constructor itself. This two-step is unfortunately necessary since the creation of MessageOps instances requires that this class be completely initialized, otherwise the MessageOp list could have been passed in as a constructor argument.

Parameters:
protocolOps - the message ops defined by the subclass.

getOpenTimeout

public int getOpenTimeout()

getReadTimeout

public int getReadTimeout()

messageCount

public int messageCount()

updateNodeIds

public void updateNodeIds(Set<Integer> newMemberIds)
Updates the current set of nodes that constitutes the group. Also update the id used in the header, in case it was null and isn't anymore.

Parameters:
newMemberIds -

getMajorVersionNumber

public int getMajorVersionNumber(String version)
Returns the Integer number which represents a Protocol version.


parse

public TextProtocol.Message parse(String line)
                           throws TextProtocol.InvalidMessageException
Parses a line into a Request/Response message.

Parameters:
line - containing the message
Returns:
a message instance
Throws:
TextProtocol.InvalidMessageException

parseResponse

TextProtocol.ResponseMessage parseResponse(String responseLine)
                                     throws TextProtocol.InvalidMessageException
Converts a response line into a ResponseMessage.

Parameters:
responseLine -
Returns:
the response message
Throws:
TextProtocol.InvalidMessageException

parseRequest

public TextProtocol.RequestMessage parseRequest(String requestLine)
                                         throws TextProtocol.InvalidMessageException
Converts a request line into a requestMessage.

Parameters:
requestLine -
Returns:
the request message
Throws:
TextProtocol.InvalidMessageException

getRequestMessage

public TextProtocol.RequestMessage getRequestMessage(SocketChannel channel)
                                              throws IOException
Reads the channel and returns a read request. If the message format was bad, it sends a ProtocolError response back over the channel and no further action is needed by the caller.

Parameters:
channel - the channel delivering the request
Returns:
null if EOF was reached or the message format was bad
Throws:
IOException

process

public TextProtocol.ResponseMessage process(Object requestProcessor,
                                            TextProtocol.RequestMessage requestMessage)


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