X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.uuid%2Fsrc%2Forg%2Fargeo%2Fapi%2Fuuid%2FConcurrentTimeUuidState.java;h=25ba62b03ba4d7224bcc8ec3326838a68b95b9ce;hb=5f820a14abf7371714514ed5f20580ceb5edaeec;hp=61f5b8304d3710713a500fa2fc7347ec81ae07c6;hpb=475dc8545eb01b541c63be6a480fdd8d808e75a4;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api.uuid/src/org/argeo/api/uuid/ConcurrentTimeUuidState.java b/org.argeo.api.uuid/src/org/argeo/api/uuid/ConcurrentTimeUuidState.java index 61f5b8304..25ba62b03 100644 --- a/org.argeo.api.uuid/src/org/argeo/api/uuid/ConcurrentTimeUuidState.java +++ b/org.argeo.api.uuid/src/org/argeo/api/uuid/ConcurrentTimeUuidState.java @@ -19,7 +19,7 @@ import java.util.concurrent.atomic.AtomicLong; * A simple base implementation of {@link TimeUuidState}, which maintains * different clock sequences for each thread. */ -public class ConcurrentTimeUuidState implements TimeUuidState { +public class ConcurrentTimeUuidState implements UuidFactory.TimeUuidState { private final static Logger logger = System.getLogger(ConcurrentTimeUuidState.class.getName()); /** The maximum possible value of the clocksequence. */ @@ -46,8 +46,8 @@ public class ConcurrentTimeUuidState implements TimeUuidState { // compute the start reference startInstant = Instant.now(this.clock); long nowVm = nowVm(); - Duration duration = Duration.between(TimeUuidState.GREGORIAN_START, startInstant); - startTimeStamp = durationToUuidTimestamp(duration) - nowVm; + Duration duration = Duration.between(TimeUuid.TIMESTAMP_ZERO, startInstant); + startTimeStamp = TimeUuid.durationToTimestamp(duration) - nowVm; clockSequenceProvider = new ClockSequenceProvider(secureRandom); @@ -100,8 +100,8 @@ public class ConcurrentTimeUuidState implements TimeUuidState { private long computeNow() { if (useClockForMeasurement) { - Duration duration = Duration.between(TimeUuidState.GREGORIAN_START, Instant.now(clock)); - return durationToUuidTimestamp(duration); + Duration duration = Duration.between(TimeUuid.TIMESTAMP_ZERO, Instant.now(clock)); + return TimeUuid.durationToTimestamp(duration); } else { return startTimeStamp + nowVm(); } @@ -111,10 +111,6 @@ public class ConcurrentTimeUuidState implements TimeUuidState { return System.nanoTime() / 100; } - private long durationToUuidTimestamp(Duration duration) { - return (duration.getSeconds() * 10000000 + duration.getNano() / 100); - } - @Override public long getClockSequence() { return currentHolder.get().clockSequence; @@ -141,8 +137,7 @@ public class ConcurrentTimeUuidState implements TimeUuidState { @Override public long getMostSignificantBits() { long timestamp = useTimestamp(); - long mostSig = MOST_SIG_VERSION1 // base for version 1 UUID - | ((timestamp & 0xFFFFFFFFL) << 32) // time_low + long mostSig = UuidFactory.MOST_SIG_VERSION1 | ((timestamp & 0xFFFFFFFFL) << 32) // time_low | (((timestamp >> 32) & 0xFFFFL) << 16) // time_mid | ((timestamp >> 48) & 0x0FFFL);// time_hi_and_version return mostSig;