org.multiverse.api.clock
Class StrictPrimitiveClock

java.lang.Object
  extended by org.multiverse.api.clock.StrictPrimitiveClock
All Implemented Interfaces:
PrimitiveClock

public final class StrictPrimitiveClock
extends Object
implements PrimitiveClock

The intuitive implementation of a PrimitiveClock. It wraps an AtomicLong and increases the value every time a tick is done.

A strict clock provides a full ordering of all transactions (also transactions that don't share state). This full ordering can cause a lot of contention on the memory bus. See the RelaxedPrimitiveClock for more info.

A StrictPrimitiveClock is thread-safe.

Reading the version is very cheap (even though a volatile read needs to be executed).

Author:
Peter Veentjer.

Constructor Summary
StrictPrimitiveClock()
          Creates a new StrictPrimitiveClock.
StrictPrimitiveClock(long time)
          Creates a new StrictPrimitiveClock initialized with the provided time.
 
Method Summary
 long getVersion()
          Returns the current version of this PrimitiveClock.
 long strictTick()
          Executes a strict clock tick by increasing the version.
 long tick()
          Executes a clock tick by increasing the version.
 long tickTo(long version)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StrictPrimitiveClock

public StrictPrimitiveClock()
Creates a new StrictPrimitiveClock.


StrictPrimitiveClock

public StrictPrimitiveClock(long time)
Creates a new StrictPrimitiveClock initialized with the provided time.

Parameters:
time - the initial time of the clock
Throws:
IllegalArgumentException - if time smaller than 0.
Method Detail

strictTick

public long strictTick()
Description copied from interface: PrimitiveClock
Executes a strict clock tick by increasing the version. The big difference between the strictTick() and the PrimitiveClock.tick() is that the former will always increase the version for every calling thread and the is allowed to return the same version for concurrent ticks.

The returned value could be stale as soon as it is received.

Specified by:
strictTick in interface PrimitiveClock
Returns:
the time after the tick.
See Also:
PrimitiveClock.tick()

tick

public long tick()
Description copied from interface: PrimitiveClock
Executes a clock tick by increasing the version. The returned value will always be bigger than the current version. Once the tick method completes, the PrimitiveClock.getVersion() method will always return a time equal or larger than.the last tick.

The returned value could be stale as soon as it is received.

Specified by:
tick in interface PrimitiveClock
Returns:
the time after the tick.
See Also:
PrimitiveClock.strictTick()

tickTo

public long tickTo(long version)
Specified by:
tickTo in interface PrimitiveClock

getVersion

public long getVersion()
Description copied from interface: PrimitiveClock
Returns the current version of this PrimitiveClock.

The returned value could be stale as soon as it is received.

Specified by:
getVersion in interface PrimitiveClock
Returns:
the current version.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2008-2010 Multiverse. All Rights Reserved.