public enum LogicalClock extends Enum<LogicalClock>
A logical update clock that has two states, Updating and Idle.
Each time LogicalClock.startUpdateCycle()
is called, the clock transitions to the Updating state
and the current value
is incremented by one.
When LogicalClock.completeUpdateCycle()
is called, the clock transitions back to Idle.
Modifier and Type | Class and Description |
---|---|
static class |
LogicalClock.State
The state component of a logical timestamp.
|
Enum Constant and Description |
---|
DEFAULT |
Modifier and Type | Method and Description |
---|---|
void |
completeUpdateCycle()
Increment the current step and set the clock state to
idle . |
LogicalClock.State |
currentState()
Get the current clock state.
|
long |
currentStep()
Get the current Step of the clock.
|
long |
currentValue()
Get the current value of the clock.
|
void |
ensureUpdateCycleCompleted(long updatingCycleValue)
After we complete a table refresh, we must ensure that the logical clock is idle.
|
static LogicalClock.State |
getState(long value)
Get the
LogicalClock.State of the LogicalClock for a particular clock value. |
static long |
getStep(long value)
Get the clock step for the input clock value.
|
void |
resetForUnitTests()
Reset the clock to its initial state, in order to ensure that unit tests proceed cleanly.
|
long |
startUpdateCycle()
Increment the current value and set the clock state to
updating . |
static LogicalClock |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static LogicalClock[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final LogicalClock DEFAULT
public static LogicalClock[] values()
for (LogicalClock c : LogicalClock.values()) System.out.println(c);
public static LogicalClock valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static long getStep(long value)
start
- end
cycle.value
- The clock value to get the step forpublic static LogicalClock.State getState(long value)
LogicalClock.State
of the LogicalClock for a particular clock value.value
- The clock valuepublic final long currentValue()
public final long currentStep()
LogicalClock.getStep(long)
public final LogicalClock.State currentState()
LogicalClock.getState(long)
public final long startUpdateCycle()
updating
.idle
before this method is called.public final void completeUpdateCycle()
idle
.updating
before this method is called.public final void ensureUpdateCycleCompleted(long updatingCycleValue)
The only valid possibilities are (1) we have completed the cycle, in which case we return; or (2) we have terminated the cycle early and have the same value as at the start of our updating cycle, in which case we complete the cycle.
If our clock is any other value; then it was changed out from under us and we throw an exception.
updatingCycleValue
- the clock value at the end of LogicalClock.startUpdateCycle()
@TestUseOnly public final void resetForUnitTests()