java.lang.Object
com.fasterxml.uuid.UUIDGenerator
com.fasterxml.uuid.NoArgGenerator
com.fasterxml.uuid.impl.TimeBasedEpochGenerator
Implementation of UUID generator that uses time/location based generation
method field from the Unix Epoch timestamp source - the number of
milliseconds seconds since midnight 1 Jan 1970 UTC, leap seconds excluded.
This is usually referred to as "Version 7".
As all JUG provided implementations, this generator is fully thread-safe.
Additionally it can also be made externally synchronized with other instances
(even ones running on other JVMs); to do this, use
FileBasedTimestampSynchronizer (or
equivalent).
- Since:
- 4.1
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedTimeBasedEpochGenerator(Consumer<byte[]> randomNextBytes, UUIDClock clock) TimeBasedEpochGenerator(Random rnd, UUIDClock clock) -
Method Summary
Modifier and TypeMethodDescriptionconstruct(long rawTimestamp) Method that will construct actualUUIDinstance for given unix epoch timestamp: called bygenerate()but may alternatively be called directly to construct an instance with known timestamp.generate()Method for generating aUUID.getType()Accessor for determining type of UUIDs (version) that this generator instance will produce.Methods inherited from class com.fasterxml.uuid.UUIDGenerator
_toInt, _toLong, _toShort
-
Field Details
-
ENTROPY_BYTE_LENGTH
private static final int ENTROPY_BYTE_LENGTH- See Also:
-
_randomNextBytes
Source for random numbers used to fill a byte array with entropy.- Since:
- 5.2 (replaced earlier
java.util.Random _random)
-
_clock
UnderlyingUUIDClockused for accessing current time, to use for generation.- Since:
- 4.3
-
_lastTimestamp
private long _lastTimestamp -
_lastEntropy
private final byte[] _lastEntropy
-
-
Constructor Details
-
TimeBasedEpochGenerator
- Parameters:
rnd- Random number generator to use for generating UUIDs; if null, shared default generator is used. Note that it is strongly recommend to use a good (pseudo) random number generator; for example, JDK'sSecureRandom.
-
TimeBasedEpochGenerator
- Parameters:
rnd- Random number generator to use for generating UUIDs; if null, shared default generator is used. Note that it is strongly recommend to use a good (pseudo) random number generator; for example, JDK'sSecureRandom.clock- clock Object used for accessing current time to use for generation
-
TimeBasedEpochGenerator
- Parameters:
randomNextBytes- Source for random numbers to use for generating UUIDs. Note that it is strongly recommend to use a good (pseudo) random number source; for example, JDK'sSecureRandom::nextBytes.clock- clock Object used for accessing current time to use for generation- Since:
- 5.2
-
-
Method Details
-
getType
Description copied from class:UUIDGeneratorAccessor for determining type of UUIDs (version) that this generator instance will produce.- Specified by:
getTypein classUUIDGenerator
-
generate
Description copied from class:NoArgGeneratorMethod for generating aUUID.- Specified by:
generatein classNoArgGenerator- Returns:
- Newly generated
UUID
-
construct
Method that will construct actualUUIDinstance for given unix epoch timestamp: called bygenerate()but may alternatively be called directly to construct an instance with known timestamp. NOTE: calling this method directly produces somewhat distinct UUIDs as "entropy" value is still generated as necessary to avoid producing sameUUIDeven if same timestamp is being passed.- Parameters:
rawTimestamp- unix epoch millis- Returns:
- unix epoch time based UUID
- Since:
- 4.3
-