org.apache.directory.shared.ldap.csn
Class Csn

java.lang.Object
  extended by org.apache.directory.shared.ldap.csn.Csn
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<Csn>

public class Csn
extends java.lang.Object
implements java.io.Serializable, java.lang.Comparable<Csn>

Represents 'Change Sequence Number' in LDUP specification. A CSN is a composition of a timestamp, a replica ID and a operation sequence number. It's described in http://tools.ietf.org/html/draft-ietf-ldup-model-09. The CSN syntax is :

             ::=  #  #  # 
       ::= A GMT based time, YYYYmmddHHMMSS.uuuuuuZ
     ::= [000000-ffffff] 
       ::= [000-fff]
  ::= [000000-ffffff]
 
It distinguishes a change made on an object on a server, and if two operations take place during the same timeStamp, the operation sequence number makes those operations distinct.

Author:
Apache Directory Project
See Also:
Serialized Form

Constructor Summary
Csn(long timestamp, int changeCount, int replicaId, int operationNumber)
          Creates a new instance.
Csn(java.lang.String value)
          Creates a new instance of SimpleCSN from a String.
 
Method Summary
 int compareTo(Csn csn)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object o)
          Indicates whether some other object is "equal to" this one
 byte[] getBytes()
          Get the CSN as a byte array.
 int getChangeCount()
           
 int getOperationNumber()
           
 int getReplicaId()
           
 long getTimestamp()
           
 int hashCode()
          Returns a hash code value for the object.
static boolean isValid(java.lang.String value)
          Check if the given String is a valid CSN.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Csn

public Csn(long timestamp,
           int changeCount,
           int replicaId,
           int operationNumber)
Creates a new instance. This method should be used only for deserializing a CSN

Parameters:
timestamp - GMT timestamp of modification
changeCount - The operation increment
replicaId - Replica ID where modification occurred ([-_A-Za-z0-9]{1,16})
operationNumber - Operation number in a modification operation

Csn

public Csn(java.lang.String value)
    throws InvalidCSNException
Creates a new instance of SimpleCSN from a String. The string format must be : <timestamp> # <changeCount> # <replica ID> # <operation number>

Parameters:
value - The String containing the CSN
Throws:
InvalidCSNException
Method Detail

isValid

public static boolean isValid(java.lang.String value)
Check if the given String is a valid CSN.

Parameters:
value - The String to check
Returns:
true if the String is a valid CSN

getBytes

public byte[] getBytes()
Get the CSN as a byte array. The data are stored as : bytes 1 to 8 : timestamp, big-endian bytes 9 to 12 : change count, big endian bytes 13 to ... : ReplicaId

Returns:
A copy of the byte array representing theCSN

getTimestamp

public long getTimestamp()
Returns:
The timestamp

getChangeCount

public int getChangeCount()
Returns:
The changeCount

getReplicaId

public int getReplicaId()
Returns:
The replicaId

getOperationNumber

public int getOperationNumber()
Returns:
The operation number

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
Returns:
The CSN as a String

hashCode

public int hashCode()
Returns a hash code value for the object.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code value for this object.

equals

public boolean equals(java.lang.Object o)
Indicates whether some other object is "equal to" this one

Overrides:
equals in class java.lang.Object
Parameters:
o - the reference object with which to compare.
Returns:
true if this object is the same as the obj argument; false otherwise.

compareTo

public int compareTo(Csn csn)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface java.lang.Comparable<Csn>
Parameters:
o - the Object to be compared.
Returns:
a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.


Copyright © 2003-2011 Apache Software Foundation. All Rights Reserved.