Top Description Inners Fields Constructors Methods
org.apache.derby.impl.store.replication.net

public Class ReplicationMessageTransmit

extends Object
Class Inheritance
Imports
java.io.IOException, java.net.InetSocketAddress, .Socket, .SocketTimeoutException, javax.net.SocketFactory, org.apache.derby.shared.common.error.StandardException, org.apache.derby.shared.common.reference.SQLState, .MessageId, org.apache.derby.iapi.util.InterruptStatus

Used to send replication messages to the slave. Called by the Master controller to transmit replication messages wrapped in a ReplicationMessage object to a receiver. The receiver is implemented by the ReplicationMessageReceive class.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
ReplicationMessageTransmit.MasterReceiverThread

Thread that listens for messages from the slave.

Field Summary

Modifier and TypeField and Description
private String
dbname

The name of the replicated database

private final int
DEFAULT_MESSAGE_RESPONSE_TIMEOUT

Number of millis to wait for a response message before timing out

private ReplicationMessage
receivedMsg

The message received from the slave as a response to sending a message.

private final Object
receiveSemaphore

Used to synchronize when waiting for a response message from the slave

private final SlaveAddress
slaveAddress

Contains the address (hostname and port number) of the slave to replicate to.

private SocketConnection
socketConn

Used to write/read message objects to/from a connection.

private volatile boolean
stopMessageReceiver

Whether or not to keep the message receiver thread alive.

Constructor Summary

AccessConstructor and Description
public
ReplicationMessageTransmit(SlaveAddress
contains the address (host name and port number) of the slave to connect to.
slaveAddress
)

Constructor initializes the slave address used in replication.

Method Summary

Modifier and TypeMethod and Description
private void
brokerConnection(long
the master log instant, used to check that the master and slave log files are in synch. If no chunks of log records have been shipped to the slave yet, this is the end position in the current log file. If a chunk of log has been shipped, this is the instant of the log record shipped last. Note that there is a difference!
synchOnInstant
)

Used to send initiator messages to the slave and receive information about the compatibility of the slave with the master.

private void
checkSocketConnection()

Verifies if the SocketConnection is valid.

public void
initConnection(int
the amount of time for which the connection should block before being established.
timeout
,
long
the master log instant, used to check that the master and slave log files are in synch. If no chunks of log records have been shipped to the slave yet, this is the end position in the current log file. If a chunk of log has been shipped, this is the instant of the log record shipped last. Note that there is a difference!
synchOnInstant
)

Used to create a Socket connection to the slave and establish compatibility with the database version of the slave by comparing the UID's of the ReplicationMessage classes of the master and the slave.

public void
sendMessage(ReplicationMessage
a ReplicationMessage object that contains the message to be transmitted.
message
)

Used to send a replication message to the slave.

public synchronized ReplicationMessage

Returns:

the response message
sendMessageWaitForReply
(ReplicationMessage
a ReplicationMessage object that contains the message to be transmitted.
message
)

Send a replication message to the slave and return the message received as a response.

private void
public void
tearDown()

Tear down the network connection established with the other replication peer

private boolean
verifyMessageType(ReplicationMessage message, int expectedType)

Used to parse a message received from the slave.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dbnameback to summary
private String dbname

The name of the replicated database

DEFAULT_MESSAGE_RESPONSE_TIMEOUTback to summary
private final int DEFAULT_MESSAGE_RESPONSE_TIMEOUT

Number of millis to wait for a response message before timing out

receivedMsgback to summary
private ReplicationMessage receivedMsg

The message received from the slave as a response to sending a message.

receiveSemaphoreback to summary
private final Object receiveSemaphore

Used to synchronize when waiting for a response message from the slave

slaveAddressback to summary
private final SlaveAddress slaveAddress

Contains the address (hostname and port number) of the slave to replicate to.

socketConnback to summary
private SocketConnection socketConn

Used to write/read message objects to/from a connection.

stopMessageReceiverback to summary
private volatile boolean stopMessageReceiver

Whether or not to keep the message receiver thread alive. Set to true to terminate the thread

Constructor Detail

ReplicationMessageTransmitback to summary
public ReplicationMessageTransmit(SlaveAddress slaveAddress)

Constructor initializes the slave address used in replication.

Parameters
slaveAddress:SlaveAddress

contains the address (host name and port number) of the slave to connect to.

Method Detail

brokerConnectionback to summary
private void brokerConnection(long synchOnInstant) throws IOException, StandardException, ClassNotFoundException

Used to send initiator messages to the slave and receive information about the compatibility of the slave with the master. One message is used to check that the slave and master have the same software versions. A second message is used to check that the master and slave log files are in synch.

Parameters
synchOnInstant:long

the master log instant, used to check that the master and slave log files are in synch. If no chunks of log records have been shipped to the slave yet, this is the end position in the current log file. If a chunk of log has been shipped, this is the instant of the log record shipped last. Note that there is a difference!

Exceptions
IOException:
if an exception occurs during the sending or reading of the message.
StandardException:
If an error message is received from the server indicating a mis-match in serialVersionUID or log files out of synch.
ClassNotFoundException:
Class of a serialized object cannot be found.
checkSocketConnectionback to summary
private void checkSocketConnection() throws IOException

