Class CSNGenerator


  • public class CSNGenerator
    extends Object
    This class defines a structure that is used for storing the last CSNs generated on this server or received from other servers and generating new CSNs that are guaranteed to be larger than all the previously seen or generated CSNs.
    • Constructor Detail

      • CSNGenerator

        public CSNGenerator​(int serverId,
                            long timestamp)
        Create a new CSNGenerator.
        Parameters:
        serverId - id to use when creating CSNs.
        timestamp - time to start with.
      • CSNGenerator

        public CSNGenerator​(int serverId,
                            ServerState state)
        Create a new CSNGenerator.
        Parameters:
        serverId - serverId to use when creating CSNs.
        state - This generator will be created in a way that makes sure that all CSNs generated will be larger than all the CSNs currently in state.
    • Method Detail

      • newCSN

        public CSN newCSN()
        Generate a new CSN.
        Returns:
        the generated CSN
      • adjust

        public void adjust​(CSN number)
        Adjust the lastTime of this CSNGenerator with a CSN that we have received from another server.

        This is necessary because we need that the CSN generated after processing an update received from other hosts to be larger than the received CSN

        Parameters:
        number - the CSN to adjust with
      • adjust

        public void adjust​(ServerState state)
        Adjust utility method that takes ServerState as a parameter.
        Parameters:
        state - the ServerState to adjust with