Class CSN
- java.lang.Object
-
- org.opends.server.replication.common.CSN
-
- All Implemented Interfaces:
Serializable,Comparable<CSN>
public final class CSN extends Object implements Serializable, Comparable<CSN>
Class used to represent Change Sequence Numbers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classCSN.CsnVersionThe version of a CSN to ask for a particular representation.
-
Field Summary
Fields Modifier and Type Field Description static intBYTE_ENCODING_V1_LENGTHThe number of bytes used by the byte string representation of a change number v0.static CSNMAX_VALUEThe maximum possible value for a CSN.static CSNMIN_VALUEThe minimum possible value for a CSN.static intREPLICA_NAME_POSITIONThe position of the replica name in a string representation of a CSN.static intSTRING_ENCODING_V1_LENGTHThe number of characters used by the string representation of a change number v0.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static intcompare(CSN csn1, CSN csn2)Compares this CSN with the provided CSN for order and returns a negative number ifcsn1is older thancsn2, zero if they have the same age, or a positive number ifcsn1is newer thancsn2.intcompareTo(CSN csn)Compares this CSN with the provided CSN for order and returns a negative number if this CSN is older thancsn, zero if they have the same age, or a positive number if this CSN is newer thancsn.booleanequals(Object obj)ReplicaIdgetReplicaId()Getter for the replica ID.intgetSeqnum()Getter for the sequence number.longgetTime()Getter for the time.longgetTimeSec()Get the timestamp associated to thisCSNin seconds.inthashCode()booleanisNewerThan(CSN csn)Returnstrueif this CSN is newer than the provided CSN.booleanisNewerThanOrEqualTo(CSN csn)Returnstrueif this CSN is newer than or equal to the provided CSN.booleanisOlderThan(CSN csn)Returnstrueif this CSN is older than the provided CSN.booleanisOlderThanOrEqualTo(CSN csn)Returnstrueif this CSN is older than or equal to the provided CSN.booleanisOldestCsn(ReplicaId replicaId)Returns if this is the oldest possible CSN for a replica.static CSNnewestCsn(long timeStamp)Return the newest possible CSN for the given time.static CSNnewestCsn(ReplicaId replicaId)Returns the newest possible CSN for a replica.static CSNoldestCsn(long timeStamp)Returns the oldest possible CSN for the given time.static CSNoldestCsn(ReplicaId replicaId)Returns the oldest possible CSN for a replica.static voidskipCsn(ByteSequenceReader reader)Advances reading the provided reader to the end of the CSN representation, by skipping over it.ByteStringtoByteString()Encodes this CSN as a byte string.voidtoByteString(ByteStringBuilder builder, CSN.CsnVersion version)Encodes this CSN into the provided byte string builder according to the given CSN version.ByteStringtoByteString(CSN.CsnVersion version)Encodes this CSN as a byte string according to the given CSN version.InstanttoInstant()Returns theInstantrepresenting the CSN time.JsonValuetoJson()Returns the json representation of this CSN.StringtoString()Convert theCSNto a printable String.StringtoString(CSN.CsnVersion version)Convert theCSNto a printable String according to the given CSN version.StringtoStringUI()Convert theCSNto a printable String with a user friendly format.static CSNvalueOf(String str)Parses the providedtoString()representation of a CSN.static CSNvalueOf(ByteSequence bs)Decodes the providedtoByteString(CsnVersion)representation of a CSN.static CSNvalueOf(ByteSequenceReader reader)Decodes the providedtoByteString(CsnVersion)representation of a CSN, possibly embedded in a larger sequence.
-
-
-
Field Detail
-
BYTE_ENCODING_V1_LENGTH
public static final int BYTE_ENCODING_V1_LENGTH
The number of bytes used by the byte string representation of a change number v0.
-
STRING_ENCODING_V1_LENGTH
public static final int STRING_ENCODING_V1_LENGTH
The number of characters used by the string representation of a change number v0.- See Also:
valueOf(String),toString(), Constant Field Values
-
REPLICA_NAME_POSITION
public static final int REPLICA_NAME_POSITION
The position of the replica name in a string representation of a CSN.- See Also:
- Constant Field Values
-
MIN_VALUE
public static final CSN MIN_VALUE
The minimum possible value for a CSN.
-
MAX_VALUE
public static final CSN MAX_VALUE
The maximum possible value for a CSN.
-
-
Method Detail
-
valueOf
public static CSN valueOf(String str)
Parses the providedtoString()representation of a CSN.- Parameters:
str- The string to be parsed.- Returns:
- The parsed CSN.
- See Also:
toString()
-
valueOf
public static CSN valueOf(ByteSequence bs)
Decodes the providedtoByteString(CsnVersion)representation of a CSN.- Parameters:
bs- The byte sequence to be parsed.- Returns:
- The decoded CSN.
- See Also:
toByteString(CsnVersion)
-
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 providedtoByteString(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 thisCSNin seconds.- Returns:
- timestamp associated to this
CSNin 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
-
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 theCSNto 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.
-
toString
public String toString(CSN.CsnVersion version)
Convert theCSNto a printable String according to the given CSN version.- Parameters:
version- The required representation version- Returns:
- the string
-
toStringUI
public String toStringUI()
Convert theCSNto 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 ifcsn1is older thancsn2, zero if they have the same age, or a positive number ifcsn1is newer thancsn2.- Parameters:
csn1- The first CSN to be compared, which may benull.csn2- The second CSN to be compared, which may benull.- Returns:
- A negative number if
csn1is older thancsn2, zero if they have the same age, or a positive number ifcsn1is newer thancsn2.
-
isOlderThan
public boolean isOlderThan(CSN csn)
Returnstrueif this CSN is older than the provided CSN.- Parameters:
csn- The CSN to be compared.- Returns:
trueif this CSN is older than the provided CSN.
-
isOlderThanOrEqualTo
public boolean isOlderThanOrEqualTo(CSN csn)
Returnstrueif this CSN is older than or equal to the provided CSN.- Parameters:
csn- The CSN to be compared.- Returns:
trueif this CSN is older than or equal to the provided CSN.
-
isNewerThanOrEqualTo
public boolean isNewerThanOrEqualTo(CSN csn)
Returnstrueif this CSN is newer than or equal to the provided CSN.- Parameters:
csn- The CSN to be compared.- Returns:
trueif this CSN is newer than or equal to the provided CSN.
-
isNewerThan
public boolean isNewerThan(CSN csn)
Returnstrueif this CSN is newer than the provided CSN.- Parameters:
csn- The CSN to be compared.- Returns:
trueif 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 thancsn, zero if they have the same age, or a positive number if this CSN is newer thancsn.- Specified by:
compareToin interfaceComparable<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 thancsn.
-
toInstant
public Instant toInstant()
Returns theInstantrepresenting the CSN time.- Returns:
- the
Instantrepresenting 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
-
-