File tree Expand file tree Collapse file tree 2 files changed +12
-5
lines changed
impl/core/src/main/java/io/serverlessworkflow/impl Expand file tree Collapse file tree 2 files changed +12
-5
lines changed Original file line number Diff line number Diff line change 19
19
import java .security .SecureRandom ;
20
20
21
21
/**
22
- * A {@link WorkflowInstanceIdFactory} implementation that generates ULIDs as workflow instance IDs.
22
+ * A {@link WorkflowInstanceIdFactory} implementation that generates Monotonic ULIDs as workflow
23
+ * instance IDs.
23
24
*/
24
- public class UlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
25
+ public class MonotonicUlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
25
26
26
27
private final SecureRandom random = new SecureRandom ();
27
28
private final ULID ulid = new ULID (random );
29
+ private ULID .Value previousUlid ;
28
30
29
31
@ Override
30
- public String get () {
31
- return ulid .nextULID ();
32
+ public synchronized String get () {
33
+ if (previousUlid == null ) {
34
+ previousUlid = ulid .nextValue ();
35
+ } else {
36
+ previousUlid = ulid .nextMonotonicValue (previousUlid );
37
+ }
38
+ return previousUlid .toString ();
32
39
}
33
40
}
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ public SchemaValidator getValidator(SchemaInline inline) {
140
140
private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory .get ();
141
141
private SchemaValidatorFactory schemaValidatorFactory ;
142
142
private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition ();
143
- private WorkflowInstanceIdFactory idFactory = new UlidWorkflowInstanceIdFactory ();
143
+ private WorkflowInstanceIdFactory idFactory = new MonotonicUlidWorkflowInstanceIdFactory ();
144
144
private ExecutorServiceFactory executorFactory = new DefaultExecutorServiceFactory ();
145
145
private EventConsumer <?, ?> eventConsumer ;
146
146
private Collection <EventPublisher > eventPublishers = new ArrayList <>();
You can’t perform that action at this time.
0 commit comments