All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class syd.logicalclock.LogicalClock

java.lang.Object
   |
   +----syd.logicalclock.LogicalClock

public class LogicalClock
extends Object
Real times are all expressed as long integer values, one unit corresponding to one millisecond, according with java APIs that allow a granularity of 1 millisecond.

IMPORTANT: this object is built to be "multiple readers, single writer". The only Accessor that can be reliably operated by several partners is the toBytes and is presently the only synchronized method. The chances that its operation slows the other operations is considered negligible: otherwise, the "origin" field could be used as a timestamp to abort this operation without requiring a the synchronized operation: checking the value before of this fiels before and after the construction of the byte array one understands if other values were updated. The toString is non reentrant.

See Also:
toString, toBytes

Constructor Index

 o LogicalClock(byte[])
CONSTRUCTOR: creates a new logical clock using an array of bytes to determine the relevant fields.
 o LogicalClock(double)
CONSTRUCTOR

Method Index

 o commit()
MUTATOR: commits this clock as accurate
 o is_committed()
ACCESSOR: tests whether this clock is accurate or not.
 o is_valid()
ACCESSOR: tests whether this clock can be used or not
 o offset()
ACCESSOR: returns the offset of the logical clock with respect to system clock.
 o precision()
ACCESSOR: Returns the current precision of this logical clock.
 o precision(long)
ACCESSOR: Returns the precision of this logical clock at a given time.
 o set(long, long)
MUTATOR: Sets the current value and precision of this logical clock.
 o set(long, long, long)
MUTATOR: Sets the value and precision of this logical clock at a given time.
 o toBytes()
ACCESSOR: encodes the relevant variables into a new byte array.
 o toString()
ACCESSOR: this is mainly for testing purpose
 o value()
ACCESSOR: Returns the current value of this logical clock.
 o value(long)
ACCESSOR: Returns the value of this logical clock at a given time.

Constructors

 o LogicalClock
 public LogicalClock(double r)
CONSTRUCTOR

Parameters:
r - is the maximum drift (rho) in [arts per million
 o LogicalClock
 public LogicalClock(byte packet[])
CONSTRUCTOR: creates a new logical clock using an array of bytes to determine the relevant fields.

Parameters:
packet - the byte array that encodes the internal state;
Returns:
a new LogicalClock

Methods

 o offset
 public long offset()
ACCESSOR: returns the offset of the logical clock with respect to system clock.

Returns:
the difference from the logical clock and the system clock
 o is_valid
 public boolean is_valid()
ACCESSOR: tests whether this clock can be used or not

Returns:
a boolean that is true if the clock is valid
 o commit
 public void commit()
MUTATOR: commits this clock as accurate

 o is_committed
 public boolean is_committed()
ACCESSOR: tests whether this clock is accurate or not.

Returns:
a boolean that is true if the clock is within the tolerance
 o value
 public long value() throws LogicalClockException
ACCESSOR: Returns the current value of this logical clock.

Returns:
a long that represents the logical clock in millisecs (Java)
 o precision
 public long precision() throws LogicalClockException
ACCESSOR: Returns the current precision of this logical clock.

Returns:
a long that represents the estimated error (in millisecs)
 o set
 public void set(long v,
                 long p)
MUTATOR: Sets the current value and precision of this logical clock.

Parameters:
v - the current time in millisecs (Java)
p - the estimated precision in millisecs
 o value
 public long value(long when) throws LogicalClockException
ACCESSOR: Returns the value of this logical clock at a given time.

Parameters:
when - the baseline (computed on the system clock)
Returns:
a long that represents the logical clock in millisecs (Java)
 o precision
 public long precision(long when) throws LogicalClockException
ACCESSOR: Returns the precision of this logical clock at a given time.

Parameters:
when - the baseline (computed on the system clock)
Returns:
a long that represents the estimated error (in millisecs)
 o set
 public synchronized void set(long v,
                              long p,
                              long when)
MUTATOR: Sets the value and precision of this logical clock at a given time.

Parameters:
v - the time in millisecs (Java)
p - the estimated precision in millisecs
when - the baseline (computed on the system clock)
 o toBytes
 public synchronized byte[] toBytes()
ACCESSOR: encodes the relevant variables into a new byte array.

Returns:
a new byte array
 o toString
 public String toString()
ACCESSOR: this is mainly for testing purpose

Overrides:
toString in class Object

All Packages  Class Hierarchy  This Package  Previous  Next  Index