public abstract class AbstTimeBasedFactory extends UuidFactory
The time stamp has 100-nanoseconds resolution, starting from 1582-10-15, which is a date known as Gregorian Epoch. The the time stamp rolls over around AD 5235 (1582 + 2^60 / 365.25 / 24 / 60 / 60 / 10000000).
The node identifier can be:
The node identifier used by this factory can be controlled by defining a
system property 'uuidcreator.node' or an environment variable
'UUIDCREATOR_NODE'. The system property has preference over the
environment variable.
Options accepted by the system property and the environment variable:
If a property or variable is defined, all UUIDs generated by this factory will be based on it.
Otherwise, if no property or variable is defined, a random node identifier is generated once at instantiation. This is the default.
Example of system property definition:
# Append to VM arguments
-Duuidcreator.node="mac"
Example of environment variable definition:
# Append to ~/.profile
export UUIDCREATOR_NODE="mac"
TimeFunction,
NodeIdFunction,
ClockSeqFunction,
RFC 9562| Modifier and Type | Class and Description |
|---|---|
static class |
AbstTimeBasedFactory.Builder<T,B extends AbstTimeBasedFactory.Builder<T,B>>
Abstract builder for creating a time-based factory.
|
UuidFactory.Parameters| Modifier and Type | Field and Description |
|---|---|
protected ClockSeqFunction |
clockseqFunction
The clock sequence function.
|
protected ReentrantLock |
lock
The reentrant lock for synchronization.
|
protected NodeIdFunction |
nodeidFunction
The node function.
|
protected TimeFunction |
timeFunction
The time function.
|
version, versionMask| Modifier | Constructor and Description |
|---|---|
protected |
AbstTimeBasedFactory(UuidVersion version,
AbstTimeBasedFactory.Builder<?,?> builder)
A protected constructor that receives a builder object.
|
| Modifier and Type | Method and Description |
|---|---|
UUID |
create()
Returns a time-based UUID.
|
UUID |
create(UuidFactory.Parameters parameters)
Returns a time-based UUID.
|
protected long |
formatLeastSignificantBits(long nodeIdentifier,
long clockSequence)
Returns the least significant bits of the UUID.
|
protected long |
formatMostSignificantBits(long timestamp)
Returns the most significant bits of the UUID.
|
protected static NodeIdFunction |
selectNodeIdFunction()
Select the node identifier function.
|
protected static TimeFunction |
selectTimeFunction()
Select the time function.
|
getVersion, nameBytes, nameBytes, namespaceBytes, namespaceBytes, namespaceBytes, toUuidprotected TimeFunction timeFunction
protected NodeIdFunction nodeidFunction
protected ClockSeqFunction clockseqFunction
protected final ReentrantLock lock
protected AbstTimeBasedFactory(UuidVersion version, AbstTimeBasedFactory.Builder<?,?> builder)
version - the version number (1, 2 or 6)builder - a builder objectpublic UUID create()
create in class UuidFactorypublic UUID create(UuidFactory.Parameters parameters)
create in class UuidFactoryparameters - parameters objectprotected long formatMostSignificantBits(long timestamp)
It implements the algorithm for generating UUIDv1.
timestamp - the number of 100-nanoseconds since 1970-01-01 (Unix epoch)protected long formatLeastSignificantBits(long nodeIdentifier,
long clockSequence)
nodeIdentifier - a node identifierclockSequence - a clock sequenceprotected static NodeIdFunction selectNodeIdFunction()
protected static TimeFunction selectTimeFunction()
Copyright © 2024. All rights reserved.