org.opends.server.replication.server
Class ReplicationServerDomain

java.lang.Object
  extended by org.opends.server.replication.server.ReplicationServerDomain

public class ReplicationServerDomain
extends java.lang.Object

This class define an in-memory cache that will be used to store the messages that have been received from an LDAP server or from another replication server and that should be forwarded to other servers. The size of the cache is set by configuration. If the cache becomes bigger than the configured size, the older messages are removed and should they be needed again must be read from the backing file it runs a thread that is responsible for saving the messages received to the disk and for trimming them Decision to trim can be based on disk space or age of the message


Constructor Summary
ReplicationServerDomain(DN baseDn, ReplicationServer replicationServer)
          Creates a new ReplicationServerDomain associated to the DN baseDn.
 
Method Summary
 void ack(AckMessage message, short fromServerId)
          Add an ack to the list of ack received for a given change.
 void checkAllSaturation()
          Check if some server Handler should be removed from flow control state.
 void clearDbs()
          Clears the Db associated with that cache.
 DN getBaseDn()
          Get the baseDn.
 ReplicationIterator getChangelogIterator(short serverId, ChangeNumber changeNumber)
          Creates and returns an iterator.
 java.util.Set<java.lang.String> getChangelogs()
          Return a Set of String containing the lists of Replication servers connected to this server.
 long getChangesCount()
          Returns the change count for that ReplicationServerDomain.
 java.util.List<java.lang.String> getConnectedLDAPservers()
          Returns as a set of String the list of LDAP servers connected to us.
 ServerState getDbServerState()
          Returns the ServerState describing the last change from this replica.
protected  java.util.List<ServerHandler> getDestinationServers(RoutableMessage msg, ServerHandler senderHandler)
          Retrieves the destination handlers for a routable message.
 long getGenerationId()
          Get the generationId associated to this domain.
 boolean getGenerationIdSavedStatus()
          Get the generationId saved status.
protected  MonitorData getMonitorData()
          Retrieves the global monitor data.
 ReplicationServer getReplicationServer()
          Return the associated replication server.
 java.util.Set<java.lang.Short> getServers()
          Return a Set containing the servers known by this replicationServer.
 boolean isDegradedDueToGenerationId(short serverId)
          Returns whether the provided server is in degraded state due to the fact that the peer server has an invalid generationId for this domain.
protected  void mayResetGenerationId()
          Resets the generationId for this domain if there is no LDAP server currently connected and if the generationId has never been saved.
 void process(RoutableMessage msg, ServerHandler senderHandler)
          Processes a message coming from one server in the topology and potentially forwards it to one or all other servers.
 void put(UpdateMessage update, ServerHandler sourceHandler)
          Add an update that has been received to the list of updates that must be forwarded to all other servers.
 void receiveReplServerInfo(ReplServerInfoMessage infoMsg, ServerHandler handler)
          Process reception of a ReplServerInfoMessage.
 void receivesMonitorDataResponse(MonitorMessage msg)
          Processes a Monitor message receives from a remote Replication Server and stores the data received.
 void resetGenerationId(ServerHandler senderHandler, ResetGenerationId genIdMsg)
          Resets the generationID.
 boolean restartAfterSaturation(ServerHandler sourceHandler)
          Check if a server that was in flow control can now restart sending updates.
 void sendAck(ChangeNumber changeNumber, boolean isLDAPserver)
          Send back an ack to the server that sent the change.
 void sendAck(ChangeNumber changeNumber, boolean isLDAPserver, short serverId)
          Send back an ack to a server that sent the change.
protected  short sendMonitorDataRequest()
          Sends a MonitorRequest message to all connected RS.
 void setDbHandler(short serverId, DbHandler dbHandler)
          Sets the provided DbHandler associated to the provided serverId.
 void setGenerationId(long generationId, boolean savedStatus)
          Sets the provided value as the new in memory generationId.
 void shutdown()
          Shutdown this ReplicationServerDomain.
 boolean startReplicationServer(ServerHandler handler)
          Create initialize context necessary for finding the changes that must be sent to a given replication server.
 boolean startServer(ServerHandler handler)
          Create initialize context necessary for finding the changes that must be sent to a given LDAP or replication server.
 void stopServer(ServerHandler handler)
          Stop operations with a given server.
 UpdateMessage take(ServerHandler handler)
          Get the next update that need to be sent to a given LDAP server.
 java.lang.String toString()
          
 void waitDisconnection(short serverId)
          Wait a short while for ServerId disconnection.
