Class ReplicationBroker


  • public class ReplicationBroker
    extends Object
    The broker for Multi-master Replication.
    • Constructor Detail

      • ReplicationBroker

        public ReplicationBroker​(ReplicationDomain replicationDomain,
                                 ServerState state,
                                 ReplicationDomainCfg config,
                                 ReplSessionSecurity replSessionSecurity)
        Creates a new ReplicationServer Broker for a particular ReplicationDomain.
        Parameters:
        replicationDomain - The replication domain that is creating us.
        state - The ServerState that should be used by this broker when negotiating the session with the replicationServer.
        config - The configuration to use.
        replSessionSecurity - The session security configuration.
    • Method Detail

      • start

        public void start()
        Start the ReplicationBroker.
      • getRsGroupId

        public byte getRsGroupId()
        Gets the group id of the RS we are connected to.
        Returns:
        The group id of the RS we are connected to
      • getRsServerId

        public int getRsServerId()
        Gets the server id of the RS we are connected to.
        Returns:
        The server id of the RS we are connected to
      • getServerId

        public int getServerId()
        Gets the server id.
        Returns:
        The server id
      • setGenerationID

        public void setGenerationID​(long generationID)
        Set the generation id - for test purpose.
        Parameters:
        generationID - The generation id
      • reStart

        public void reStart​(boolean infiniteTry)
        Restart the ReplicationBroker.
        Parameters:
        infiniteTry - the socket which failed
      • publish

        public void publish​(ReplicationMsg msg)
        Publish a message to the other servers.
        Parameters:
        msg - the message to publish
      • publishRecovery

        public void publishRecovery​(ReplicationMsg msg)
        Publish a recovery message to the other servers.
        Parameters:
        msg - the message to publish
      • receive

        public ReplicationMsg receive()
                               throws SocketTimeoutException
        Receive a message. This method is not thread-safe and should either always be called in a single thread or protected by a locking mechanism before being called. This is a wrapper to the method with a boolean version so that we do not have to modify existing tests.
        Returns:
        the received message
        Throws:
        SocketTimeoutException - if the timeout set by setSoTimeout has expired
      • getReplicaStates

        public Map<Integer,​ServerState> getReplicaStates()
        Gets the States of all the Replicas currently in the Topology. When this method is called, a Monitoring message will be sent to the Replication Server to which this domain is currently connected so that it computes a table containing information about all Directory Servers in the topology. This Computation involves communications will all the servers currently connected and
        Returns:
        The States of all Replicas in the topology (except us)
      • 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 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 usable even after such an Exception is raised.
        Parameters:
        timeout - the specified timeout, in milliseconds.
        Throws:
        SocketException - if there is an error in the underlying protocol, such as a TCP error.
      • getReplicationServer

        public HostPort getReplicationServer()
        Get the host and port of the replicationServer to which this broker is currently connected.
        Returns:
        the host and port of the replicationServer to which this domain is currently connected.
      • 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.
      • 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.
      • signalStatusChange

        public void signalStatusChange​(ServerStatus newStatus)
        Signals the RS we just entered a new status.
        Parameters:
        newStatus - The status the local DS just entered
      • getReplicaInfos

        public Map<Integer,​DSInfo> getReplicaInfos()
        Gets the info for DSs in the topology (except us).
        Returns:
        The info for DSs in the topology (except us)
      • getRsInfos

        public List<RSInfo> getRsInfos()
        Gets the info for RSs in the topology (except the one we are connected to).
        Returns:
        The info for RSs in the topology (except the one we are connected to)
      • setRecoveryRequired

        public void setRecoveryRequired​(boolean b)
        Set the connectRequiresRecovery to the provided value. This flag is used to indicate if a recovery of Update is necessary after a reconnection to a RS. It is the responsibility of the ReplicationDomain to set it during the sessionInitiated phase.
        Parameters:
        b - the new value of the connectRequiresRecovery.