X-Git-Url: https://git.argeo.org/?a=blobdiff_plain;f=org.argeo.api.uuid%2Fsrc%2Forg%2Fargeo%2Fapi%2Fuuid%2FUuidFactory.java;h=ee5aa699472659127a4d40f1c3dbedaf6100490d;hb=d2bca81ff63496bf1d879f4cbcd6a531f598e69c;hp=91191dae2bf1fd17a4138048685a8e8d62515ad5;hpb=5550fa28a7578ce6dbc50d1f94bb4740c1f3ec32;p=lgpl%2Fargeo-commons.git diff --git a/org.argeo.api.uuid/src/org/argeo/api/uuid/UuidFactory.java b/org.argeo.api.uuid/src/org/argeo/api/uuid/UuidFactory.java index 91191dae2..ee5aa6994 100644 --- a/org.argeo.api.uuid/src/org/argeo/api/uuid/UuidFactory.java +++ b/org.argeo.api.uuid/src/org/argeo/api/uuid/UuidFactory.java @@ -14,9 +14,21 @@ import java.util.function.Supplier; * {@link Supplier#get()} method MUST be a v4 UUID (random). * * @see UUID - * @see https://datatracker.ietf.org/doc/html/rfc4122 + * @see "https://datatracker.ietf.org/doc/html/rfc4122" */ public interface UuidFactory extends Supplier { + + /* + * DEFAULT + */ + /** + * The default {@link UUID} to provide, either random (v4) or time based (v1). + * It SHOULD wrap either {@link #timeUUID()} (recommended) or + * {@link #randomUUID()}. + */ + @Override + UUID get(); + /* * TIME-BASED (version 1) */ @@ -120,16 +132,6 @@ public interface UuidFactory extends Supplier { return randomUUIDStrong(); } - /** - * The default {@link UUID} to provide, either random (v4) or time based (v1). - * This default implementations returns {@link #timeUUID()} because it is - * supposed to be fast and use few resources. - */ - @Override - default UUID get() { - return timeUUID(); - } - /* * STANDARD UUIDs */ @@ -157,6 +159,14 @@ public interface UuidFactory extends Supplier { */ final static UUID NAMESPACE_UUID_X500 = UUID.fromString("6ba7b814-9dad-11d1-80b4-00c04fd430c8"); + /* + * BIT LEVEL CONSTANTS + */ + /** Base for the most significant bit of version 1 (time based) UUIDs. */ + long MOST_SIG_VERSION1 = (1l << 12); + /** Base for the least significant part of RFC4122 (variant 2) UUIDs. */ + long LEAST_SIG_RFC4122_VARIANT = (1l << 63); + /* * UTILITIES */ @@ -174,7 +184,7 @@ public interface UuidFactory extends Supplier { * Whether this UUID is time based but was not generated from an IEEE 802 * address, as per Section 4.5 of RFC4122. * - * @see https://datatracker.ietf.org/doc/html/rfc4122#section-4.5 + * @see "https://datatracker.ietf.org/doc/html/rfc4122#section-4.5" */ static boolean isTimeBasedWithMacAddress(UUID uuid) { if (uuid.version() == 1) { @@ -187,4 +197,30 @@ public interface UuidFactory extends Supplier { static boolean isNameBased(UUID uuid) { return uuid.version() == 3 || uuid.version() == 5; } + + /** + * The state of a time based UUID generator, as described and discussed in + * section 4.2.1 of RFC4122. + * + * @see "https://datatracker.ietf.org/doc/html/rfc4122#section-4.2.1" + */ + interface TimeUuidState { + /** Current node id and clock sequence for this thread. */ + long getLeastSignificantBits(); + + /** A new current timestamp for this thread. */ + long getMostSignificantBits(); + + /** + * The last timestamp which was produced by this thread, as returned by + * {@link UUID#timestamp()}. + */ + long getLastTimestamp(); + + /** + * The current clock sequence for this thread, as returned by + * {@link UUID#clockSequence()}. + */ + long getClockSequence(); + } }