public class ReplicationServerHandler extends MonitorProvider
Modifier and Type | Field and Description |
---|---|
protected long |
heartbeatInterval
The time in milliseconds between heartbeats from the replication server.
|
protected HostPort |
hostPort
The host port of the remote server.
|
protected long |
peerGenerationId
Remote generation id.
|
protected GroupId |
peerGroupId
Group id of this remote server.
|
protected ProcessId |
peerProcessId
Process id of this remote server.
|
protected ReplicationServer |
replicationServer
Local hosting RS.
|
protected ReplicationServerDomain |
replicationServerDomain
Specifies the related replication server domain based on baseDN.
|
protected Session |
session
The session opened with the remote server.
|
protected boolean |
sslEncryption
The SSL encryption after the negotiation with the peer.
|
protected int |
weight
Weight of this remote server.
|
registry
Constructor and Description |
---|
ReplicationServerHandler(Session session,
ReplicationServer replicationServer)
Creates a new handler object to a remote replication server.
|
Modifier and Type | Method and Description |
---|---|
protected void |
abortStart(LocalizableMessage reason)
Abort a start procedure currently establishing.
|
void |
addDSInfos(List<DSInfo> dsInfos)
Add the DSinfos of the connected Directory Servers to the List of DSInfo provided as a parameter.
|
protected void |
addMonitorObjectClassNames(Attribute objectClassAttribute)
Adds to the provided attribute the objectclass names that should be included in the monitor entry created from
this monitor provider.
|
void |
bindTo(MeterRegistry parent)
.
|
protected Dn |
computeMonitorInstanceDn()
Returns the monitor instance DN for this monitor provider.
|
void |
connect(Dn baseDN,
boolean sslEncryption)
Connect the hosting RS to the RS represented by THIS handler on an outgoing connection.
|
protected ReplServerStartMsg |
createReplServerStartMsg()
Creates a ReplServerStartMsg for the current ServerHandler.
|
void |
doStop()
Stop this handler.
|
int |
estimateNumberOfUnsentMessages()
Returns an estimation of the number of messages not yet sent.
|
protected void |
finalizeStart()
Finalize the initialization, create reader, writer, heartbeat system and monitoring system.
|
long |
getApproxFirstMissingDate()
Get the age of the older change that has not yet been replicated to the server handled by this ServerHandler.
|
LocalizableMessage |
getBadlyDisconnectedErrorMessage()
Returns a "badly disconnected" error message for this server handler.
|
protected Dn |
getBaseDN()
Get the baseDN for this handler.
|
Set<ReplicaId> |
getConnectedDirectoryServerIds()
Return a Set containing the servers known by this replicationServer.
|
ReplicationServerDomain |
getDomain()
Returns the Replication Server Domain to which belongs this server handler.
|
long |
getHeartbeatInterval()
Get our heartbeat interval.
|
ReplicationServerId |
getLocalReplicationServerId()
Get the serverId of the hosting replication server.
|
long |
getPeerGenerationId()
Returns the value of generationId for that handler.
|
GroupId |
getPeerGroupId()
Gets the group id of the server represented by this object.
|
ProcessId |
getPeerProcessId()
Gets the process id of the server represented by this object.
|
HostPort |
getPeerServerHostPort()
Retrieves the address host port for this server handler.
|
ReplicationServerId |
getPeerServerId()
Get the serverId of the remote server.
|
short |
getProtocolVersion()
Gets the protocol version used with this remote server.
|
long |
getReferenceGenId()
Get the reference generation id (associated with the changes in the db).
|
ServerState |
getServerState()
Get the state of this server.
|
ServerStatus |
getStatus()
Gets the status of the connected DS.
|
boolean |
hasRemoteLDAPServers()
When the handler is connected to a replication server, specifies the replication server has remote LDAP servers
connected to it.
|
boolean |
isDataServer()
Check if the server associated to this ServerHandler is a data server in the topology.
|
boolean |
isRemoteLDAPServer(ReplicaId replicaId)
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.
|
void |
lockDomainNoTimeout()
Lock the domain without a timeout.
|
void |
lockDomainWithTimeout()
Lock the domain with a timeout.
|
protected void |
logStartHandshakeRCVandSND(StartMsg inStartMsg,
StartMsg outStartMsg)
Log the messages involved in the start handshake.
|
protected void |
logStartHandshakeSNDandRCV(StartMsg outStartMsg,
StartMsg inStartMsg)
Log the messages involved in the start handshake.
|
protected void |
logStartSessionHandshake(StartSessionMsg inStartSessionMsg,
TopologyMsg outTopoMsg)
Log the messages involved in the Topology/StartSession handshake.
|
protected void |
logStopReceived()
Log stop message has been received.
|
protected void |
logTopoHandshakeRCVandSND(TopologyMsg inTopoMsg,
TopologyMsg outTopoMsg)
Log the messages involved in the Topology handshake.
|
protected void |
logTopoHandshakeSNDandRCV(TopologyMsg outTopoMsg,
TopologyMsg inTopoMsg)
Log the messages involved in the Topology handshake.
|
void |
processTopoInfoFromRS(TopologyMsg topoMsg)
Stores topology information received from a peer RS and that must be kept in RS handler.
|
void |
put(UpdateMsg update)
Put a new update message received.
|
void |
receiveTopoInfoFromRS(TopologyMsg topoMsg)
Receives a topology msg.
|
protected void |
releaseDomainLock()
Releases the lock on the replication server domain if it was held.
|
void |
replyToWindowProbe()
Process the reception of a WindowProbeMsg message.
|
void |
send(ReplicationMsg msg)
Sends a message.
|
void |
sendTopoInfo(TopologyMsg topoMsg)
Sends the provided TopologyMsg to the peer server.
|
protected void |
setBaseDNAndDomain(Dn baseDN,
boolean isDataServer)
Set the baseDN for this handler.
|
void |
setInitialServerState(ServerState serverState)
Set the initial value of the serverState for this handler.
|
void |
setPeerGenerationId(long peerGenerationId)
Set a new generation ID.
|
void |
shutdown()
Shutdown This ServerHandler.
|
void |
startFromRemoteRS(ReplServerStartMsg inReplServerStartMsg)
Starts the handler from a remote ReplServerStart message received from the remote replication server.
|
RSInfo |
toRSInfo()
Creates a RSInfo structure representing this remote RS.
|
String |
toString() |
configurationDnToMonitorDn, deregisterAll, getMonitorEntry, getMonitorInstanceDn
protected final ReplicationServer replicationServer
protected ReplicationServerDomain replicationServerDomain
protected final Session session
protected HostPort hostPort
protected long peerGenerationId
protected GroupId peerGroupId
protected ProcessId peerProcessId
unknown
if the
performExtendedHandshake()
has not been done.protected boolean sslEncryption
protected long heartbeatInterval
protected int weight
public ReplicationServerHandler(Session session, ReplicationServer replicationServer)
session
- The session with the remote RS.replicationServer
- The hosting local RS object.public ReplicationServerId getPeerServerId()
public RSInfo toRSInfo()
public void connect(Dn baseDN, boolean sslEncryption) throws LdapException
baseDN
- The baseDNsslEncryption
- The sslEncryption requested to the remote RS.LdapException
- when an error occurs.public void startFromRemoteRS(ReplServerStartMsg inReplServerStartMsg)
inReplServerStartMsg
- The provided ReplServerStart message received.public boolean isDataServer()
public void addDSInfos(List<DSInfo> dsInfos)
dsInfos
- The List of DSInfo that should be updated with the DSInfo for the remoteDirectoryServers connected to
this ServerHandler.public void shutdown()
public void processTopoInfoFromRS(TopologyMsg topoMsg)
topoMsg
- The received topology messagepublic boolean isRemoteLDAPServer(ReplicaId replicaId)
replicaId
- The replica we want to know if it is connected to the replication server represented by this handler.public boolean hasRemoteLDAPServers()
public Set<ReplicaId> getConnectedDirectoryServerIds()
protected Dn computeMonitorInstanceDn()
MonitorProvider
computeMonitorInstanceDn
in class MonitorProvider
protected void addMonitorObjectClassNames(Attribute objectClassAttribute)
MonitorProvider
addMonitorObjectClassNames
in class MonitorProvider
objectClassAttribute
- the objectClass attribute where to add the object class namespublic void bindTo(MeterRegistry parent)
MonitorProvider
Implementations MUST set the MonitorProvider.registry
field by creating a new MeterRegistryHolder
, and
specifying the appropriate prefix for the dimensional model and also the hierarchical model if they are
different. This can be done using a parameter on the constructor, or the
MeterRegistryHolder.hierarchicalNamePrefix(String)
method. Tags common to all metrics for this monitor
provider can also be set using the MeterRegistryHolder.tag(String, String)
method.
Attribute names are then registered by calling factory methods on the MonitorProvider.registry
field.
(Please remove the comments when using this code as a template)
public void bindTo(final MeterRegistry parent) {
// create the MeterRegistryHolder wrapping OpenDJ's MeterRegistry
registry = new MeterRegistryHolder("dimensional-name-prefix", parent)
.tag("label", "dimension")
.hierarchicalNamePrefix("hierarchical-name-prefix.dimension");
// register the metrics against the wrapper
registry.numberGauge("gauge", numberSupplier); // use lambdas or method references here
timer = registry.timer("requests-submitted");
// set a different name for the metric in cn=monitor, dimensional model and hierarchical model
Gauge.doubleGauge(dimensionalName, supplier)
.hierarchicalName(hierarchicalName)
.tag(MeterRegistryHolder.TAG_ATTRIBUTE_NAME, "cn-monitor-name") // drop the "ds-mon-" prefix here
.register(registry);
// this gauge will only output to cn=monitor based monitoring endpoints
registry.monitoringGauge("only-visible-in-cn-monitor", supplier);
}
bindTo
in interface MeterBinder
public String toString()
toString
in class MonitorProvider
public ServerStatus getStatus()
public HostPort getPeerServerHostPort()
public void receiveTopoInfoFromRS(TopologyMsg topoMsg)
topoMsg
- The message received.public int estimateNumberOfUnsentMessages()
public ServerState getServerState()
protected Dn getBaseDN()
public void setInitialServerState(ServerState serverState) throws LdapException
serverState
- the provided serverState.LdapException
- raised when a problem occurs.protected void setBaseDNAndDomain(Dn baseDN, boolean isDataServer) throws LdapException
baseDN
- The provided baseDN.isDataServer
- The handler is a dataServerLdapException
- raised when a problem occurs.public ReplicationServerId getLocalReplicationServerId()
protected void abortStart(LocalizableMessage reason)
reason
- The provided reason.protected void releaseDomainLock()
protected void finalizeStart() throws LdapException
LdapException
- When an exception is raised.public void send(ReplicationMsg msg) throws IOException
msg
- The message to be sent.IOException
- When it occurs while sending the message,public long getApproxFirstMissingDate()
public ReplicationServerDomain getDomain()
public long getPeerGenerationId()
public GroupId getPeerGroupId()
public ProcessId getPeerProcessId()
unknown
if the information is not available either because handshake has not been done or peer is too old and
does not support process id.public long getHeartbeatInterval()
public short getProtocolVersion()
public boolean isReplicationServer()
public void lockDomainNoTimeout() throws InterruptedException
If domain already exists, lock it until handshake is finished otherwise it will be created and locked later in the method
InterruptedException
- If the current thread was interrupted while waiting for the lock.public void lockDomainWithTimeout() throws LdapException, InterruptedException
Take the lock on the domain. WARNING: Here we try to acquire the lock with a timeout. This is for preventing a deadlock that may happen if there are cross connection attempts (for same domain) from this replication server and from a peer one.
Here is the scenario:
To prevent threads locking in such situation, the listen threads here will both timeout trying to acquire the lock. The random time for the timeout should allow on connection attempt to be aborted whereas the other one should have time to finish in the same time.
Warning: the minimum time (3s) should be big enough to allow normal situation connections to terminate. The added random time should represent a big enough range so that the chance to have one listen thread timing out a lot before the peer one is great. When the first listen thread times out, the remote connect thread should release the lock and allow the peer listen thread to take the lock it was waiting for and process the connection attempt.
LdapException
- When an exception occurs.InterruptedException
- If the current thread was interrupted while waiting for the lock.public void replyToWindowProbe() throws IOException
IOException
- When the session becomes unavailable.public void sendTopoInfo(TopologyMsg topoMsg) throws IOException
topoMsg
- The TopologyMsg message to be sent.IOException
- When it occurs while sending the message,public void setPeerGenerationId(long peerGenerationId)
peerGenerationId
- The new generation IDprotected void logStartHandshakeRCVandSND(StartMsg inStartMsg, StartMsg outStartMsg)
inStartMsg
- The message received first.outStartMsg
- The message sent in response.protected void logStartHandshakeSNDandRCV(StartMsg outStartMsg, StartMsg inStartMsg)
outStartMsg
- The message sent first.inStartMsg
- The message received in response.protected void logTopoHandshakeRCVandSND(TopologyMsg inTopoMsg, TopologyMsg outTopoMsg)
inTopoMsg
- The message received first.outTopoMsg
- The message sent in response.protected void logTopoHandshakeSNDandRCV(TopologyMsg outTopoMsg, TopologyMsg inTopoMsg)
outTopoMsg
- The message sent first.inTopoMsg
- The message received in response.protected void logStartSessionHandshake(StartSessionMsg inStartSessionMsg, TopologyMsg outTopoMsg)
inStartSessionMsg
- The message received first.outTopoMsg
- The message sent in response.protected void logStopReceived()
public long getReferenceGenId()
public void put(UpdateMsg update) throws IOException
update
- the update message received.IOException
- when it occurs.public void doStop()
protected ReplServerStartMsg createReplServerStartMsg()
public LocalizableMessage getBadlyDisconnectedErrorMessage()
Copyright 2010-2022 ForgeRock AS.