]> git.argeo.org Git - lgpl/argeo-commons.git/blob - TimeUuidState.java
9c8b6dd69b294b8eb56f8cf9b66d02ae388bd40f
[lgpl/argeo-commons.git] / TimeUuidState.java
1 package org.argeo.api.uuid;
2
3 import java.time.Instant;
4 import java.time.ZoneOffset;
5 import java.time.ZonedDateTime;
6 import java.util.UUID;
7
8 /**
9 * The state of a time based UUID generator, as described and discussed in
10 * section 4.2.1 of RFC4122.
11 *
12 * @see https://datatracker.ietf.org/doc/html/rfc4122#section-4.2.1
13 */
14 public interface TimeUuidState {
15 long MOST_SIG_VERSION1 = (1l << 12);
16 long LEAST_SIG_RFC4122_VARIANT = (1l << 63);
17
18 /** Start of the Gregorian time, used by time-based UUID (v1). */
19 final static Instant GREGORIAN_START = ZonedDateTime.of(1582, 10, 15, 0, 0, 0, 0, ZoneOffset.UTC).toInstant();
20
21 /** Current node id and clock sequence for this thread. */
22 long getLeastSignificantBits();
23
24 /** A new current timestamp for this thread. */
25 long getMostSignificantBits();
26
27 /**
28 * The last timestamp which was produced by this thread, as returned by
29 * {@link UUID#timestamp()}.
30 */
31 long getLastTimestamp();
32
33 /**
34 * The current clock sequence for this thread, as returned by
35 * {@link UUID#clockSequence()}.
36 */
37 long getClockSequence();
38
39 static boolean isNoMacAddressNodeId(byte[] nodeId) {
40 return (nodeId[0] & 1) != 0;
41 }
42 }