Class Csn
java.lang.Object
org.opends.server.replication.common.Csn
- All Implemented Interfaces:
Serializable, Comparable<Csn>
Class used to represent Change Sequence Numbers.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumThe version of a CSN to ask for a particular representation. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe number of bytes used by the byte string representation of a change number v1.static final longThe maximum stream sequence number.static final CsnThe maximum possible value for a CSN; used for comparisons and initialization, the stream id does not count.static final longThe minimum stream sequence number.static final CsnThe minimum possible value for a CSN; used for comparisons and initialization, the stream id does not count.static final longThe has no meaning for this CSN.static final longThe stream sequence number to use when no stream sequence number is needed.static final intThe position of the replica name in a string representation of a CSN V1 and V2.static final intThe position of the replica name in a string representation of a CSN V3.static final intThe position of the stream sequence number in a string representation of a CSN V3.static final intThe number of characters used by the string representation of a change number v1. -
Method Summary
Modifier and TypeMethodDescriptionstatic intCompares 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.intCompares 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.booleanReturns the replica ID.intReturns the sequence number.longReturns the stream sequence number.longReturns the stream timestamp associated to thisCsnin milliseconds.longgetTime()Returns the timestamp associated to this CSN in milliseconds.longReturns the timestamp associated to thisCsnin seconds.Returns the CSN version.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 booleanReturnstrueif the provided string can be parsed as a CSN.static CsnCreate a newCsn.static CsnCreate a newCsn.static CsnnewCsnV1(long timeStamp, int seqNum, int replicaId) Create a newCsn.static CsnCreate a newCsn.static CsnnewestCsn(long timeStamp) Returns the newest possible CSN for the given time.static CsnReturns the newest possible CSN for a replica.static CsnoldestCsn(long timeStamp) Returns the oldest possible CSN for the given time.static CsnReturns the oldest possible CSN for a replica.static voidskipCsn(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.voidtoByteString(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 theInstantrepresenting the CSN time.toJson()Returns the json representation of this CSN.toString()Convert theCsnto a printable String.toString(Csn.CsnVersion version) Convert theCsnto a printable String according to the given CSN version.Convert theCsnto a printable String with a user friendly format.static CsnParses the providedtoString()representation of a CSN.static CsnvalueOf(ByteString bs) Decodes the providedtoByteString(CsnVersion)representation of a CSN.static CsnvalueOf(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 v1.- See Also:
-
STRING_ENCODING_V1_LENGTH
public static final int STRING_ENCODING_V1_LENGTHThe number of characters used by the string representation of a change number v1.- See Also:
-
REPLICA_NAME_POSITION_V2
public static final int REPLICA_NAME_POSITION_V2The position of the replica name in a string representation of a CSN V1 and V2.- See Also:
-
STREAM_SEQNUM_POSITION_V3
public static final int STREAM_SEQNUM_POSITION_V3The position of the stream sequence number in a string representation of a CSN V3.- See Also:
-
REPLICA_NAME_POSITION_V3
public static final int REPLICA_NAME_POSITION_V3The position of the replica name in a string representation of a CSN V3.- See Also:
-
NO_STREAM
public static final long NO_STREAMThe has no meaning for this CSN.- See Also:
-
NO_STREAM_SEQ_NUM
public static final long NO_STREAM_SEQ_NUMThe stream sequence number to use when no stream sequence number is needed.- See Also:
-
MIN_STREAM_SEQ_NUM
public static final long MIN_STREAM_SEQ_NUMThe minimum stream sequence number.- See Also:
-
MAX_STREAM_SEQ_NUM
public static final long MAX_STREAM_SEQ_NUMThe maximum stream sequence number.- See Also:
-
MIN_VALUE
The minimum possible value for a CSN; used for comparisons and initialization, the stream id does not count. -
MAX_VALUE
The maximum possible value for a CSN; used for comparisons and initialization, the stream id does not count.
-
-
Method Details
-
isValid
Returnstrueif the provided string can be parsed as a CSN.- Parameters:
str- the CSN- Returns:
trueif 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
-
newCsnV1
-
newCsnV2
-
newCsn
-
newCsn
-
getVersion
-
getTime
public long getTime()Returns the timestamp associated to this CSN in milliseconds.- Returns:
- the timestamp associated to this CSN in milliseconds
-
getTimeSec
-
getStreamTimeStamp
-
getSeqnum
public int getSeqnum()Returns the sequence number.- Returns:
- the sequence number
-
getStreamSeqNum
public long getStreamSeqNum()Returns the stream sequence number.- Returns:
- the stream sequence number
-
getReplicaId
-
equals
-
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 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
Convert theCsnto a printable String according to the given CSN version.- Parameters:
version- The required representation version- Returns:
- the string
-
toStringUI
-
compare
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
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
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
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
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
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
Returns theInstantrepresenting the CSN time.- Returns:
- the
Instantrepresenting 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
-
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
Returns 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
-
toJson
Returns the json representation of this CSN.- Returns:
- the json representation of this CSN
-