Class ServerState
- java.lang.Object
-
- org.opends.server.replication.common.ServerState
-
-
Constructor Summary
Constructors Constructor Description ServerState()Creates a new empty ServerState.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Empty the ServerState.booleancover(CSN covered)Checks that the CSN given as a parameter is in this ServerState.booleancover(ServerState covered)Check that all the CSNs in the covered serverState are also in this serverState.static intdiffChanges(ServerState ss1, ServerState ss2)Computes the number of changes a first server state has in advance compared to a second server state.ServerStateduplicate()Make a duplicate of this state.CSNgetCSN(int serverId)Returns theCSNcontained in this server state which corresponds to the provided server ID.Map<Integer,CSN>getServerIdToCSNMap()Returns a copy of this ServerState's content as a Map of serverId => CSN.List<CSN>getSnapshot()Returns a snapshot of this object.booleanisEmpty()Tests if the state is empty.booleanisSaved()Get the saved status of this ServerState.Iterator<CSN>iterator()booleanremoveCSN(CSN expectedCSN)Removes the mapping to the provided CSN if it is present in this ServerState.voidsetSaved(boolean b)Set the saved status of this ServerState.ArrayList<ByteString>toASN1ArrayList()Return an ArrayList of ANS1OctetString encoding the CSNs contained in the ServerState.StringtoString()Return the text representation of ServerState.Set<String>toStringSet()Return a Set of String usable as a textual representation of a Server state.booleanupdate(CSN csn)Forward update the Server State with a CSN.booleanupdate(ServerState serverState)Update the Server State with a Server State.voidwriteTo(ASN1Writer writer, short protocolVersion)Encodes this server state to the provided ASN1 writer.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Method Detail
-
clear
public void clear()
Empty the ServerState. After this call the Server State no longer holds any CSN. A state which held one is marked as not saved: dropping it is a change like any other, which persistent storage has yet to be told about. A state which held nothing is left alone, the way an update which changes nothing is.
-
update
public boolean update(CSN csn)
Forward update the Server State with a CSN. The provided CSN will be put on the current object only if it is newer than the existing CSN for the same serverId or if there is no existing CSN.- Parameters:
csn- The committed CSN.- Returns:
- a boolean indicating if the update was meaningful.
-
update
public boolean update(ServerState serverState)
Update the Server State with a Server State. Every CSN of this object is updated with the CSN of the passed server state if it is newer.- Parameters:
serverState- the server state to use for the update.- Returns:
- a boolean indicating if the update was meaningful.
-
removeCSN
public boolean removeCSN(CSN expectedCSN)
Removes the mapping to the provided CSN if it is present in this ServerState.- Parameters:
expectedCSN- the CSN to be removed- Returns:
- true if the CSN could be removed, false otherwise.
-
toStringSet
public Set<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 ArrayList<ByteString> toASN1ArrayList()
Return an ArrayList of ANS1OctetString encoding the CSNs contained in the ServerState.- Returns:
- an ArrayList of ANS1OctetString encoding the CSNs contained in the ServerState.
-
writeTo
public void writeTo(ASN1Writer writer, short protocolVersion) throws IOException
Encodes this server state to the provided ASN1 writer.- Parameters:
writer- The ASN1 writer.protocolVersion- The replication protocol version.- Throws:
IOException- If an error occurred during encoding.
-
getSnapshot
public List<CSN> getSnapshot()
Returns a snapshot of this object.- Returns:
- an unmodifiable List representing a snapshot of this object.
-
toString
public String toString()
Return the text representation of ServerState.
-
getCSN
public CSN getCSN(int serverId)
Returns theCSNcontained in this server state which corresponds to the provided server ID.- Parameters:
serverId- The server ID.- Returns:
- The
CSNcontained in this server state which corresponds to the provided server ID.
-
getServerIdToCSNMap
public Map<Integer,CSN> getServerIdToCSNMap()
Returns a copy of this ServerState's content as a Map of serverId => CSN.- Returns:
- a copy of this ServerState's content as a Map of serverId => CSN.
-
cover
public boolean cover(ServerState covered)
Check that all the CSNs 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.
-
cover
public boolean cover(CSN covered)
Checks that the CSN given as a parameter is in this ServerState.- Parameters:
covered- The CSN that should be checked.- Returns:
- A boolean indicating if this ServerState contains the CSN 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.
-
diffChanges
public static int diffChanges(ServerState ss1, ServerState ss2) throws IllegalArgumentException
Computes the number of changes a first server state has in advance compared to a second server state.- Parameters:
ss1- The server state supposed to be newer than the second oness2- The server state supposed to be older than the first one- Returns:
- The difference of changes (sum of the differences for each server id changes). 0 If no gap between 2 states.
- Throws:
IllegalArgumentException- If one of the passed state is null
-
setSaved
public void setSaved(boolean b)
Set the saved status of this ServerState.- Parameters:
b- A boolean indicating if the State has been safely stored.
-
isSaved
public boolean isSaved()
Get the saved status of this ServerState.- Returns:
- The saved status of this ServerState.
-
-