Package com.fasterxml.uuid.impl
Class TimeBasedEpochRandomGenerator
java.lang.Object
com.fasterxml.uuid.UUIDGenerator
com.fasterxml.uuid.NoArgGenerator
com.fasterxml.uuid.impl.TimeBasedEpochRandomGenerator
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".
In addition to that random part is regenerated for every new UUID.
This removes possibilities to have almost similar UUID, when calls
to generate are made within same millisecond.
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:
- 5.0
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionconstruct
(long rawTimestamp) Method that will construct actualUUID
instance 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
-
_random
Random number generator that this generator uses. -
_clock
UnderlyingUUIDClock
used for accessing current time, to use for generation.
-
-
Constructor Details
-
TimeBasedEpochRandomGenerator
- 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
.
-
TimeBasedEpochRandomGenerator
- 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
-
-
Method Details
-
getType
Description copied from class:UUIDGenerator
Accessor for determining type of UUIDs (version) that this generator instance will produce.- Specified by:
getType
in classUUIDGenerator
-
generate
Description copied from class:NoArgGenerator
Method for generating aUUID
.- Specified by:
generate
in classNoArgGenerator
- Returns:
- Newly generated
UUID
-
construct
Method that will construct actualUUID
instance 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 sameUUID
even if same timestamp is being passed.- Parameters:
rawTimestamp
- unix epoch millis- Returns:
- unix epoch time based UUID
-