org.opends.server.replication.server
Class ServerHandler

java.lang.Object
  extended by java.lang.Thread
      extended by org.opends.server.api.DirectoryThread
          extended by org.opends.server.api.MonitorProvider<MonitorProviderCfg>
              extended by org.opends.server.replication.server.ServerHandler
All Implemented Interfaces:
java.lang.Runnable

public class ServerHandler
extends MonitorProvider<MonitorProviderCfg>

This class defines a server handler, which handles all interaction with a replication server.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
ServerHandler(ProtocolSession session, int queueSize)
          Creates a new server handler instance with the provided socket.
 
Method Summary
 void ack(AckMessage message, short ackingServerId)
          Do the work when an ack message has been received from another server.
static void ackChangelog(AckMessage message, short ackingServerId)
          Process reception of an for an update that was received from a ReplicationServer.
 void add(UpdateMessage update, ServerHandler sourceHandler)
          Add an update the list of updates that must be sent to the server managed by this ServerHandler.
 void addWaitingAck(UpdateMessage update, int nbWaitedAck)
          Add an update to the list of update waiting for acks.
static void addWaitingAck(UpdateMessage update, short ChangelogServerId, ReplicationServerDomain replicationServerDomain, int nbWaitedAck)
          Add an update to the list of update received from a replicationServer and waiting for acks.
 void checkWindow()
          Check the protocol window and send WindowMessage if necessary.
 void decAndCheckWindow()
          Decrement the protocol window, then check if it is necessary to send a WindowMessage and send it.
 void forwardGenerationIdToRS(ResetGenerationId msg)
          Sends a message containing a generationId to a peer server.
 long getApproxDelay()
          Get an approximation of the delay by looking at the age of the oldest message that has not been sent to this server.
 java.lang.Long getApproxFirstMissingDate()
          Get the age of the older change that has not yet been replicated to the server handled by this ServerHandler.
 java.util.Set<java.lang.Short> getConnectedServerIds()
          Return a Set containing the servers known by this replicationServer.
 ReplicationServerDomain getDomain()
          Returns the Replication Server Domain to which belongs this server handler.
 long getGenerationId()
          Returns the value of generationId for that handler.
 long getHeartbeatInterval()
          Get our heartbeat interval.
 int getInAckCount()
          Get the number of Ack received from the server managed by this handler.
 int getInCount()
          Get the count of updates received from the server.
 java.util.ArrayList<Attribute> getMonitorData()
          Retrieves a set of attributes containing monitor data that should be returned to the client if the corresponding monitor entry is requested.
 java.lang.String getMonitorInstanceName()
          Retrieves the name of this monitor provider.
 ChangeNumber getOlderUpdateCN()
          Get the older Change Number for that server.
 long getOlderUpdateTime()
          Get the older update time for that server.
 int getOutAckCount()
          Get the number of Ack sent to the server managed by this handler.
 int getOutCount()
          Get the count of updates sent to this server.
 int getRcvMsgQueueSize()
          Get the number of message in the receive message queue.
 java.lang.String getServerAddressURL()
          Retrieves the Address URL for this server handler.
 short getServerId()
          get the Server Id.
 ServerState getServerState()
          Get the state of this server.
 java.lang.String getServerURL()
          Retrieves the URL for this server handler.
 long getUpdateInterval()
          Retrieves the length of time in milliseconds that should elapse between calls to the updateMonitorData() method.
 int getWaitingAckSize()
          Get the size of the list of update waiting for acks.
 boolean hasRemoteLDAPServers()
          When the handler is connected to a replication server, specifies the replication server has remote LDAP servers connected to it.
 void incrementInAckCount()
          Increment the count of Acks received from this server.
 void incrementInCount()
          Increase the counter of update received from the server.
 void incrementOutCount()
          Increase the counter of updates sent to the server.
 void initializeMonitorProvider(MonitorProviderCfg configuration)
          Initializes this monitor provider based on the information in the provided configuration entry.
 boolean isFollowing()
          Check if the LDAP server can follow the speed of the other servers.
 boolean isLDAPserver()
          Check type of server handled.
 boolean isRemoteLDAPServer(short wantedServer)
          When this handler is connected to a replication server, specifies if a wanted server is connected to this replication server.
 boolean isReplicationServer()
          Check if the server associated to this ServerHandler is a replication server.
 boolean isSaturated(ChangeNumber changeNumber, ServerHandler sourceHandler)
          Check is this server is saturated (this server has already been sent a bunch of updates and has not processed them so they are staying in the message queue for this server an the size of the queue for this server is above the configured limit.
 void process(RoutableMessage msg)
          Processes a routable message.
 void process(WindowProbe windowProbeMsg)
          Process the reception of a WindowProbe message.
 void receiveReplServerInfo(ReplServerInfoMessage infoMsg)
          Sets the replication server from the message provided.
 boolean restartAfterSaturation(ServerHandler source)
          Check that the size of the Server Handler messages Queue has lowered below the limit and therefore allowing the reception of messages from other servers to restart.
 void send(RoutableMessage msg)
          Send an InitializeRequestMessage to the server connected through this handler.
 void sendAck(ChangeNumber changeNumber)
          Send the ack to the server that did the original modification.
 void sendError(ErrorMessage errorMsg)
          Send an ErrorMessage to the peer.
 void sendInfo(ReplServerInfoMessage info)
          Sends the provided ReplServerInfoMessage.
 void setFollowing(boolean following)
          Set the following flag of this server.
 void setGenerationId(long generationId)
          Set a new generation ID.
 void shutdown()
          Shutdown This ServerHandler.
 void start(DN baseDn, short replicationServerId, java.lang.String replicationServerURL, int windowSize, boolean sslEncryption, ReplicationServer replicationServer)
          Do the exchange of start messages to know if the remote server is an LDAP or replication server and to exchange serverID.
 void stopHandler()
          Stop this server handler processing.
 UpdateMessage take()
          Select the next update that must be sent to the server managed by this ServerHandler.
 java.lang.String toString()
          
 void updateMonitorData()
          Performs any processing periodic processing that may be desired to update the information associated with this monitor.
 boolean updateServerState(UpdateMessage msg)
          Update the serverState with the last message sent.
 void updateWindow(WindowMessage windowMsg)
          Update the send window size based on the credit specified in the given window message.
 void warnBadGenerationId()
          Resets the generationId for this domain.
 
Methods inherited from class org.opends.server.api.MonitorProvider
finalizeMonitorProvider, getMonitorObjectClass, isConfigurationAcceptable, run
 
Methods inherited from class org.opends.server.api.DirectoryThread
getAssociatedTask, getCreationStackTrace, getDebugProperties, getParentThread, setAssociatedTask
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, yield
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerHandler

public ServerHandler(ProtocolSession session,
                     int queueSize)
Creates a new server handler instance with the provided socket.

Parameters:
session - The ProtocolSession used by the ServerHandler to communicate with the remote entity.
queueSize - The maximum number of update that will be kept in memory by this ServerHandler.
Method Detail

start

public void start(DN baseDn,
                  short replicationServerId,
                  java.lang.String replicationServerURL,
                  int windowSize,
                  boolean sslEncryption,
                  ReplicationServer replicationServer)
Do the exchange of start messages to know if the remote server is an LDAP or replication server and to exchange serverID. Then create the reader and writer thread.

Parameters:
baseDn - baseDn of the ServerHandler when this is an outgoing conn. null if this is an incoming connection (listen).
replicationServerId - The identifier of the replicationServer that creates this server handler.
replicationServerURL - The URL of the replicationServer that creates this server handler.
windowSize - the window size that this server handler must use.
sslEncryption - For outgoing connections indicates whether encryption should be used after the exchange of start messages. Ignored for incoming connections.
replicationServer - the ReplicationServer that created this server handler.

getServerId

public short getServerId()
get the Server Id.

Returns:
the ID of the server to which this object is linked

getServerAddressURL

public java.lang.String getServerAddressURL()
Retrieves the Address URL for this server handler.

Returns:
The Address URL for this server handler, in the form of an IP address and port separated by a colon.

getServerURL

public java.lang.String getServerURL()
Retrieves the URL for this server handler.

Returns:
The URL for this server handler, in the form of an address and port separated by a colon.

incrementOutCount

public void incrementOutCount()
Increase the counter of updates sent to the server.


incrementInCount

public void incrementInCount()
Increase the counter of update received from the server.


getInCount

public int getInCount()
Get the count of updates received from the server.

Returns:
the count of update received from the server.

getOutCount

public int getOutCount()
Get the count of updates sent to this server.

Returns:
The count of update sent to this server.

getInAckCount

public int getInAckCount()
Get the number of Ack received from the server managed by this handler.

Returns:
Returns the inAckCount.

getOutAckCount

public int getOutAckCount()
Get the number of Ack sent to the server managed by this handler.

Returns:
Returns the outAckCount.

isSaturated

public boolean isSaturated(ChangeNumber changeNumber,
                           ServerHandler sourceHandler)
Check is this server is saturated (this server has already been sent a bunch of updates and has not processed them so they are staying in the message queue for this server an the size of the queue for this server is above the configured limit. The limit can be defined in number of updates or with a maximum delay

Parameters:
changeNumber - The changenumber to use to make the delay calculations.
sourceHandler - The ServerHandler which is sending the update.
Returns:
true is saturated false if not saturated.

restartAfterSaturation

public boolean restartAfterSaturation(ServerHandler source)
Check that the size of the Server Handler messages Queue has lowered below the limit and therefore allowing the reception of messages from other servers to restart.

Parameters:
source - The ServerHandler which was sending the update. can be null.
Returns:
true if the processing can restart

isReplicationServer

public boolean isReplicationServer()
Check if the server associated to this ServerHandler is a replication server.

Returns:
true if the server associated to this ServerHandler is a replication server.

getRcvMsgQueueSize

public int getRcvMsgQueueSize()
Get the number of message in the receive message queue.

Returns:
Size of the receive message queue.

getApproxDelay

public long getApproxDelay()
Get an approximation of the delay by looking at the age of the oldest message that has not been sent to this server. This is an approximation because the age is calculated using the clock of the servee where the replicationServer is currently running while it should be calculated using the clock of the server that originally processed the change. The approximation error is therefore the time difference between

Returns:
the approximate delay for the connected server.

getApproxFirstMissingDate

public java.lang.Long getApproxFirstMissingDate()
Get the age of the older change that has not yet been replicated to the server handled by this ServerHandler.

Returns:
The age if the older change has not yet been replicated to the server handled by this ServerHandler.

getOlderUpdateTime

public long getOlderUpdateTime()
Get the older update time for that server.

Returns:
The older update time.

getOlderUpdateCN

public ChangeNumber getOlderUpdateCN()
Get the older Change Number for that server. Returns null when the queue is empty.

Returns:
The older change number.

isFollowing

public boolean isFollowing()
Check if the LDAP server can follow the speed of the other servers.

Returns:
true when the server has all the not yet sent changes in its queue.

setFollowing

public void setFollowing(boolean following)
Set the following flag of this server.

Parameters:
following - the value that should be set.

add

public void add(UpdateMessage update,
                ServerHandler sourceHandler)
Add an update the list of updates that must be sent to the server managed by this ServerHandler.

Parameters:
update - The update that must be added to the list of updates.
sourceHandler - The server that sent the update.

take

public UpdateMessage take()
Select the next update that must be sent to the server managed by this ServerHandler.

Returns:
the next update that must be sent to the server managed by this ServerHandler.

updateServerState

public boolean updateServerState(UpdateMessage msg)
Update the serverState with the last message sent.

Parameters:
msg - the last update sent.
Returns:
boolean indicating if the update was meaningfull.

getServerState

public ServerState getServerState()
Get the state of this server.

Returns:
ServerState the state for this server..

stopHandler

public void stopHandler()
Stop this server handler processing.


sendAck

public void sendAck(ChangeNumber changeNumber)
             throws java.io.IOException
Send the ack to the server that did the original modification.

Parameters:
changeNumber - The ChangeNumber of the update that is acked.
Throws:
java.io.IOException - In case of Exception thrown sending the ack.

ack

public void ack(AckMessage message,
                short ackingServerId)
Do the work when an ack message has been received from another server.

Parameters:
message - The ack message that was received.
ackingServerId - The id of the server that acked the change.

ackChangelog

public static void ackChangelog(AckMessage message,
                                short ackingServerId)
Process reception of an for an update that was received from a ReplicationServer.

Parameters:
message - the ack message that was received.
ackingServerId - The id of the server that acked the change.

addWaitingAck

public void addWaitingAck(UpdateMessage update,
                          int nbWaitedAck)
Add an update to the list of update waiting for acks.

Parameters:
update - the update that must be added to the list
nbWaitedAck - The number of ack that must be received before the update is fully acked.

addWaitingAck

public static void addWaitingAck(UpdateMessage update,
                                 short ChangelogServerId,
                                 ReplicationServerDomain replicationServerDomain,
                                 int nbWaitedAck)
Add an update to the list of update received from a replicationServer and waiting for acks.

Parameters:
update - The update that must be added to the list.
ChangelogServerId - The identifier of the replicationServer that sent the update.
replicationServerDomain - The ReplicationServerDomain from which the change was processed and to which the ack must later be sent.
nbWaitedAck - The number of ack that must be received before the update is fully acked.

getWaitingAckSize

public int getWaitingAckSize()
Get the size of the list of update waiting for acks.

Returns:
the size of the list of update waiting for acks.

incrementInAckCount

public void incrementInAckCount()
Increment the count of Acks received from this server.


isLDAPserver

public boolean isLDAPserver()
Check type of server handled.

Returns:
true if the handled server is an LDAP server. false if the handled server is a replicationServer

initializeMonitorProvider

public void initializeMonitorProvider(MonitorProviderCfg configuration)
                               throws ConfigException,
                                      InitializationException
Initializes this monitor provider based on the information in the provided configuration entry.

Specified by:
initializeMonitorProvider in class MonitorProvider<MonitorProviderCfg>
Parameters:
configuration - The configuration to use to initialize this monitor provider.
Throws:
ConfigException - If an unrecoverable problem arises in the process of performing the initialization.
InitializationException - If a problem occurs during initialization that is not related to the server configuration.

getMonitorInstanceName

public java.lang.String getMonitorInstanceName()
Retrieves the name of this monitor provider. It should be unique among all monitor providers, including all instances of the same monitor provider.

Specified by:
getMonitorInstanceName in class MonitorProvider<MonitorProviderCfg>
Returns:
The name of this monitor provider.

getUpdateInterval

public long getUpdateInterval()
Retrieves the length of time in milliseconds that should elapse between calls to the updateMonitorData() method. A negative or zero return value indicates that the updateMonitorData() method should not be periodically invoked.

Specified by:
getUpdateInterval in class MonitorProvider<MonitorProviderCfg>
Returns:
The length of time in milliseconds that should elapse between calls to the updateMonitorData() method.

updateMonitorData

public void updateMonitorData()
Performs any processing periodic processing that may be desired to update the information associated with this monitor. Note that best-effort attempts will be made to ensure that calls to this method come getUpdateInterval() milliseconds apart, but no guarantees will be made.

Specified by:
updateMonitorData in class MonitorProvider<MonitorProviderCfg>

getMonitorData

public java.util.ArrayList<Attribute> getMonitorData()
Retrieves a set of attributes containing monitor data that should be returned to the client if the corresponding monitor entry is requested.

Specified by:
getMonitorData in class MonitorProvider<MonitorProviderCfg>
Returns:
A set of attributes containing monitor data that should be returned to the client if the corresponding monitor entry is requested.

shutdown

public void shutdown()
Shutdown This ServerHandler.


toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Thread

decAndCheckWindow

public void decAndCheckWindow()
                       throws java.io.IOException
Decrement the protocol window, then check if it is necessary to send a WindowMessage and send it.

Throws:
java.io.IOException - when the session becomes unavailable.

checkWindow

public void checkWindow()
                 throws java.io.IOException
Check the protocol window and send WindowMessage if necessary.

Throws:
java.io.IOException - when the session becomes unavailable.

updateWindow

public void updateWindow(WindowMessage windowMsg)
Update the send window size based on the credit specified in the given window message.

Parameters:
windowMsg - The Window Message containing the information necessary for updating the window size.

getHeartbeatInterval

public long getHeartbeatInterval()
Get our heartbeat interval.

Returns:
Our heartbeat interval.

process

public void process(RoutableMessage msg)
Processes a routable message.

Parameters:
msg - The message to be processed.

sendInfo

public void sendInfo(ReplServerInfoMessage info)
              throws java.io.IOException
Sends the provided ReplServerInfoMessage.

Parameters:
info - The ReplServerInfoMessage message to be sent.
Throws:
java.io.IOException - When it occurs while sending the message,

receiveReplServerInfo

public void receiveReplServerInfo(ReplServerInfoMessage infoMsg)
Sets the replication server from the message provided.

Parameters:
infoMsg - The information message.

isRemoteLDAPServer

public boolean isRemoteLDAPServer(short wantedServer)
When this handler is connected to a replication server, specifies if a wanted server is connected to this replication server.

Parameters:
wantedServer - The server we want to know if it is connected to the replication server represented by this handler.
Returns:
boolean True is the wanted server is connected to the server represented by this handler.

hasRemoteLDAPServers

public boolean hasRemoteLDAPServers()
When the handler is connected to a replication server, specifies the replication server has remote LDAP servers connected to it.

Returns:
boolean True is the replication server has remote LDAP servers connected to it.

send

public void send(RoutableMessage msg)
          throws java.io.IOException
Send an InitializeRequestMessage to the server connected through this handler.

Parameters:
msg - The message to be processed
Throws:
java.io.IOException - when raised by the underlying session

sendError

public void sendError(ErrorMessage errorMsg)
               throws java.io.IOException
Send an ErrorMessage to the peer.

Parameters:
errorMsg - The message to be sent
Throws:
java.io.IOException - when raised by the underlying session

process

public void process(WindowProbe windowProbeMsg)
             throws java.io.IOException
Process the reception of a WindowProbe message.

Parameters:
windowProbeMsg - The message to process.
Throws:
java.io.IOException - When the session becomes unavailable.

getGenerationId

public long getGenerationId()
Returns the value of generationId for that handler.

Returns:
The value of the generationId.

warnBadGenerationId

public void warnBadGenerationId()
Resets the generationId for this domain.


forwardGenerationIdToRS

public void forwardGenerationIdToRS(ResetGenerationId msg)
                             throws java.io.IOException
Sends a message containing a generationId to a peer server. The peer is expected to be a replication server.

Parameters:
msg - The GenerationIdMessage message to be sent.
Throws:
java.io.IOException - When it occurs while sending the message,

setGenerationId

public void setGenerationId(long generationId)
Set a new generation ID.

Parameters:
generationId - The new generation ID

getDomain

public ReplicationServerDomain getDomain()
Returns the Replication Server Domain to which belongs this server handler.

Returns:
The replication server domain.

getConnectedServerIds

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

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