protected  void waitMonitorDataResponses(int expectedResponses)
          Wait for the expected count of received MonitorMessage.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ReplicationServerDomain

public ReplicationServerDomain(DN baseDn,
                               ReplicationServer replicationServer)
Creates a new ReplicationServerDomain associated to the DN baseDn.

Parameters:
baseDn - The baseDn associated to the ReplicationServerDomain.
replicationServer - the ReplicationServer that created this replicationServer cache.
Method Detail

put

public void put(UpdateMessage update,
                ServerHandler sourceHandler)
         throws java.io.IOException
Add an update that has been received to the list of updates that must be forwarded to all other servers.

Parameters:
update - The update that has been received.
sourceHandler - The ServerHandler for the server from which the update was received
Throws:
java.io.IOException - When an IO exception happens during the update processing.

waitDisconnection

public void waitDisconnection(short serverId)
Wait a short while for ServerId disconnection.

Parameters:
serverId - the serverId to be checked.

startServer

public boolean startServer(ServerHandler handler)
                    throws java.lang.Exception
Create initialize context necessary for finding the changes that must be sent to a given LDAP or replication server.

Parameters:
handler - handler for the server that must be started
Returns:
A boolean indicating if the start was successfull.
Throws:
java.lang.Exception - when method has failed

stopServer

public void stopServer(ServerHandler handler)
Stop operations with a given server.

Parameters:
handler - the server for which we want to stop operations

mayResetGenerationId

protected void mayResetGenerationId()
Resets the generationId for this domain if there is no LDAP server currently connected and if the generationId has never been saved.


startReplicationServer

public boolean startReplicationServer(ServerHandler handler)
                               throws java.lang.Exception
Create initialize context necessary for finding the changes that must be sent to a given replication server.

Parameters:
handler - the server ID to which we want to forward changes
Returns:
A boolean indicating if the start was successfull.
Throws:
java.lang.Exception - in case of errors

take

public UpdateMessage take(ServerHandler handler)
Get the next update that need to be sent to a given LDAP server. This call is blocking when no update is available or when dependencies do not allow to send the next available change

Parameters:
handler - The server handler for the target directory server.
Returns:
the update that must be forwarded

getChangelogs

public java.util.Set<java.lang.String> getChangelogs()
Return a Set of String containing the lists of Replication servers connected to this server.

Returns:
the set of connected servers

getServers

public java.util.Set<java.lang.Short> getServers()
Return a Set containing the servers known by this replicationServer.

Returns:
a set containing the servers known by this replicationServer.

getConnectedLDAPservers

public java.util.List<java.lang.String> getConnectedLDAPservers()
Returns as a set of String the list of LDAP servers connected to us. Each string is the serverID of a connected LDAP server.

Returns:
The set of connected LDAP servers

getChangelogIterator

public ReplicationIterator getChangelogIterator(short serverId,
                                                ChangeNumber changeNumber)
Creates and returns an iterator. When the iterator is not used anymore, the caller MUST call the ReplicationIterator.releaseCursor() method to free the ressources and locks used by the ReplicationIterator.

Parameters:
serverId - Identifier of the server for which the iterator is created.
changeNumber - Starting point for the iterator.
Returns:
the created ReplicationIterator. Null when no DB is available for the provided server Id.

getChangesCount

public long getChangesCount()
Returns the change count for that ReplicationServerDomain.

Returns:
the change count.

getBaseDn

public DN getBaseDn()
Get the baseDn.

Returns:
Returns the baseDn.

setDbHandler

public void setDbHandler(short serverId,
                         DbHandler dbHandler)
                  throws com.sleepycat.je.DatabaseException
Sets the provided DbHandler associated to the provided serverId.

Parameters:
serverId - the serverId for the server to which is associated the Dbhandler.
dbHandler - the dbHandler associated to the serverId.
Throws:
com.sleepycat.je.DatabaseException - If a database error happened.

ack

public void ack(AckMessage message,
                short fromServerId)
Add an ack to the list of ack received for a given change.

Parameters:
message - The ack message received.
fromServerId - The identifier of the server that sent the ack.

getDestinationServers

protected java.util.List<ServerHandler> getDestinationServers(RoutableMessage msg,
                                                              ServerHandler senderHandler)
