File tree Expand file tree Collapse file tree 2 files changed +11
-5
lines changed
impl/core/src/main/java/io/serverlessworkflow/impl Expand file tree Collapse file tree 2 files changed +11
-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 instance IDs.
23
23
*/
24
- public class UlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
24
+ public class MonotnicUlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
25
25
26
26
private final SecureRandom random = new SecureRandom ();
27
27
private final ULID ulid = new ULID (random );
28
+ private ULID .Value previousUlid ;
28
29
29
30
@ Override
30
- public String get () {
31
- return ulid .nextULID ();
31
+ public synchronized String get () {
32
+ if (previousUlid == null ) {
33
+ previousUlid = ulid .nextValue ();
34
+ } else {
35
+ previousUlid = ulid .nextMonotonicValue (previousUlid );
36
+ }
37
+ return previousUlid .toString ();
32
38
}
33
39
}
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 MonotnicUlidWorkflowInstanceIdFactory ();
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