Package org.apache.jackrabbit.oak.stats
Class Clock
- java.lang.Object
 - 
- java.time.Clock
 - 
- org.apache.jackrabbit.oak.stats.Clock
 
 
 
- 
- Direct Known Subclasses:
 Clock.Fast,Clock.Virtual
public abstract class Clock extends java.time.ClockMechanism for keeping track of time at millisecond accuracy.As of Oak 1.20, this extends from
Clock. 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classClock.FastFast clock implementation whoseClock.Fast.getTime()method returns instantaneously thanks to a background task that takes care of the actual time-keeping work.static classClock.VirtualA virtual clock that has no connection to the actual system time. 
- 
Field Summary
Fields Modifier and Type Field Description static ClockACCURATEAccurate clock implementation that uses interval timings from theSystem.nanoTime()method to calculate an as accurate as possible time based on occasional calls toSystem.currentTimeMillis()to prevent clock drift.static ClockSIMPLESimple clock implementation based onSystem.currentTimeMillis(), which is known to be rather slow on some platforms. 
- 
Constructor Summary
Constructors Constructor Description Clock() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description java.util.DategetDate()Convenience method that returns thegetTime()value as aDateinstance.java.util.DategetDateIncreasing()Convenience method that returns thegetTimeIncreasing()value as aDateinstance.java.util.DategetDateMonotonic()Convenience method that returns thegetTimeMonotonic()value as aDateinstance.abstract longgetTime()Returns the current time in milliseconds since the epoch.longgetTimeIncreasing()Returns a strictly increasing timestamp based on the current time.longgetTimeMonotonic()Returns a monotonically increasing timestamp based on the current time.java.time.ZoneIdgetZone()java.time.Instantinstant()voidwaitUntil(long timestamp)Waits until the given point in time is reached.java.time.ClockwithZone(java.time.ZoneId zone) 
 - 
 
- 
- 
Field Detail
- 
SIMPLE
public static Clock SIMPLE
Simple clock implementation based onSystem.currentTimeMillis(), which is known to be rather slow on some platforms. 
- 
ACCURATE
public static Clock ACCURATE
Accurate clock implementation that uses interval timings from theSystem.nanoTime()method to calculate an as accurate as possible time based on occasional calls toSystem.currentTimeMillis()to prevent clock drift. 
 - 
 
- 
Method Detail
- 
getTime
public abstract long getTime()
Returns the current time in milliseconds since the epoch.- Returns:
 - current time in milliseconds since the epoch
 - See Also:
 System.currentTimeMillis(),Clock.millis()
 
- 
getTimeMonotonic
public long getTimeMonotonic()
Returns a monotonically increasing timestamp based on the current time. A call to this method will always return a value that is greater than or equal to a value returned by any previous call. This contract holds even across multiple threads and in cases when the system time is adjusted backwards. In the latter case the returned value will remain constant until the previously reported timestamp is again reached.- Returns:
 - monotonically increasing timestamp
 
 
- 
getTimeIncreasing
public long getTimeIncreasing() throws java.lang.InterruptedExceptionReturns a strictly increasing timestamp based on the current time. This method is likegetTimeMonotonic(), with the exception that two calls of this method will never return the same timestamp. Instead this method will explicitly wait until the current time increases beyond any previously returned value. Note that the wait may last long if this method is called frequently from many concurrent thread or if the system time is adjusted backwards. The caller should be prepared to deal with an explicit interrupt in such cases.- Returns:
 - strictly increasing timestamp
 - Throws:
 java.lang.InterruptedException- if the wait was interrupted
 
- 
getDate
public java.util.Date getDate()
Convenience method that returns thegetTime()value as aDateinstance.- Returns:
 - current time
 
 
- 
getDateMonotonic
public java.util.Date getDateMonotonic()
Convenience method that returns thegetTimeMonotonic()value as aDateinstance.- Returns:
 - monotonically increasing time
 
 
- 
getDateIncreasing
public java.util.Date getDateIncreasing() throws java.lang.InterruptedExceptionConvenience method that returns thegetTimeIncreasing()value as aDateinstance.- Returns:
 - strictly increasing time
 - Throws:
 java.lang.InterruptedException
 
- 
waitUntil
public void waitUntil(long timestamp) throws java.lang.InterruptedExceptionWaits until the given point in time is reached. The current thread is suspended until thegetTimeIncreasing()method returns a time that's equal or greater than the given point in time.- Parameters:
 timestamp- time in milliseconds since epoch- Throws:
 java.lang.InterruptedException- if the wait was interrupted
 
- 
getZone
public java.time.ZoneId getZone()
- Specified by:
 getZonein classjava.time.Clock
 
- 
instant
public java.time.Instant instant()
- Specified by:
 instantin classjava.time.Clock
 
- 
withZone
public java.time.Clock withZone(java.time.ZoneId zone)
- Specified by:
 withZonein classjava.time.Clock
 
 - 
 
 -