Class CSN

    • Constructor Detail

      • CSN

        public CSN​(long timeStamp,
                   int seqNum,
                   int replicaId)
        Create a new CSN.
        Parameters:
        timeStamp - timeStamp for the CSN
        seqNum - sequence number
        replicaId - identity of replica
      • CSN

        public CSN​(long timeStamp,
                   int seqNum,
                   ReplicaId replicaId)
        Create a new CSN.
        Parameters:
        timeStamp - timeStamp for the CSN
        seqNum - sequence number
        replicaId - identity of replica
    • Method Detail

      • valueOf

        public static CSN valueOf​(String str)
        Parses the provided toString() representation of a CSN.
        Parameters:
        str - The string to be parsed.
        Returns:
        The parsed CSN.
        See Also:
        toString()
      • skipCsn

        public static void skipCsn​(ByteSequenceReader reader)
        Advances reading the provided reader to the end of the CSN representation, by skipping over it.
        Parameters:
        reader - The reader to advance
      • valueOf

        public static CSN valueOf​(ByteSequenceReader reader)
        Decodes the provided toByteString(CsnVersion) representation of a CSN, possibly embedded in a larger sequence.
        Parameters:
        reader - The reader of the byte sequence to be parsed.
        Returns:
        The decoded CSN.
      • getTime

        public long getTime()
        Getter for the time.
        Returns:
        the time
      • getTimeSec

        public long getTimeSec()
        Get the timestamp associated to this CSN in seconds.
        Returns:
        timestamp associated to this CSN in seconds
      • getSeqnum

        public int getSeqnum()
        Getter for the sequence number.
        Returns:
        the sequence number
      • getReplicaId

        public ReplicaId getReplicaId()
        Getter for the replica ID.
        Returns:
        the replica ID
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • toByteString

        public ByteString toByteString()
        Encodes this CSN as a byte string.

        The returned representation is according to the most recent CSN version. Use toByteString(CsnVersion) to get a representation compatible with earlier protocol versions.

        Returns:
        The encoded representation of this CSN.
        See Also:
        valueOf(ByteSequence)
      • toByteString

        public ByteString toByteString​(CSN.CsnVersion version)
        Encodes this CSN as a byte string according to the given CSN version.
        Parameters:
        version - The required representation version
        Returns:
        The encoded representation of this CSN.
      • toByteString

        public void toByteString​(ByteStringBuilder builder,
                                 CSN.CsnVersion version)
        Encodes this CSN into the provided byte string builder according to the given CSN version.
        Parameters:
        builder - The byte string builder.
        version - The required representation version
        See Also:
        valueOf(ByteSequence)
      • toString

        public String toString()
        Convert the CSN to a printable String.

        The returned representation is according to the most recent CSN version. Use toString(CsnVersion) to get a representation compatible with earlier protocol versions.

        Overrides:
        toString in class Object
        Returns:
        the string
      • toString

        public String toString​(CSN.CsnVersion version)
        Convert the CSN to a printable String according to the given CSN version.

        Parameters:
        version - The required representation version
        Returns:
        the string
      • toStringUI

        public String toStringUI()
        Convert the CSN to a printable String with a user friendly format.
        Returns:
        the string
      • compare

        public static int compare​(CSN csn1,
                                  CSN csn2)
        Compares this CSN with the provided CSN for order and returns a negative number if csn1 is older than csn2, zero if they have the same age, or a positive number if csn1 is newer than csn2.
        Parameters:
        csn1 - The first CSN to be compared, which may be null.
        csn2 - The second CSN to be compared, which may be null.
        Returns:
        A negative number if csn1 is older than csn2, zero if they have the same age, or a positive number if csn1 is newer than csn2.
      • isOlderThan

        public boolean isOlderThan​(CSN csn)
        Returns true if this CSN is older than the provided CSN.
        Parameters:
        csn - The CSN to be compared.
        Returns:
        true if this CSN is older than the provided CSN.
      • isOlderThanOrEqualTo

        public boolean isOlderThanOrEqualTo​(CSN csn)
        Returns true if this CSN is older than or equal to the provided CSN.
        Parameters:
        csn - The CSN to be compared.
        Returns:
        true if this CSN is older than or equal to the provided CSN.
      • isNewerThanOrEqualTo

        public boolean isNewerThanOrEqualTo​(CSN csn)
        Returns true if this CSN is newer than or equal to the provided CSN.
        Parameters:
        csn - The CSN to be compared.
        Returns:
        true if this CSN is newer than or equal to the provided CSN.
      • isNewerThan

        public boolean isNewerThan​(CSN csn)
        Returns true if this CSN is newer than the provided CSN.
        Parameters:
        csn - The CSN to be compared.
        Returns:
        true if this CSN is newer than the provided CSN.
      • compareTo

        public int compareTo​(CSN csn)
        Compares this CSN with the provided CSN for order and returns a negative number if this CSN is older than csn, zero if they have the same age, or a positive number if this CSN is newer than csn.
        Specified by:
        compareTo in interface Comparable<CSN>
        Parameters:
        csn - The CSN to be compared.
        Returns:
        A negative number if this CSN is older than csn, zero if they have the same age, or a positive number if this CSN is newer than csn.
      • toInstant

        public Instant toInstant()
        Returns the Instant representing the CSN time.
        Returns:
        the Instant representing the CSN time
      • oldestCsn

        public static CSN oldestCsn​(long timeStamp)
        Returns the oldest possible CSN for the given time.
        Parameters:
        timeStamp - the time of the CSN
        Returns:
        the oldest possible CSN for the given time
      • oldestCsn

        public static CSN oldestCsn​(ReplicaId replicaId)
        Returns the oldest possible CSN for a replica.
        Parameters:
        replicaId - the replica
        Returns:
        the oldest possible CSN for a replica
      • isOldestCsn

        public boolean isOldestCsn​(ReplicaId replicaId)
        Returns if this is the oldest possible CSN for a replica.
        Parameters:
        replicaId - the replica
        Returns:
        if this is the oldest possible CSN for a replica
      • newestCsn

        public static CSN newestCsn​(long timeStamp)
        Return the newest possible CSN for the given time.
        Parameters:
        timeStamp - the time of the CSN
        Returns:
        the newest possible CSN for the given time
      • newestCsn

        public static CSN newestCsn​(ReplicaId replicaId)
        Returns the newest possible CSN for a replica.
        Parameters:
        replicaId - the replica
        Returns:
        the newest possible CSN for a replica
      • toJson

        public JsonValue toJson()
        Returns the json representation of this CSN.
        Returns:
        the json representation of this CSN