protected static final void waitTillNext(long seconds) { TimeUtil.tillNextMillis(TimeUtil.timeGen() + seconds * 1000); } }
public synchronized long nextId() { long timestamp = TimeUtil.timeGen(); if (timestamp > this.lastTimestamp) { this.sequence = 0L; } else if (timestamp == this.lastTimestamp) { this.sequence = (this.sequence + 1) & SEQUENCE_MASK; if (this.sequence == 0) { timestamp = TimeUtil.tillNextMillis(this.lastTimestamp); } } else { assert timestamp < this.lastTimestamp; LOG.error("Clock is moving backwards, " + "rejecting requests until {}.", this.lastTimestamp); throw new HugeException("Clock moved backwards. Refusing to " + "generate id for %d milliseconds", this.lastTimestamp - timestamp); } this.lastTimestamp = timestamp; return (timestamp << TIMESTAMP_SHIFT) | (this.datacenterId << DC_SHIFT) | (this.workerId << WORKER_SHIFT) | (this.sequence); } }
public synchronized long nextId() { long timestamp = TimeUtil.timeGen(); if (timestamp > this.lastTimestamp) { this.sequence = 0L; } else if (timestamp == this.lastTimestamp) { this.sequence = (this.sequence + 1) & SEQUENCE_MASK; if (this.sequence == 0) { timestamp = TimeUtil.tillNextMillis(this.lastTimestamp); } } else { assert timestamp < this.lastTimestamp; LOG.error("Clock is moving backwards, " + "rejecting requests until {}.", this.lastTimestamp); throw new HugeException("Clock moved backwards. Refusing to " + "generate id for %d milliseconds", this.lastTimestamp - timestamp); } this.lastTimestamp = timestamp; return (timestamp << TIMESTAMP_SHIFT) | (this.datacenterId << DC_SHIFT) | (this.workerId << WORKER_SHIFT) | (this.sequence); } }