Class ServerState

  • All Implemented Interfaces:
    Iterable<CSN>

    public class ServerState
    extends Object
    implements Iterable<CSN>
    This class is used to associate serverIds with CSNs.

    For example, it is exchanged with the replication servers at connection establishment time to communicate "which CSNs was last seen by a serverId".

    • Constructor Detail

      • ServerState

        public ServerState()
        Creates a new empty ServerState.
    • Method Detail

      • clear

        public void clear()
        Empty the ServerState. After this call the Server State no longer holds any CSN. A state which held one is marked as not saved: dropping it is a change like any other, which persistent storage has yet to be told about. A state which held nothing is left alone, the way an update which changes nothing is.
      • update

        public boolean update​(CSN csn)
        Forward update the Server State with a CSN. The provided CSN will be put on the current object only if it is newer than the existing CSN for the same serverId or if there is no existing CSN.
        Parameters:
        csn - The committed CSN.
        Returns:
        a boolean indicating if the update was meaningful.
      • update

        public boolean update​(ServerState serverState)
        Update the Server State with a Server State. Every CSN of this object is updated with the CSN of the passed server state if it is newer.
        Parameters:
        serverState - the server state to use for the update.
        Returns:
        a boolean indicating if the update was meaningful.
      • removeCSN

        public boolean removeCSN​(CSN expectedCSN)
        Removes the mapping to the provided CSN if it is present in this ServerState.
        Parameters:
        expectedCSN - the CSN to be removed
        Returns:
        true if the CSN could be removed, false otherwise.
      • toStringSet

        public Set<String> toStringSet()
        Return a Set of String usable as a textual representation of a Server state. format : time seqnum id example : 1 00000109e4666da600220001 2 00000109e44567a600220002
        Returns:
        the representation of the Server state
      • toASN1ArrayList

        public ArrayList<ByteString> toASN1ArrayList()
        Return an ArrayList of ANS1OctetString encoding the CSNs contained in the ServerState.
        Returns:
        an ArrayList of ANS1OctetString encoding the CSNs contained in the ServerState.
      • writeTo

        public void writeTo​(ASN1Writer writer,
                            short protocolVersion)
                     throws IOException
        Encodes this server state to the provided ASN1 writer.
        Parameters:
        writer - The ASN1 writer.
        protocolVersion - The replication protocol version.
        Throws:
        IOException - If an error occurred during encoding.
      • getSnapshot

        public List<CSN> getSnapshot()
        Returns a snapshot of this object.
        Returns:
        an unmodifiable List representing a snapshot of this object.
      • toString

        public String toString()
        Return the text representation of ServerState.
        Overrides:
        toString in class Object
        Returns:
        the text representation of ServerState
      • getCSN

        public CSN getCSN​(int serverId)
        Returns the CSN contained in this server state which corresponds to the provided server ID.
        Parameters:
        serverId - The server ID.
        Returns:
        The CSN contained in this server state which corresponds to the provided server ID.
      • getServerIdToCSNMap

        public Map<Integer,​CSN> getServerIdToCSNMap()
        Returns a copy of this ServerState's content as a Map of serverId => CSN.
        Returns:
        a copy of this ServerState's content as a Map of serverId => CSN.
      • cover

        public boolean cover​(ServerState covered)
        Check that all the CSNs in the covered serverState are also in this serverState.
        Parameters:
        covered - The ServerState that needs to be checked.
        Returns:
        A boolean indicating if this ServerState covers the ServerState given in parameter.
      • cover

        public boolean cover​(CSN covered)
        Checks that the CSN given as a parameter is in this ServerState.
        Parameters:
        covered - The CSN that should be checked.
        Returns:
        A boolean indicating if this ServerState contains the CSN given in parameter.
      • isEmpty

        public boolean isEmpty()
        Tests if the state is empty.
        Returns:
        True if the state is empty.
      • duplicate

        public ServerState duplicate()
        Make a duplicate of this state.
        Returns:
        The duplicate of this state.
      • diffChanges

        public static int diffChanges​(ServerState ss1,
                                      ServerState ss2)
                               throws IllegalArgumentException
        Computes the number of changes a first server state has in advance compared to a second server state.
        Parameters:
        ss1 - The server state supposed to be newer than the second one
        ss2 - The server state supposed to be older than the first one
        Returns:
        The difference of changes (sum of the differences for each server id changes). 0 If no gap between 2 states.
        Throws:
        IllegalArgumentException - If one of the passed state is null
      • setSaved

        public void setSaved​(boolean b)
        Set the saved status of this ServerState.
        Parameters:
        b - A boolean indicating if the State has been safely stored.
      • isSaved

        public boolean isSaved()
        Get the saved status of this ServerState.
        Returns:
        The saved status of this ServerState.