org.opends.server.replication.plugin
Class ReplicationBroker

java.lang.Object
  extended by org.opends.server.replication.plugin.ReplicationBroker
All Implemented Interfaces:
InternalSearchListener

public class ReplicationBroker
extends java.lang.Object
implements InternalSearchListener

The broker for Multi-master Replication.


Constructor Summary
ReplicationBroker(ServerState state, DN baseDn, short serverID, int maxReceiveQueue, int maxReceiveDelay, int maxSendQueue, int maxSendDelay, int window, long heartbeatInterval, long generationId, ReplSessionSecurity replSessionSecurity)
          Creates a new ReplicationServer Broker for a particular ReplicationDomain.
 
Method Summary
 void changeConfig(java.util.Collection<java.lang.String> replicationServers, int maxReceiveQueue, int maxReceiveDelay, int maxSendQueue, int maxSendDelay, int window, long heartbeatInterval)
          Change some config parameters.
static java.lang.String computeBestReplicationServer(ServerState myState, java.util.HashMap<java.lang.String,ServerState> rsStates, short serverId, DN baseDn)
          Returns the replication server that best fits our need so that we can connect to it.
 int getCurrentRcvWindow()
          Get the current receive window size.
 int getCurrentSendWindow()
          Get the current send window size.
 int getMaxRcvWindow()
          Get the maximum receive window size.
 int getMaxSendWindow()
          Get the maximum send window size.
 int getNumLostConnections()
          Get the number of times the connection was lost.
 short getProtocolVersion()
          Get the version of the replication protocol.
 java.lang.String getReplicationServer()
          Get the name of the replicationServer to which this broker is currently connected.
 void handleInternalSearchEntry(InternalSearchOperation searchOperation, SearchResultEntry searchEntry)
          Performs any processing necessary for the provided search result entry.
 void handleInternalSearchReference(InternalSearchOperation searchOperation, SearchResultReference searchReference)
          Performs any processing necessary for the provided search result reference.
 boolean isConnected()
          Check if the broker is connected to a ReplicationServer and therefore ready to received and send Replication Messages.
 boolean isSessionEncrypted()
          Determine whether the connection to the replication server is encrypted.
 ReplServerStartMessage performHandshake(java.lang.String server, boolean keepConnection)
          Connect to the provided server performing the handshake (start messages exchange) and return the reply message from the replication server.
 void publish(ReplicationMessage msg)
          Publish a message to the other servers.
 ReplicationMessage receive()
          Receive a message.
 void reStart()
          restart the ReplicationBroker.
 void reStart(ProtocolSession failingSession)
          Restart the ReplicationServer broker after a failure.
static InternalSearchOperation searchForChangedEntries(DN baseDn, ChangeNumber fromChangeNumber, InternalSearchListener resultListener)
          Search for the changes that happened since fromChangeNumber based on the historical attribute.
 void setGenerationId(long generationId)
          Set the value of the generationId for that broker.
 void setSoTimeout(int timeout)
          Set a timeout value.
 void start(java.util.Collection<java.lang.String> servers)
          Start the ReplicationBroker.
 void stop()
          stop the server.
 void updateWindowAfterReplay()
          This method allows to do the necessary computing for the window management after treatment by the worker threads.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReplicationBroker

public ReplicationBroker(ServerState state,
                         DN baseDn,
                         short serverID,
                         int maxReceiveQueue,
                         int maxReceiveDelay,
                         int maxSendQueue,
                         int maxSendDelay,
                         int window,
                         long heartbeatInterval,
                         long generationId,
                         ReplSessionSecurity replSessionSecurity)
Creates a new ReplicationServer Broker for a particular ReplicationDomain.

Parameters:
state - The ServerState that should be used by this broker when negociating the session with the replicationServer.
baseDn - The base DN that should be used by this broker when negociating the session with the replicationServer.
serverID - The server ID that should be used by this broker when negociating the session with the replicationServer.
maxReceiveQueue - The maximum size of the receive queue to use on the replicationServer.
maxReceiveDelay - The maximum replication delay to use on the replicationServer.
maxSendQueue - The maximum size of the send queue to use on the replicationServer.
maxSendDelay - The maximum send delay to use on the replicationServer.
window - The size of the send and receive window to use.
heartbeatInterval - The interval between heartbeats requested of the replicationServer, or zero if no heartbeats are requested.
generationId - The generationId for the server associated to the provided serverID and for the domain associated to the provided baseDN.
replSessionSecurity - The session security configuration.
Method Detail

start

public void start(java.util.Collection<java.lang.String> servers)
Start the ReplicationBroker.

Parameters:
servers - list of servers used

performHandshake

public ReplServerStartMessage performHandshake(java.lang.String server,
                                               boolean keepConnection)
Connect to the provided server performing the handshake (start messages exchange) and return the reply message from the replication server.

Parameters:
server - Server to connect to.
keepConnection - Do we keep session opened or not after handshake.
Returns:
The ReplServerStartMessage the server replied. Null if could not get an answer.

computeBestReplicationServer

