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 1919import java .security .SecureRandom ;
2020
2121/**
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.
2324 */
24- public class UlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
25+ public class MonotonicUlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
2526
2627 private final SecureRandom random = new SecureRandom ();
2728 private final ULID ulid = new ULID (random );
29+ private ULID .Value previousUlid ;
2830
2931 @ 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 ();
3239 }
3340}
Original file line number Diff line number Diff line change @@ -140,7 +140,7 @@ public SchemaValidator getValidator(SchemaInline inline) {
140140 private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory .get ();
141141 private SchemaValidatorFactory schemaValidatorFactory ;
142142 private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition ();
143- private WorkflowInstanceIdFactory idFactory = new UlidWorkflowInstanceIdFactory ();
143+ private WorkflowInstanceIdFactory idFactory = new MonotonicUlidWorkflowInstanceIdFactory ();
144144 private ExecutorServiceFactory executorFactory = new DefaultExecutorServiceFactory ();
145145 private EventConsumer <?, ?> eventConsumer ;
146146 private Collection <EventPublisher > eventPublishers = new ArrayList <>();
You can’t perform that action at this time.
0 commit comments