org.sdnplatform.sync.internal.version
Class VectorClock

java.lang.Object
  extended by org.sdnplatform.sync.internal.version.VectorClock
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, IVersion

public class VectorClock
extends java.lang.Object
implements IVersion, java.io.Serializable, java.lang.Cloneable

A vector of the number of writes mastered by each node. The vector is stored sparely, since, in general, writes will be mastered by only one node. This means implicitly all the versions are at zero, but we only actually store those greater than zero.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.sdnplatform.sync.IVersion
IVersion.Occurred
 
Constructor Summary
VectorClock()
          Construct an empty VectorClock
VectorClock(java.util.List<ClockEntry> versions, long timestamp)
          Create a VectorClock with the given version and timestamp
VectorClock(long timestamp)
           
 
Method Summary
 VectorClock clone()
           
 IVersion.Occurred compare(IVersion v)
          Return whether or not the given version preceeded this one, succeeded it, or is concurrant with it
static IVersion.Occurred compare(VectorClock v1, VectorClock v2)
          Is this Reflexive, AntiSymetic, and Transitive? Compare two VectorClocks, the outcomes will be one of the following: -- Clock 1 is BEFORE clock 2 if there exists an i such that c1(i) <= c(2) and there does not exist a j such that c1(j) > c2(j).
 boolean equals(java.lang.Object obj)
           
 java.util.List<ClockEntry> getEntries()
           
 long getMaxVersion()
           
 long getTimestamp()
           
 int hashCode()
           
 VectorClock incremented(int nodeId, long time)
          Get new vector clock based on this clock but incremented on index nodeId
 VectorClock merge(VectorClock clock)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

VectorClock

public VectorClock()
Construct an empty VectorClock


VectorClock

public VectorClock(long timestamp)

VectorClock

public VectorClock(java.util.List<ClockEntry> versions,
                   long timestamp)
Create a VectorClock with the given version and timestamp

Parameters:
versions - The version to prepopulate
timestamp - The timestamp to prepopulate
Method Detail

incremented

public VectorClock incremented(int nodeId,
                               long time)
Get new vector clock based on this clock but incremented on index nodeId

Parameters:
nodeId - The id of the node to increment
Returns:
A vector clock equal on each element execept that indexed by nodeId

clone

public VectorClock clone()
Overrides:
clone in class java.lang.Object

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getMaxVersion

public long getMaxVersion()

merge

public VectorClock merge(VectorClock clock)

compare

public IVersion.Occurred compare(IVersion v)
Description copied from interface: IVersion
Return whether or not the given version preceeded this one, succeeded it, or is concurrant with it

Specified by:
compare in interface IVersion
Parameters:
v - The other version

compare

public static IVersion.Occurred compare(VectorClock v1,
                                        VectorClock v2)
Is this Reflexive, AntiSymetic, and Transitive? Compare two VectorClocks, the outcomes will be one of the following: -- Clock 1 is BEFORE clock 2 if there exists an i such that c1(i) <= c(2) and there does not exist a j such that c1(j) > c2(j). -- Clock 1 is CONCURRENT to clock 2 if there exists an i, j such that c1(i) < c2(i) and c1(j) > c2(j) -- Clock 1 is AFTER clock 2 otherwise

Parameters:
v1 - The first VectorClock
v2 - The second VectorClock

getTimestamp

public long getTimestamp()

getEntries

public java.util.List<ClockEntry> getEntries()