Verifies if the SocketConnection is valid.

Exceptions
IOException:
If the socket connection object is not valid (is null).
initConnectionback to summary
public void initConnection(int timeout, long synchOnInstant) throws IOException, StandardException, ClassNotFoundException

Used to create a Socket connection to the slave and establish compatibility with the database version of the slave by comparing the UID's of the ReplicationMessage classes of the master and the slave.

Parameters
timeout:int

the amount of time for which the connection should block before being established.

synchOnInstant:long

the master log instant, used to check that the master and slave log files are in synch. If no chunks of log records have been shipped to the slave yet, this is the end position in the current log file. If a chunk of log has been shipped, this is the instant of the log record shipped last. Note that there is a difference!

Exceptions
IOException:
if an exception occurs while trying to create the SocketConnection class or open a connection.
StandardException:
If an error message is received from the server indicating incompatible software versions of master and slave.
ClassNotFoundException:
Class of a serialized object cannot be found.
sendMessageback to summary
public void sendMessage(ReplicationMessage message) throws IOException

Used to send a replication message to the slave.

Parameters
message:ReplicationMessage

a ReplicationMessage object that contains the message to be transmitted.

Exceptions
IOException:
1) if an exception occurs while transmitting the message. 2) if the connection handle is invalid.
sendMessageWaitForReplyback to summary
public synchronized ReplicationMessage sendMessageWaitForReply(ReplicationMessage message) throws IOException, StandardException

Send a replication message to the slave and return the message received as a response. Will only wait DEFAULT_MESSAGE_RESPONSE_TIMEOUT millis for the response message. If not received when the wait times out, no message is returned. The method is synchronized to guarantee that only one thread will be waiting for a response message at any time.

Parameters
message:ReplicationMessage

a ReplicationMessage object that contains the message to be transmitted.

Returns:ReplicationMessage

the response message

Exceptions
IOException:
1) if an exception occurs while sending or receiving a message. 2) if the connection handle is invalid.
StandardException:
if the response message has not been received after DEFAULT_MESSAGE_RESPONSE_TIMEOUT millis
startMessageReceiverThreadback to summary
private void startMessageReceiverThread(String dbname)
tearDownback to summary
public void tearDown() throws IOException

Tear down the network connection established with the other replication peer

Exceptions
IOException:
if an exception occurs while trying to tear down the network connection
verifyMessageTypeback to summary
private boolean verifyMessageType(ReplicationMessage message, int expectedType) throws StandardException

Used to parse a message received from the slave. If the message is an ack of the last shipped message, this method terminates quietly. Otherwise, it throws the exception received in the message from the slave describing why the last message could not be acked.

Exceptions
StandardException:
If an error message is received from the server
ClassNotFoundException:
Class of a serialized object cannot be found.
org.apache.derby.impl.store.replication.net back to summary

private Class ReplicationMessageTransmit.MasterReceiverThread

extends Thread
Class Inheritance

Thread that listens for messages from the slave. A separate thread listening for messages from the slave is needed because the slave may send messages to the master at any time, and these messages require immediate action.

Field Summary

Modifier and TypeField and Description
private final ReplicationMessage
Inherited from java.lang.Thread:
MAX_PRIORITYMIN_PRIORITYNORM_PRIORITY

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
private ReplicationMessage

Returns:

the reply message.
readMessage
()

Used to read a replication message sent by the slave.

public void
run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

This method is run by the thread when it executes.

Inherited from java.lang.Thread:
activeCountcheckAccessclonecurrentThreaddumpStackenumerategetAllStackTracesgetContextClassLoadergetDefaultUncaughtExceptionHandlergetIdgetNamegetPrioritygetStackTracegetStategetThreadGroupgetUncaughtExceptionHandlerholdsLockinterruptinterruptedisAliveisDaemonisInterruptedisVirtualjoinjoinjoinjoinofPlatformofVirtualonSpinWaitsetContextClassLoadersetDaemonsetDefaultUncaughtExceptionHandlersetNamesetPrioritysetUncaughtExceptionHandlersleepsleepsleepstartstartVirtualThreadstopthreadIdtoStringyield

Field Detail

pongMsgback to summary
private final ReplicationMessage pongMsg

Constructor Detail

MasterReceiverThreadback to summary
pack-priv MasterReceiverThread(String dbname)

Method Detail

readMessageback to summary
private ReplicationMessage readMessage() throws ClassNotFoundException, IOException

Used to read a replication message sent by the slave. Hangs until a message is received from the slave

Returns:ReplicationMessage

the reply message.

Exceptions
ClassNotFoundException:
Class of a serialized object cannot be found.
IOException:
1) if an exception occurs while reading from the stream. 2) if the connection handle is invalid.
runback to summary
public void run()

Overrides java.lang.Thread.run.

Implements java.lang.Runnable.run.

Doc from java.lang.Thread.run.

This method is run by the thread when it executes. Subclasses of Thread may override this method.

This method is not intended to be invoked directly. If this thread is a platform thread created with a Runnable task then invoking this method will invoke the task's run method. If this thread is a virtual thread then invoking this method directly does nothing.