Class SafeClock
SafeClock maintains a "safe" time in milliseconds.
Inherited Members
Namespace: Tangosol.Util
Assembly: Coherence.dll
Syntax
public class SafeClock
Remarks
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.
Constructors
SafeClock(long)
Create a new SafeClock with the default maximum expected jitter.
Declaration
public SafeClock(long ldtUnsafe)
Parameters
Type | Name | Description |
---|---|---|
long | ldtUnsafe | The current unsafe time |
SafeClock(long, long)
Create a new SafeClock with the specified jitter threshold.
Declaration
public SafeClock(long ldtUnsafe, long lJitter)
Parameters
Type | Name | Description |
---|---|---|
long | ldtUnsafe | The current unsafe time |
long | lJitter | The maximum expected jitter in the underlying system clock |
Fields
DEFAULT_JITTER_THRESHOLD
The default jitter threshold.
Declaration
public static readonly long DEFAULT_JITTER_THRESHOLD
Field Value
Type | Description |
---|---|
long |
m_lJitter
The maximum expected jitter exposed by the underlying unsafe clock.
Declaration
protected readonly long m_lJitter
Field Value
Type | Description |
---|---|
long |
m_ldtLastSafe
The last known safe time value.
Declaration
protected long m_ldtLastSafe
Field Value
Type | Description |
---|---|
long |
m_ldtLastUnsafe
The last recorded unsafe time value.
Declaration
protected long m_ldtLastUnsafe
Field Value
Type | Description |
---|---|
long |
Methods
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.
Declaration
public long GetLastSafeTimeMillis()
Returns
Type | Description |
---|---|
long | The last "safe" time in milliseconds. |
GetSafeTimeMillis(long)
Returns a "safe" current time in milliseconds.
Declaration
public long GetSafeTimeMillis(long ldtUnsafe)
Parameters
Type | Name | Description |
---|---|---|
long | ldtUnsafe | The current unsafe time |
Returns
Type | Description |
---|---|
long | The difference, measured in milliseconds, between the corrected current time and midnight, January 1, 0001. |
UpdateSafeTimeMillis(long)
Updates and returns a "safe" current time in milliseconds based on the "unsafe" time.
Declaration
protected long UpdateSafeTimeMillis(long ldtUnsafe)
Parameters
Type | Name | Description |
---|---|---|
long | ldtUnsafe | The unsafe current time in milliseconds. |
Returns
Type | Description |
---|---|
long | The corrected safe time. |