public static java.lang.String computeBestReplicationServer(ServerState myState,
                                                            java.util.HashMap<java.lang.String,ServerState> rsStates,
                                                            short serverId,
                                                            DN baseDn)
Returns the replication server that best fits our need so that we can connect to it. Note: this method put as public static for unit testing purpose.

Parameters:
myState - The local server state.
rsStates - The list of available replication servers and their associated server state.
serverId - The server id for the suffix we are working for.
baseDn - The suffix for which we are working for.
Returns:
The computed best replication server.

searchForChangedEntries

public static InternalSearchOperation searchForChangedEntries(DN baseDn,
                                                              ChangeNumber fromChangeNumber,
                                                              InternalSearchListener resultListener)
                                                       throws java.lang.Exception
Search for the changes that happened since fromChangeNumber based on the historical attribute.

Parameters:
baseDn - the base DN
fromChangeNumber - The change number from which we want the changes
resultListener - that will process the entries returned.
Returns:
the internal search operation
Throws:
java.lang.Exception - when raised.

reStart

public void reStart()
restart the ReplicationBroker.


reStart

public void reStart(ProtocolSession failingSession)
Restart the ReplicationServer broker after a failure.

Parameters:
failingSession - the socket which failed

publish

public void publish(ReplicationMessage msg)
Publish a message to the other servers.

Parameters:
msg - the message to publish

receive

public ReplicationMessage receive()
                           throws java.net.SocketTimeoutException
Receive a message. This method is not multithread safe and should either always be called in a single thread or protected by a locking mechanism before being called.

Returns:
the received message
Throws:
java.net.SocketTimeoutException - if the timeout set by setSoTimeout has expired

updateWindowAfterReplay

public void updateWindowAfterReplay()
This method allows to do the necessary computing for the window management after treatment by the worker threads. This should be called once the replay thread have done their job and the window can be open again.


stop

public void stop()
stop the server.


setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Set a timeout value. With this option set to a non-zero value, calls to the receive() method block for only this amount of time after which a java.net.SocketTimeoutException is raised. The Broker is valid and useable even after such an Exception is raised.

Parameters:
timeout - the specified timeout, in milliseconds.
Throws:
java.net.SocketException - if there is an error in the underlying protocol, such as a TCP error.

setGenerationId

public void setGenerationId(long generationId)
Set the value of the generationId for that broker. Normally the generationId is set through the constructor but there are cases where the value of the generationId must be changed while the broker already exist for example after an on-line import.

Parameters:
generationId - The value of the generationId.

getReplicationServer

public java.lang.String getReplicationServer()
Get the name of the replicationServer to which this broker is currently connected.

Returns:
the name of the replicationServer to which this domain is currently connected.

handleInternalSearchEntry

public void handleInternalSearchEntry(InternalSearchOperation searchOperation,
                                      SearchResultEntry searchEntry)
Performs any processing necessary for the provided search result entry.

Specified by:
handleInternalSearchEntry in interface InternalSearchListener
Parameters:
searchOperation - The internal search operation being processed.
searchEntry - The matching search result entry to be processed.

handleInternalSearchReference

public void handleInternalSearchReference(InternalSearchOperation searchOperation,
                                          SearchResultReference searchReference)
Performs any processing necessary for the provided search result reference.

Specified by:
handleInternalSearchReference in interface InternalSearchListener
Parameters:
searchOperation - The internal search operation being processed.
searchReference - The search result reference to be processed.

getMaxRcvWindow

public int getMaxRcvWindow()
Get the maximum receive window size.

Returns:
The maximum receive window size.

getCurrentRcvWindow

public int getCurrentRcvWindow()
Get the current receive window size.

Returns:
The current receive window size.

getMaxSendWindow

public int getMaxSendWindow()
Get the maximum send window size.

Returns:
The maximum send window size.

getCurrentSendWindow

public int getCurrentSendWindow()
Get the current send window size.

Returns:
The current send window size.

getNumLostConnections

public int getNumLostConnections()
Get the number of times the connection was lost.

Returns:
The number of times the connection was lost.

changeConfig

public void changeConfig(java.util.Collection<java.lang.String> replicationServers,
                         int maxReceiveQueue,
                         int maxReceiveDelay,
                         int maxSendQueue,
                         int maxSendDelay,
                         int window,
                         long heartbeatInterval)
Change some config parameters.

Parameters:
replicationServers - The new list of replication servers.
maxReceiveQueue - The max size of receive queue.
maxReceiveDelay - The max receive delay.
maxSendQueue - The max send queue.
maxSendDelay - The max Send Delay.
window - The max window size.
heartbeatInterval - The heartbeat interval.

getProtocolVersion

public short getProtocolVersion()
Get the version of the replication protocol.

Returns:
The version of the replication protocol.

isConnected

public boolean isConnected()
Check if the broker is connected to a ReplicationServer and therefore ready to received and send Replication Messages.

Returns:
true if the server is connected, false if not.

isSessionEncrypted

public boolean isSessionEncrypted()
Determine whether the connection to the replication server is encrypted.

Returns:
true if the connection is encrypted, false otherwise.