Class CSN
java.lang.Object
org.opends.server.replication.common.CSN
- All Implemented Interfaces:
Serializable
,Comparable<CSN>
Class used to represent Change Sequence Numbers.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
The version of a CSN to ask for a particular representation. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
The number of bytes used by the byte string representation of a change number v0.static final CSN
The maximum possible value for a CSN.static final CSN
The minimum possible value for a CSN.static final int
The position of the replica name in a string representation of a CSN.static final int
The number of characters used by the string representation of a change number v0. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic int
Compares this CSN with the provided CSN for order and returns a negative number ifcsn1
is older thancsn2
, zero if they have the same age, or a positive number ifcsn1
is newer thancsn2
.int
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
.boolean
Getter for the replica ID.int
Getter for the sequence number.long
getTime()
Getter for the time.long
Get the timestamp associated to thisCSN
in seconds.int
hashCode()
boolean
isNewerThan
(CSN csn) Returnstrue
if this CSN is newer than the provided CSN.boolean
isNewerThanOrEqualTo
(CSN csn) Returnstrue
if this CSN is newer than or equal to the provided CSN.boolean
isOlderThan
(CSN csn) Returnstrue
if this CSN is older than the provided CSN.boolean
isOlderThanOrEqualTo
(CSN csn) Returnstrue
if this CSN is older than or equal to the provided CSN.boolean
isOldestCsn
(ReplicaId replicaId) Returns if this is the oldest possible CSN for a replica.static boolean
Returnstrue
if the provided string can be parsed as a CSN.static CSN
newestCsn
(long timeStamp) Return the newest possible CSN for the given time.static CSN
Returns the newest possible CSN for a replica.static CSN
oldestCsn
(long timeStamp) Returns the oldest possible CSN for the given time.static CSN
Returns the oldest possible CSN for a replica.static void
skipCsn
(ByteStringReader reader) Advances reading the provided reader to the end of the CSN representation, by skipping over it.Encodes this CSN as a byte string.void
toByteString
(ByteStringBuilder builder, CSN.CsnVersion version) Encodes this CSN into the provided byte string builder according to the given CSN version.toByteString
(CSN.CsnVersion version) Encodes this CSN as a byte string according to the given CSN version.Returns theInstant
representing the CSN time.toJson()
Returns the json representation of this CSN.toString()
Convert theCSN
to a printable String.toString
(CSN.CsnVersion version) Convert theCSN
to a printable String according to the given CSN version.Convert theCSN
to a printable String with a user friendly format.static CSN
Parses the providedtoString()
representation of a CSN.static CSN
valueOf
(ByteString bs) Decodes the providedtoByteString(CsnVersion)
representation of a CSN.static CSN
valueOf
(ByteStringReader reader) Decodes the providedtoByteString(CsnVersion)
representation of a CSN, possibly embedded in a larger sequence.
-
Field Details
-
BYTE_ENCODING_V1_LENGTH
public static final int BYTE_ENCODING_V1_LENGTHThe 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_LENGTHThe number of characters used by the string representation of a change number v0.- See Also:
-
REPLICA_NAME_POSITION
public static final int REPLICA_NAME_POSITIONThe position of the replica name in a string representation of a CSN.- See Also:
-
MIN_VALUE
The minimum possible value for a CSN. -
MAX_VALUE
The maximum possible value for a CSN.
-
-
Constructor Details
-
CSN
public CSN(long timeStamp, int seqNum, int replicaId) Create a newCSN
.- Parameters:
timeStamp
- timeStamp for theCSN
seqNum
- sequence numberreplicaId
- identity of replica
-
CSN
Create a newCSN
.- Parameters:
timeStamp
- timeStamp for theCSN
seqNum
- sequence numberreplicaId
- identity of replica
-
-
Method Details
-
isValid
Returnstrue
if the provided string can be parsed as a CSN.- Parameters:
str
- the CSN- Returns:
true
if the provided string can be parsed as a CSN
-
valueOf
Parses the providedtoString()
representation of a CSN.- Parameters:
str
- The string to be parsed.- Returns:
- The parsed CSN.
- See Also:
-
valueOf
Decodes the providedtoByteString(CsnVersion)
representation of a CSN.- Parameters:
bs
- The byte string to be parsed.- Returns:
- The decoded CSN.
- See Also:
-
valueOf
Decodes the providedtoByteString(CsnVersion)
representation of a CSN, possibly embedded in a larger sequence.- Parameters:
reader
- The reader of the byte string to be parsed.- Returns:
- The decoded CSN.
-
skipCsn
Advances reading the provided reader to the end of the CSN representation, by skipping over it.- Parameters:
reader
- The reader to advance
-
getTime
public long getTime()Getter for the time.- Returns:
- the time
-
getTimeSec
public long getTimeSec()Get the timestamp associated to thisCSN
in seconds.- Returns:
- timestamp associated to this
CSN
in seconds
-
getSeqnum
public int getSeqnum()Getter for the sequence number.- Returns:
- the sequence number
-
getReplicaId
Getter for the replica ID.- Returns:
- the replica ID
-
equals
-
hashCode
public int hashCode() -
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:
-
toByteString
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
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:
-
toString
Convert theCSN
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. -
toString
Convert theCSN
to a printable String according to the given CSN version.- Parameters:
version
- The required representation version- Returns:
- the string
-
toStringUI
Convert theCSN
to a printable String with a user friendly format.- Returns:
- the string
-
compare
Compares this CSN with the provided CSN for order and returns a negative number ifcsn1
is older thancsn2
, zero if they have the same age, or a positive number ifcsn1
is 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
csn1
is older thancsn2
, zero if they have the same age, or a positive number ifcsn1
is newer thancsn2
.
-
isOlderThan
Returnstrue
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
Returnstrue
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
Returnstrue
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
Returnstrue
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
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:
compareTo
in 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
Returns theInstant
representing the CSN time.- Returns:
- the
Instant
representing the CSN time
-
oldestCsn
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
Returns the oldest possible CSN for a replica.- Parameters:
replicaId
- the replica- Returns:
- the oldest possible CSN for a replica
-
isOldestCsn
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
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
Returns the newest possible CSN for a replica.- Parameters:
replicaId
- the replica- Returns:
- the newest possible CSN for a replica
-
toJson
Returns the json representation of this CSN.- Returns:
- the json representation of this CSN
-