Retrieves the destination handlers for a routable message.

Parameters:
msg - The message to route.
senderHandler - The handler of the server that published this message.
Returns:
The list of destination handlers.

process

public void process(RoutableMessage msg,
                    ServerHandler senderHandler)
Processes a message coming from one server in the topology and potentially forwards it to one or all other servers.

Parameters:
msg - The message received and to be processed.
senderHandler - The server handler of the server that emitted the message.

sendAck

public void sendAck(ChangeNumber changeNumber,
                    boolean isLDAPserver)
Send back an ack to the server that sent the change.

Parameters:
changeNumber - The ChangeNumber of the change that must be acked.
isLDAPserver - This boolean indicates if the server that sent the change was an LDAP server or a ReplicationServer.

sendAck

public void sendAck(ChangeNumber changeNumber,
                    boolean isLDAPserver,
                    short serverId)
Send back an ack to a server that sent the change.

Parameters:
changeNumber - The ChangeNumber of the change that must be acked.
isLDAPserver - This boolean indicates if the server that sent the change was an LDAP server or a ReplicationServer.
serverId - The identifier of the server from which we received the change..

shutdown

public void shutdown()
Shutdown this ReplicationServerDomain.


getDbServerState

public ServerState getDbServerState()
Returns the ServerState describing the last change from this replica.

Returns:
The ServerState describing the last change from this replica.

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

checkAllSaturation

public void checkAllSaturation()
                        throws java.io.IOException
Check if some server Handler should be removed from flow control state.

Throws:
java.io.IOException - If an error happened.

restartAfterSaturation

public boolean restartAfterSaturation(ServerHandler sourceHandler)
Check if a server that was in flow control can now restart sending updates.

Parameters:
sourceHandler - The server that must be checked.
Returns:
true if the server can restart sending changes. false if the server can't restart sending changes.

getGenerationId

public long getGenerationId()
Get the generationId associated to this domain.

Returns:
The generationId

getGenerationIdSavedStatus

public boolean getGenerationIdSavedStatus()
Get the generationId saved status.

Returns:
The generationId saved status.

setGenerationId

public void setGenerationId(long generationId,
                            boolean savedStatus)
Sets the provided value as the new in memory generationId.

Parameters:
generationId - The new value of generationId.
savedStatus - The saved status of the generationId.

resetGenerationId

public void resetGenerationId(ServerHandler senderHandler,
                              ResetGenerationId genIdMsg)
Resets the generationID.

Parameters:
senderHandler - The handler associated to the server that requested to reset the generationId.
genIdMsg - The reset generation ID msg received.

clearDbs

public void clearDbs()
Clears the Db associated with that cache.


isDegradedDueToGenerationId

public boolean isDegradedDueToGenerationId(short serverId)
Returns whether the provided server is in degraded state due to the fact that the peer server has an invalid generationId for this domain.

Parameters:
serverId - The serverId for which we want to know the the state.
Returns:
Whether it is degraded or not.

getReplicationServer

public ReplicationServer getReplicationServer()
Return the associated replication server.

Returns:
The replication server.

receiveReplServerInfo

public void receiveReplServerInfo(ReplServerInfoMessage infoMsg,
                                  ServerHandler handler)
                           throws java.io.IOException
Process reception of a ReplServerInfoMessage.

Parameters:
infoMsg - The received message.
handler - The handler that received the message.
Throws:
java.io.IOException - when raised by the underlying session.

getMonitorData

protected MonitorData getMonitorData()
                              throws DirectoryException
Retrieves the global monitor data.

Returns:
The monitor data.
Throws:
DirectoryException - When an error occurs.

sendMonitorDataRequest

protected short sendMonitorDataRequest()
                                throws DirectoryException
Sends a MonitorRequest message to all connected RS.

Returns:
the number of requests sent.
Throws:
DirectoryException - when a problem occurs.

waitMonitorDataResponses

protected void waitMonitorDataResponses(int expectedResponses)
                                 throws DirectoryException
Wait for the expected count of received MonitorMessage.

Parameters:
expectedResponses - The number of expected answers.
Throws:
DirectoryException - When an error occurs.

receivesMonitorDataResponse

public void receivesMonitorDataResponse(MonitorMessage msg)
Processes a Monitor message receives from a remote Replication Server and stores the data received.

Parameters:
msg - The message to be processed.