Oracle® Coherence Java API Reference
v3.5.3

E15583-01

com.tangosol.util
Class SafeClock

java.lang.Object
  extended by com.tangosol.util.SafeClock

public class SafeClock
extends java.lang.Object

SafeClock maintains a "safe" time in milliseconds.

Unlike the System.currentTimeMillis() this clock guarantees that the time never "goes back". More specifically, when queried twice on the same thread, the second query will never return a value that is less then the value returned by the first.

If we detect the system clock moving backward, an attempt will be made to gradually compensate the safe clock (by slowing it down), so in the long run the safe time is the same as the system time.

The SafeClock supports the concept of "clock jitter", which is a small time interval that the system clock could fluctuate by without a corresponding passage of wall time.

Since:
Coherence 3.6
Author:
mf 2009.12.09

Field Summary
static long DEFAULT_JITTER_THRESHOLD
          The default jitter threshold.
protected  long m_ldtLastSafe
          The last known safe time value.
protected  long m_ldtLastUnsafe
          The last recorded unsafe time value.
protected  long m_lJitter
          The maximum expected jitter exposed by the underlying unsafe clock.
 
Constructor Summary
SafeClock()
          Create a new SafeClock with the default maximum expected jitter as specified by the "tangosol.coherence.safeclock.jitter" system property.
SafeClock(long lJitter)
          Create a new SafeClock with the specified jitter threshold.
 
Method Summary
 long getLastSafeTimeMillis()
          Returns the last "safe" time as computed by a previous call to the getSafeTimeMillis() method.
 long getSafeTimeMillis()
          Returns a "safe" current time in milliseconds.
protected  long getUnsafeTimeMillis()
          Return the current unsafe time.
protected  long updateSafeTimeMillis(long ldtUnsafe)
          Updates and returns a "safe" current time in milliseconds based on the "unsafe" time.
 

Field Detail

m_ldtLastSafe

protected long m_ldtLastSafe
The last known safe time value.


m_ldtLastUnsafe

protected long m_ldtLastUnsafe
The last recorded unsafe time value.


m_lJitter

protected long m_lJitter
The maximum expected jitter exposed by the underlying unsafe clock.


DEFAULT_JITTER_THRESHOLD

public static final long DEFAULT_JITTER_THRESHOLD
The default jitter threshold.

Constructor Detail

SafeClock

public SafeClock()
Create a new SafeClock with the default maximum expected jitter as specified by the "tangosol.coherence.safeclock.jitter" system property.


SafeClock

public SafeClock(long lJitter)
Create a new SafeClock with the specified jitter threshold.

Parameters:
lJitter - the maximum expected jitter in the underlying system clock
Method Detail

getSafeTimeMillis

public long getSafeTimeMillis()
Returns a "safe" current time in milliseconds.

Returns:
the difference, measured in milliseconds, between the corrected current time and midnight, January 1, 1970 UTC.

getLastSafeTimeMillis

public long getLastSafeTimeMillis()
Returns the last "safe" time as computed by a previous call to the getSafeTimeMillis() method.

Note: Since the underlying field is non-volatile, the returned value is only guaranteed to be no less than the last value returned by getSafeTimeMillis() call on the same thread.

Returns:
the last "safe" time in milliseconds

getUnsafeTimeMillis

protected long getUnsafeTimeMillis()
Return the current unsafe time.

Returns:
the current unsafe time in milliseconds

updateSafeTimeMillis

protected long updateSafeTimeMillis(long ldtUnsafe)
Updates and returns a "safe" current time in milliseconds based on the "unsafe" time.

Parameters:
ldtUnsafe - the unsafe current time in milliseconds
Returns:
the corrected safe time

Oracle® Coherence Java API Reference
v3.5.3

E15583-01

Copyright © 2000, 2010, Oracle. All rights reserved.