org.opends.server.replication.common
Class ServerState

java.lang.Object
  extended by org.opends.server.replication.common.ServerState
All Implemented Interfaces:
java.lang.Iterable<java.lang.Short>
Direct Known Subclasses:
PersistentServerState

public class ServerState
extends java.lang.Object
implements java.lang.Iterable<java.lang.Short>

ServerState class. This object is used to store the last update seen on this server from each server. It is exchanged with the replication servers at connection establishment time.


Constructor Summary
ServerState()
          Creates a new empty ServerState.
ServerState(byte[] in, int pos, int endpos)
          Creates a new ServerState object from its encoded form.
 
Method Summary
 void clear()
          Empty the ServerState.
 boolean cover(ServerState covered)
          Check that all the ChangeNumbers in the covered serverState are also in this serverState.
 ServerState duplicate()
          Make a duplicate of this state.
 byte[] getBytes()
          Encode this ServerState object and return its byte array representation.
 ChangeNumber getMaxChangeNumber(short serverId)
          Get the largest ChangeNumber seen for a given LDAP server ID.
 boolean isEmpty()
          Tests if the state is empty.
 java.util.Iterator<java.lang.Short> iterator()
          
 java.util.ArrayList<ASN1OctetString> toASN1ArrayList()
          Return an ArrayList of ANS1OctetString encoding the ChangeNumbers contained in the ServerState.
 java.lang.String toString()
          Return the text representation of ServerState.
 java.util.Set<java.lang.String> toStringSet()
          return a Set of String usable as a textual representation of a Server state.
 boolean update(ChangeNumber changeNumber)
          Update the Server State with a ChangeNumber.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ServerState

public ServerState()
Creates a new empty ServerState.


ServerState

public ServerState(byte[] in,
                   int pos,
                   int endpos)
            throws java.util.zip.DataFormatException
Creates a new ServerState object from its encoded form.

Parameters:
in - The byte array containing the encoded ServerState form.
pos - The position in the byte array where the encoded ServerState starts.
endpos - The position in the byte array where the encoded ServerState ends.
Throws:
java.util.zip.DataFormatException - If the encoded form was not correct.
Method Detail

clear

public void clear()
Empty the ServerState. After this call the Server State will be in the same state as if it was just created.


update

public boolean update(ChangeNumber changeNumber)
Update the Server State with a ChangeNumber. All operations with smaller CSN and the same serverID must be committed before calling this method.

Parameters:
changeNumber - the committed ChangeNumber.
Returns:
a boolean indicating if the update was meaningfull.

toStringSet

public java.util.Set<java.lang.String> toStringSet()
return a Set of String usable as a textual representation of a Server state. format : time seqnum id example : 1 00000109e4666da600220001 2 00000109e44567a600220002

Returns:
the representation of the Server state

toASN1ArrayList

public java.util.ArrayList<ASN1OctetString> toASN1ArrayList()
Return an ArrayList of ANS1OctetString encoding the ChangeNumbers contained in the ServerState.

Returns:
an ArrayList of ANS1OctetString encoding the ChangeNumbers contained in the ServerState.

toString

public java.lang.String toString()
Return the text representation of ServerState.

Overrides:
toString in class java.lang.Object
Returns:
the text representation of ServerState

getMaxChangeNumber

public ChangeNumber getMaxChangeNumber(short serverId)
Get the largest ChangeNumber seen for a given LDAP server ID.

Parameters:
serverId - : the server ID
Returns:
the largest ChangeNumber seen

getBytes

public byte[] getBytes()
                throws java.io.UnsupportedEncodingException
Encode this ServerState object and return its byte array representation.

Returns:
a byte array with an encoded representation of this object.
Throws:
java.io.UnsupportedEncodingException - if UTF8 is not supported by the JVM.

iterator

public java.util.Iterator<java.lang.Short> iterator()

Specified by:
iterator in interface java.lang.Iterable<java.lang.Short>

cover

public boolean cover(ServerState covered)
Check that all the ChangeNumbers in the covered serverState are also in this serverState.

Parameters:
covered - The ServerState that needs to be checked.
Returns:
A boolean indicating if this ServerState covers the ServerState given in parameter.

isEmpty

public boolean isEmpty()
Tests if the state is empty.

Returns:
True if the state is empty.

duplicate

public ServerState duplicate()
Make a duplicate of this state.

Returns:
The duplicate of this state.