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
-
LogicalClock(byte[])
- CONSTRUCTOR: creates a new logical clock using an array of bytes to
determine the relevant fields.
-
LogicalClock(double)
-
CONSTRUCTOR
-
commit()
-
MUTATOR: commits this clock as accurate
-
is_committed()
-
ACCESSOR: tests whether this clock is accurate or not.
-
is_valid()
-
ACCESSOR: tests whether this clock can be used or not
-
offset()
-
ACCESSOR: returns the offset of the logical clock with respect to
system clock.
-
precision()
-
ACCESSOR: Returns the current precision of this logical clock.
-
precision(long)
-
ACCESSOR: Returns the precision of this logical clock at a given time.
-
set(long, long)
-
MUTATOR: Sets the current value and precision of this logical clock.
-
set(long, long, long)
-
MUTATOR: Sets the value and precision of this logical clock
at a given time.
-
toBytes()
-
ACCESSOR: encodes the relevant variables into a new byte array.
-
toString()
- ACCESSOR: this is mainly for testing purpose
-
value()
-
ACCESSOR: Returns the current value of this logical clock.
-
value(long)
-
ACCESSOR: Returns the value of this logical clock at a given time.
LogicalClock
public LogicalClock(double r)
- CONSTRUCTOR
- Parameters:
- r - is the maximum drift (rho) in [arts per million
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
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
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
commit
public void commit()
- MUTATOR: commits this clock as accurate
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
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)
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)
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
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)
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)
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)
toBytes
public synchronized byte[] toBytes()
- ACCESSOR: encodes the relevant variables into a new byte array.
- Returns:
- a new byte array
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