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 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 instance IDs.
2323 */
24- public class UlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
24+ public class MonotnicUlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
2525
2626 private final SecureRandom random = new SecureRandom ();
2727 private final ULID ulid = new ULID (random );
28+ private ULID .Value previousUlid ;
2829
2930 @ 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 ();
3238 }
3339}
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 MonotnicUlidWorkflowInstanceIdFactory ();
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