Class CSN
- java.lang.Object
-
- org.opends.server.replication.common.CSN
-
- All Implemented Interfaces:
Serializable,Comparable<CSN>
public class CSN extends Object implements Serializable, Comparable<CSN>
Class used to represent Change Sequence Numbers.
-
-
Field Summary
Fields Modifier and Type Field Description static intBYTE_ENCODING_LENGTHThe number of bytes used by the byte string representation of a change number.static CSNMAX_CSN_VALUEThe maximum possible value for a CSN.static intSTRING_ENCODING_LENGTHThe number of characters used by the string representation of a change number.
-
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.static intdiffSeqNum(CSN csn1, CSN csn2)Computes the difference in number of changes between 2 CSNs.booleanequals(Object obj)intgetSeqnum()Getter for the sequence number.intgetServerId()Getter for the server ID.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.ByteStringtoByteString()Encodes this CSN as a byte string.voidtoByteString(ByteStringBuilder builder)Encodes this CSN into the provided byte string builder.StringtoString()Convert theCSNto a printable String.StringtoStringUI()Convert theCSNto a printable String with a user friendly format.static CSNvalueOf(String s)Parses the providedtoString()representation of a CSN.static CSNvalueOf(ByteSequence bs)Decodes the providedtoByteString()representation of a change number.
-
-
-
Field Detail
-
BYTE_ENCODING_LENGTH
public static final int BYTE_ENCODING_LENGTH
The number of bytes used by the byte string representation of a change number.
-
STRING_ENCODING_LENGTH
public static final int STRING_ENCODING_LENGTH
The number of characters used by the string representation of a change number.- See Also:
valueOf(String),toString(), Constant Field Values
-
MAX_CSN_VALUE
public static final CSN MAX_CSN_VALUE
The maximum possible value for a CSN.
-
-
Constructor Detail
-
CSN
public CSN(String str)
Create a newCSNfrom a String.- Parameters:
str- the string from which to create aCSN- Throws:
org.forgerock.i18n.LocalizedIllegalArgumentException- If the provided string is not a validtoString()representation of a CSN
-
-
Method Detail
-
valueOf
public static CSN valueOf(String s)
Parses the providedtoString()representation of a CSN.- Parameters:
s- The string to be parsed.- Returns:
- The parsed CSN.
- Throws:
org.forgerock.i18n.LocalizedIllegalArgumentException- If the provided string is not a validtoString()representation of a CSN- See Also:
toString()
-
valueOf
public static CSN valueOf(ByteSequence bs)
Decodes the providedtoByteString()representation of a change number.- Parameters:
bs- The byte sequence to be parsed.- Returns:
- The decoded CSN.
- See Also:
toByteString()
-
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
-
getServerId
public int getServerId()
Getter for the server ID.- Returns:
- the server ID
-
toByteString
public ByteString toByteString()
Encodes this CSN as a byte string.NOTE: this representation must not be modified otherwise interop with earlier protocol versions will be broken.
- Returns:
- The encoded representation of this CSN.
- See Also:
valueOf(ByteSequence)
-
toByteString
public void toByteString(ByteStringBuilder builder)
Encodes this CSN into the provided byte string builder.NOTE: this representation must not be modified otherwise interop with earlier protocol versions will be broken.
- Parameters:
builder- The byte string builder.- See Also:
valueOf(ByteSequence)
-
toString
public String toString()
Convert theCSNto a printable String.NOTE: this representation must not be modified otherwise interop with earlier protocol versions will be broken.
-
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.
-
diffSeqNum
public static int diffSeqNum(CSN csn1, CSN csn2)
Computes the difference in number of changes between 2 CSNs. First one is expected to be newer than second one. If this is not the case, 0 will be returned.
-
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.
-
-