Package io.cucumber.core.eventbus
Class IncrementingUuidGenerator
java.lang.Object
io.cucumber.core.eventbus.IncrementingUuidGenerator
- All Implemented Interfaces:
UuidGenerator
,Supplier<UUID>
Thread-safe and collision-free UUID generator for single JVM. This is a
sequence generator and each instance has its own counter. This generator is
about 100 times faster than #RandomUuidGenerator.
Properties:
- thread-safe
- collision-free in the same classloader
- almost collision-free in different classloaders / JVMs
- UUIDs generated using the instances from the same classloader are sortable
UUID version 8 (custom) / variant 2 ...
| 40 bits | 8 bits | 4 bits | 12 bits | 2 bits | 62 bits |
| -------------------| -------------- | ------- | ------------- | ------- | ------- |
| LSBs of epoch-time | sessionCounter | version | classloaderId | variant | counter |
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGenerate a new UUID.static void
setClassloaderId
(int classloaderId) Defines a new classloaderId for the class.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.cucumber.core.eventbus.UuidGenerator
get
-
Constructor Details
-
IncrementingUuidGenerator
public IncrementingUuidGenerator()
-
-
Method Details
-
setClassloaderId
public static void setClassloaderId(int classloaderId) Defines a new classloaderId for the class. This only affects instances created after the call (the instances created before the call keep their classloaderId). This method should be called to specify a classloaderId if you are using more than one class loader, and you want to guarantee a collision-free UUID generation (instead of the default random classloaderId which produces about 1% collision rate on the classloaderId, and thus can have UUID collision if the epoch-time, session counter and counter have the same values).- Parameters:
classloaderId
- the new classloaderId (only the least significant 12 bits are used)- See Also:
-
classloaderId
-
generateId
Generate a new UUID. Will throw an exception when out of capacity.- Specified by:
generateId
in interfaceUuidGenerator
- Returns:
- a non-null UUID
- Throws:
CucumberException
- when out of capacity
-