/** * Sets the current timestamp. * * @param timestamp the updated timestamp * @return the current timestamp */ public long setTimestamp(long timestamp) { this.currentTimestamp = timestamp; service.tick(WallClockTimestamp.from(timestamp)); return currentTimestamp; }
/** * Resets the current index to the given index and timestamp. * * @param index the index to which to reset the current index * @param timestamp the timestamp to which to reset the current timestamp */ public void resetIndex(long index, long timestamp) { currentOperation = OperationType.COMMAND; operationIndex = index; currentIndex = index; currentTimestamp = timestamp; setCommitIndex(index); service.tick(new WallClockTimestamp(currentTimestamp)); }
/** * Executes scheduled callbacks based on the provided time. */ private void tick(long index, long timestamp) { this.currentIndex = index; // If the entry timestamp is less than the current state machine timestamp // and the delta is not yet set, set the delta and do not change the current timestamp. // If the entry timestamp is less than the current state machine timestamp // and the delta is set, update the current timestamp to the entry timestamp plus the delta. // If the entry timestamp is greater than or equal to the current timestamp, update the current // timestamp and reset the delta. if (timestamp < currentTimestamp) { if (timestampDelta == 0) { timestampDelta = currentTimestamp - timestamp; } else { currentTimestamp = timestamp + timestampDelta; } } else { currentTimestamp = timestamp; timestampDelta = 0; } // Set the current operation type to COMMAND to allow events to be sent. setOperation(OperationType.COMMAND); service.tick(WallClockTimestamp.from(timestamp)); }