org.multiverse.api.clock
Class SingleThreadedPrimitiveClock

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

public final class SingleThreadedPrimitiveClock
extends java.lang.Object
implements PrimitiveClock

A PrimitiveClock implementation that can be used in a single thread environment. It is useful if you want to use the atomic behavior of the stm but don't need it to be thread-safe.

Another purpose of this PrimitiveClock is for benchmarking; to see what to overhead of an AtomicLong in a single threaded environment is.

Author:
Peter Veentjer.

Constructor Summary
SingleThreadedPrimitiveClock()
           
 
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)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SingleThreadedPrimitiveClock

public SingleThreadedPrimitiveClock()
Method Detail

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()

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()

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.

tickTo

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

toString

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


Copyright © 2008-2010 Multiverse. All Rights Reserved.