trait
MonotonicClock extends AnyRef
Value Members
-
final
def
!=(arg0: AnyRef): Boolean
-
final
def
!=(arg0: Any): Boolean
-
final
def
##(): Int
-
final
def
==(arg0: AnyRef): Boolean
-
final
def
==(arg0: Any): Boolean
-
final
def
asInstanceOf[T0]: T0
-
def
clone(): AnyRef
-
def
currentTimeNanos(): Long
-
final
def
eq(arg0: AnyRef): Boolean
-
def
equals(arg0: Any): Boolean
-
def
finalize(): Unit
-
final
def
getClass(): java.lang.Class[_]
-
def
hashCode(): Int
-
final
def
isInstanceOf[T0]: Boolean
-
def
millisecondClock(): Long
-
final
def
ne(arg0: AnyRef): Boolean
-
final
def
notify(): Unit
-
final
def
notifyAll(): Unit
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
-
def
toString(): String
-
final
def
wait(): Unit
-
final
def
wait(arg0: Long, arg1: Int): Unit
-
final
def
wait(arg0: Long): Unit
Inherited from AnyRef
Inherited from Any
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. :)