|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.apache.derby.impl.store.replication.net.ReplicationMessageReceive
public class ReplicationMessageReceive
This 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.
Nested Class Summary | |
---|---|
private class |
ReplicationMessageReceive.SlavePingThread
Thread that sends ping messages to the master on request to check if the replication network is working |
Field Summary | |
---|---|
private boolean |
connectionConfirmed
Whether or not the connection with the master is confirmed to be working. |
private static int |
DEFAULT_PING_TIMEOUT
The maximum number of millis to wait before giving up waiting for a ping response |
private boolean |
killPingThread
Used to terminate the ping thread. |
private java.lang.Thread |
pingThread
Thread used to send ping messages to master to check if the connection is working. |
private java.lang.Object |
receivePongSemaphore
Used for synchronization when waiting for a ping reply message |
private java.lang.Object |
sendPingSemaphore
Used for synchronization of the ping thread |
private java.net.ServerSocket |
serverSocket
Contains the ServerSocket used to listen for
connections from the replication master. |
private SlaveAddress |
slaveAddress
Contains the address (hostname and port number) of the slave to replicate to. |
private SocketConnection |
socketConn
Contains the methods used to read and write to the Object streams obtained from a Socket connection. |
Constructor Summary | |
---|---|
ReplicationMessageReceive(SlaveAddress slaveAddress,
java.lang.String dbname)
Constructor initializes the slave address used in replication. |
Method Summary | |
---|---|
private void |
checkSocketConnection()
Verifies if the SocketConnection is valid. |
private java.net.ServerSocket |
createServerSocket()
Used to create a ServerSocket for listening to connections
from the master. |
private void |
handleUnexpectedMessage(java.lang.String dbname,
java.lang.String expextedMsgId,
java.lang.String receivedMsgId)
Notify other replication peer that the message type was unexpected and throw a StandardException |
void |
initConnection(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. |
boolean |
isConnectedToMaster()
Check if the repliation network is working. |
private void |
parseAndAckInstant(ReplicationMessage initiatorMessage,
long synchOnInstant,
java.lang.String dbname)
Used to parse the log instant initiator message from the master and check that the master and slave log files are in synch. |
private void |
parseAndAckVersion(ReplicationMessage initiatorMessage,
java.lang.String dbname)
Used to parse the initiator message from the master and check if the slave is compatible with the master by comparing the UID of the ReplicationMessage class of the master, that is wrapped
in the initiator message, with the UID of the same class in the slave. |
ReplicationMessage |
readMessage()
Used to read a replication message sent by the master. |
void |
sendMessage(ReplicationMessage message)
Used to send a replication message to the master. |
void |
tearDown()
Used to close the ServerSocket and the resources
associated with it. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private final SlaveAddress slaveAddress
private java.net.ServerSocket serverSocket
ServerSocket
used to listen for
connections from the replication master.
private SocketConnection socketConn
Socket
connection.
private static final int DEFAULT_PING_TIMEOUT
private java.lang.Thread pingThread
private boolean killPingThread
private boolean connectionConfirmed
private final java.lang.Object sendPingSemaphore
private final java.lang.Object receivePongSemaphore
Constructor Detail |
---|
public ReplicationMessageReceive(SlaveAddress slaveAddress, java.lang.String dbname)
slaveAddress
- the address (host name and port number) of the slave
to connect to.dbname
- the name of the database.Method Detail |
---|
public void initConnection(int timeout, long synchOnInstant, java.lang.String dbname) throws java.security.PrivilegedActionException, java.io.IOException, StandardException, java.lang.ClassNotFoundException
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
PrivilegedExceptionAction 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
java.security.PrivilegedActionException
- if an exception occurs while trying
to open a connection.
java.io.IOException
- if an exception occurs while trying to create the
SocketConnection
class.
java.lang.ClassNotFoundException
- Class of a serialized object cannot
be found.
StandardException
- if an incompatible database version is found.private java.net.ServerSocket createServerSocket() throws java.security.PrivilegedActionException
ServerSocket
for listening to connections
from the master.
ServerSocket
class.
java.security.PrivilegedActionException
- if an exception occurs while trying
to open a connection.public void tearDown() throws java.io.IOException
ServerSocket
and the resources
associated with it.
java.io.IOException
- If an exception occurs while trying to
close the socket or the associated resources.private void parseAndAckVersion(ReplicationMessage initiatorMessage, java.lang.String dbname) throws java.io.IOException, StandardException
ReplicationMessage
class of the master, that is wrapped
in the initiator message, with the UID of the same class in the slave.
initiatorMessage
- the object containing the UID.dbname
- the name of the replicated database
java.io.IOException
- If an exception occurs while sending the
acknowledgment.
StandardException
- If the UID's do not match.private void parseAndAckInstant(ReplicationMessage initiatorMessage, long synchOnInstant, java.lang.String dbname) throws java.io.IOException, StandardException
initiatorMessage
- the object containing the UID.synchOnInstant
- 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
java.io.IOException
- If an exception occurs while sending the
acknowledgment.
StandardException
- If the log files are not in synchprivate void handleUnexpectedMessage(java.lang.String dbname, java.lang.String expextedMsgId, java.lang.String receivedMsgId) throws StandardException, java.io.IOException
dbname
- the name of the replicated databaseexpextedMsgId
- the expected message typereceivedMsgId
- the received message type
StandardException
- exception describing that an unexpected
message was received is always thrown
java.io.IOException
- thrown if an exception occurs while sending
the error messagepublic void sendMessage(ReplicationMessage message) throws java.io.IOException
message
- a ReplicationMessage
object that contains
the message to be transmitted.
java.io.IOException
- 1) if an exception occurs while transmitting
the message,
2) if the connection handle is invalid.public ReplicationMessage readMessage() throws java.lang.ClassNotFoundException, java.io.IOException
ReplicationMessage
object that contains
the reply that is sent.
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.private void checkSocketConnection() throws java.io.IOException
SocketConnection
is valid.
java.io.IOException
- If the socket connection object is not
valid (is null).public boolean isConnectedToMaster()
DEFAULT_PING_TIMEOUT
|
Built on Thu 2011-03-10 11:54:14+0000, from revision ??? | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |