org.opends.server.replication.protocol
Class ReplicationMessage

java.lang.Object
  extended by org.opends.server.replication.protocol.ReplicationMessage
Direct Known Subclasses:
AckMessage, HeartbeatMessage, ReplServerInfoMessage, ResetGenerationId, RoutableMessage, StartMessage, UpdateMessage, WindowMessage, WindowProbe

public abstract class ReplicationMessage
extends java.lang.Object

Abstract class that must be used when defining messages that can be sent for replication purpose between servers. When extending this class one should also create a new MSG_TYPE and should update the generateMsg() method.


Constructor Summary
ReplicationMessage()
           
 
Method Summary
protected  int addByteArray(byte[] tail, byte[] resultByteArray, int pos)
          Concatenate the tail byte array into the resultByteArray.
static ReplicationMessage generateMsg(byte[] buffer)
          Generates a ReplicationMessage from its encoded form.
abstract  byte[] getBytes()
          Return the byte[] representation of this message.
protected  int getNextLength(byte[] in, int pos)
          Get the length of the next String encoded in the in byte array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplicationMessage

public ReplicationMessage()
Method Detail

getBytes

public abstract byte[] getBytes()
                         throws java.io.UnsupportedEncodingException
Return the byte[] representation of this message. Depending on the message type, the first byte of the byte[] must be. MSG_TYPE_MODIFY_REQUEST MSG_TYPE_ADD_REQUEST MSG_TYPE_DELETE_REQUEST MSG_TYPE_MODIFY_DN_REQUEST MSG_TYPE_ACK MSG_TYPE_SERVER_START MSG_TYPE_REPL_SERVER_START MSG_TYPE_WINDOW MSG_TYPE_HEARTBEAT MSG_TYPE_INITIALIZE MSG_TYPE_INITIALIZE_TARGET MSG_TYPE_ENTRY MSG_TYPE_DONE MSG_TYPE_ERROR MSG_TYPE_WINDOW_PROBE MSG_TYPE_REPL_SERVER_INFO MSG_TYPE_RESET_GENERATION_ID MSG_TYPE_REPL_SERVER_MONITOR_REQUEST MSG_TYPE_REPL_SERVER_MONITOR

Returns:
the byte[] representation of this message.
Throws:
java.io.UnsupportedEncodingException - When the encoding of the message failed because the UTF-8 encoding is not supported.

generateMsg

public static ReplicationMessage generateMsg(byte[] buffer)
                                      throws java.util.zip.DataFormatException,
                                             java.io.UnsupportedEncodingException
Generates a ReplicationMessage from its encoded form.

Parameters:
buffer - The encode form of the ReplicationMessage.
Returns:
the generated SycnhronizationMessage.
Throws:
java.util.zip.DataFormatException - if the encoded form was not a valid msg.
java.io.UnsupportedEncodingException - if UTF8 is not supported.

addByteArray

protected int addByteArray(byte[] tail,
                           byte[] resultByteArray,
                           int pos)
Concatenate the tail byte array into the resultByteArray. The resultByteArray must be large enough before calling this method.

Parameters:
tail - the byte array to concatenate.
resultByteArray - The byte array to concatenate to.
pos - the position where to concatenate.
Returns:
the next position to use in the resultByteArray.

getNextLength

protected int getNextLength(byte[] in,
                            int pos)
                     throws java.util.zip.DataFormatException
Get the length of the next String encoded in the in byte array.

Parameters:
in - the byte array where to calculate the string.
pos - the position whre to start from in the byte array.
Returns:
the length of the next string.
Throws:
java.util.zip.DataFormatException - If the byte array does not end with null.