public class TimeBasedEpochRandomGenerator extends NoArgGenerator
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).
Modifier and Type | Field and Description |
---|---|
protected UUIDClock |
_clock
Underlying
UUIDClock used for accessing current time, to use for
generation. |
protected Random |
_random
Random number generator that this generator uses.
|
Constructor and Description |
---|
TimeBasedEpochRandomGenerator(Random rnd) |
TimeBasedEpochRandomGenerator(Random rnd,
UUIDClock clock) |
Modifier and Type | Method and Description |
---|---|
UUID |
construct(long rawTimestamp)
Method that will construct actual
UUID instance for given
unix epoch timestamp: called by generate() but may alternatively be
called directly to construct an instance with known timestamp. |
UUID |
generate()
Method for generating a
UUID . |
UUIDType |
getType()
Accessor for determining type of UUIDs (version) that this
generator instance will produce.
|
_toInt, _toLong, _toShort
protected final Random _random
public TimeBasedEpochRandomGenerator(Random rnd)
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's
SecureRandom
.public TimeBasedEpochRandomGenerator(Random rnd, UUIDClock clock)
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's
SecureRandom
.clock
- clock Object used for accessing current time to use for generationpublic UUIDType getType()
UUIDGenerator
getType
in class UUIDGenerator
public UUID generate()
NoArgGenerator
UUID
.generate
in class NoArgGenerator
UUID
public UUID construct(long rawTimestamp)
UUID
instance for given
unix epoch timestamp: called by generate()
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 same
UUID
even if same timestamp is being passed.rawTimestamp
- unix epoch millisCopyright © 2024 FasterXML.com. All rights reserved.