Class ReplicationMessage
java.lang.Object
org.apache.derby.impl.store.replication.net.ReplicationMessage
- All Implemented Interfaces:
Externalizable
,Serializable
This message is used for the communication between the master and the
slave during Replication. The message is composed of a type flag
and corresponding object. Each type flag indicating the type of the
content bundled inside the message.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Object
This is the content of the replication message.static final long
The version number is determined based on the database version of the current database.private int
The valid values for the type of the content of the message are listed below.static final int
This flag is used to send an acknowledgment of successful completion of a requested operation.static final int
Indicates that the requested operation was not able to be completed successfully.static final int
Used to signal the slave that it must failover.static final int
Used during the intial handshake between the master and the slave.static final int
used during the intial handshake between the master and the slave.static final int
This flag will be used for all messages that carry log records.static final int
A message used to check if the replication network is working.static final int
A message sent as a response to a TYPE_PING message.static final int
Used to send a stop replication signal to the slave. -
Constructor Summary
ConstructorsConstructorDescriptionpublic No args constructor required with Externalizable.ReplicationMessage
(int type, Object message) Constructor used to set thetype
andmessage
. -
Method Summary
Modifier and TypeMethodDescriptionUsed to get the actual message that is wrapped inside the ReplicationMessage object.int
getType()
Used to get the type of thisReplicationMessage
.void
Used to restore the contents of this object.void
Used to save the contents of this Object.
-
Field Details
-
serialVersionUID
public static final long serialVersionUIDThe version number is determined based on the database version of the current database. This would help to establish if the master and the slave in replication are at compatible database versions.- See Also:
-
message
This is the content of the replication message. -
type
private int typeThe valid values for the type of the content of the message are listed below. -
TYPE_INITIATE_VERSION
public static final int TYPE_INITIATE_VERSIONused during the intial handshake between the master and the slave. The initial handshake helps to negotiate the message UIDs and send a appropriate error or acknowledgment. The object this message contains will be aLong
. IMPORTANT: This constant must not be changed in future versions since we need it to decide slave/master version mismatch- See Also:
-
TYPE_INITIATE_INSTANT
public static final int TYPE_INITIATE_INSTANTUsed during the intial handshake between the master and the slave. Messages of this type are used to ensure that master and slave have identical log files by checking that they will insert the next log record on the same byte position in the log. The object this message contains will be aLong
.- See Also:
-
TYPE_LOG
public static final int TYPE_LOGThis flag will be used for all messages that carry log records. The Object this message type contains will be abyte
array. The content of the byte array is the log records in the binary form.- See Also:
-
TYPE_ACK
public static final int TYPE_ACKThis flag is used to send an acknowledgment of successful completion of a requested operation. It will however not be used to signify reception for every message transmission. The object this message type contains will be aString
. The SQLState of the error message can be used here.- See Also:
-
TYPE_ERROR
public static final int TYPE_ERRORIndicates that the requested operation was not able to be completed successfully. The object this message type contains will be aString[]
where the first length-1 fields are used as arguments to create the exception and the last field contains the SQLState. The SQLState is the last element in the Array, because this means that the whole Array can be used as input to the StandardException creator. The SQLState will be ignored by the exception creator because there is one argument too many. This way we don't have to make a copy of the received Array, containing all elements except the SQLState element.- See Also:
-
TYPE_PING
public static final int TYPE_PINGA message used to check if the replication network is working. This message type has no object- See Also:
-
TYPE_PONG
public static final int TYPE_PONGA message sent as a response to a TYPE_PING message. This message type has no object- See Also:
-
TYPE_STOP
public static final int TYPE_STOPUsed to send a stop replication signal to the slave. Since this is a control signal the object this message contains will be null.- See Also:
-
TYPE_FAILOVER
public static final int TYPE_FAILOVERUsed to signal the slave that it must failover. The object associated with this message will be null.- See Also:
-
-
Constructor Details
-
ReplicationMessage
public ReplicationMessage()public No args constructor required with Externalizable. -
ReplicationMessage
Constructor used to set thetype
andmessage
. This is used while creating messages for sending while readExternal is used on the receiving end.- Parameters:
type
- The type of this message. Must be one of the message type constants of this class (TYPE_LOG, TYPE_ACK, TYPE_ERROR, TYPE_INITIATE).message
- The message to be transmitted.
-
-
Method Details
-
getMessage
Used to get the actual message that is wrapped inside the ReplicationMessage object.- Returns:
- The object contained in the message
-
getType
public int getType()Used to get the type of thisReplicationMessage
.- Returns:
- The type of the message.
-
readExternal
Used to restore the contents of this object.- Specified by:
readExternal
in interfaceExternalizable
- Parameters:
in
- the stream to read data from in order to restore the object.- Throws:
IOException
- If an exception occurs while reading from theInputStream
.ClassNotFoundException
- Class of a serialized object cannot be found.
-
writeExternal
Used to save the contents of this Object.- Specified by:
writeExternal
in interfaceExternalizable
- Parameters:
out
- the stream to write the object to.- Throws:
IOException
- if an exception occurs while writing to theOutputStream
.
-