com.gilt.gfc.time

MonotonicClock

trait MonotonicClock extends AnyRef

Defines a clock which has essentially millisecond accuracy, but which returns times in nanoseconds so that it can include a monotonically-increasing counter so that this clock will never return the same time twice.

Note that if you take currentTimeNanos / 1000000, you'll get the value returned from currentTimeMillis(), guaranteed.

The purpose of this clock is not really to measure time. Instead, you should think of it as something like a database sequence that includes some help data about when the value was generated. It's trying to work around the situation where we'd really like to use System.currentTimeMillis(), but we need every call to return a unique value.

If the system clock moves backwards, the instance will hold on to the highest value it has seen. Each time it is called, it increments a counter, and has enough room for essentially 1M calls against it without the clock moving forward, before it can no longer guarantee that it is returning a unique value. So this is likely to be fine unless the clock moves so far back in time, and the frequency of calls against the clock is so high, that it cannot catch up. In that case the clock will throw an exception.

Note that this clock will stop working at Sat Apr 12 00:47:16 IST 2262. If Gilt is still a viable venture 250 years from now, and still depending on this code, accept my humble apologies. :)

Linear Supertypes
AnyRef, Any
Known Subclasses
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. Hide All
  2. Show all
  1. MonotonicClock
  2. AnyRef
  3. Any
Visibility
  1. Public
  2. All

Value Members

  1. final def !=(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  2. final def !=(arg0: Any): Boolean

    Definition Classes
    Any
  3. final def ##(): Int

    Definition Classes
    AnyRef → Any
  4. final def ==(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  5. final def ==(arg0: Any): Boolean

    Definition Classes
    Any
  6. final def asInstanceOf[T0]: T0

    Definition Classes
    Any
  7. def clone(): AnyRef

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  8. def currentTimeNanos(): Long

  9. final def eq(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  10. def equals(arg0: Any): Boolean

    Definition Classes
    AnyRef → Any
  11. def finalize(): Unit

    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws()
  12. final def getClass(): java.lang.Class[_]

    Definition Classes
    AnyRef → Any
  13. def hashCode(): Int

    Definition Classes
    AnyRef → Any
  14. final def isInstanceOf[T0]: Boolean

    Definition Classes
    Any
  15. def millisecondClock(): Long

  16. final def ne(arg0: AnyRef): Boolean

    Definition Classes
    AnyRef
  17. final def notify(): Unit

    Definition Classes
    AnyRef
  18. final def notifyAll(): Unit

    Definition Classes
    AnyRef
  19. final def synchronized[T0](arg0: ⇒ T0): T0

    Definition Classes
    AnyRef
  20. def toString(): String

    Definition Classes
    AnyRef → Any
  21. final def wait(): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  22. final def wait(arg0: Long, arg1: Int): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()
  23. final def wait(arg0: Long): Unit

    Definition Classes
    AnyRef
    Annotations
    @throws()

Inherited from AnyRef

Inherited from Any