org.apache.derby.impl.store.replication.net
Class ReplicationMessageReceive
- java.lang.Object
-
- org.apache.derby.impl.store.replication.net.ReplicationMessageReceive
-
public class ReplicationMessageReceive extends java.lang.ObjectThis class is the Receiver (viz. Socket server or listener) part of the network communication. It receives the message from the master and performs appropriate action depending on the type of the message.
-
-
Constructor Summary
Constructors Constructor and Description ReplicationMessageReceive(SlaveAddress slaveAddress, java.lang.String dbname)Constructor initializes the slave address used in replication.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidinitConnection(int timeout, long synchOnInstant, java.lang.String dbname)Used to create the server socket, listen on the socket for connections from the master and verify compatibility with the database version of the master.booleanisConnectedToMaster()Check if the repliation network is working.ReplicationMessagereadMessage()Used to read a replication message sent by the master.voidsendMessage(ReplicationMessage message)Used to send a replication message to the master.voidtearDown()Used to close theServerSocketand the resources associated with it.
-
-
-
Constructor Detail
-
ReplicationMessageReceive
public ReplicationMessageReceive(SlaveAddress slaveAddress, java.lang.String dbname)
Constructor initializes the slave address used in replication. Accepts the host name and port number that constitute the slave address as parameters.- Parameters:
slaveAddress- the address (host name and port number) of the slave to connect to.dbname- the name of the database.
-
-
Method Detail
-
initConnection
public void initConnection(int timeout, long synchOnInstant, java.lang.String dbname) throws java.io.IOException, StandardException, java.lang.ClassNotFoundExceptionUsed to create the server socket, listen on the socket for connections from the master and verify compatibility with the database version of the master.- Parameters:
timeout- The amount of time, in milliseconds, this method will wait for a connection to be established. If no connection has been established before the timeout, a IOException is raised with cause java.net.SocketTimeoutExceptionsynchOnInstant- the slave log instant, used to check that the master and slave log files are in synch. If no chunks of log records have been received from the master yet, this is the end position in the current log file. If a chunk of log has been received, this is the instant of the log record received last. Note that there is a difference!dbname- the name of the replicated database- Throws:
java.io.IOException- if an exception occurs while trying to create theSocketConnectionclass or while trying to open a connection.java.lang.ClassNotFoundException- Class of a serialized object cannot be found.StandardException- if an incompatible database version is found.
-
tearDown
public void tearDown() throws java.io.IOExceptionUsed to close theServerSocketand the resources associated with it.- Throws:
java.io.IOException- If an exception occurs while trying to close the socket or the associated resources.
-
sendMessage
public void sendMessage(ReplicationMessage message) throws java.io.IOException
Used to send a replication message to the master.- Parameters:
message- aReplicationMessageobject that contains the message to be transmitted.- Throws:
java.io.IOException- 1) if an exception occurs while transmitting the message, 2) if the connection handle is invalid.
-
readMessage
public ReplicationMessage readMessage() throws java.lang.ClassNotFoundException, java.io.IOException
Used to read a replication message sent by the master. This method would wait on the connection from the master until a message is received or a connection failure occurs. Replication network layer specific messages (i.e. ping/pong messages) are handled internally and are not returned.- Returns:
- a
ReplicationMessageobject that contains the reply that is sent. - Throws:
java.lang.ClassNotFoundException- Class of a serialized object cannot be found.java.io.IOException- 1) if an exception occurs while reading from the stream, 2) if the connection handle is invalid.
-
isConnectedToMaster
public boolean isConnectedToMaster()
Check if the repliation network is working. Tries to send a ping message to the master and returns the network status based on the success or failure of sending this message and receiving a pong reply. MT: Currently, only one thread is allowed to check the network status at any time to keep the code complexity down.- Returns:
- true if the pong message was received before timing out after DEFAULT_PING_TIMEOUT millis, false otherwise
- See Also:
DEFAULT_PING_TIMEOUT
-
-
DataMelt 3.0 © DataMelt by jWork.ORG