diff --git a/impl/core/pom.xml b/impl/core/pom.xml
index 089402637..1d3587aae 100644
--- a/impl/core/pom.xml
+++ b/impl/core/pom.xml
@@ -21,8 +21,8 @@
slf4j-api
- de.huxhorn.sulky
- de.huxhorn.sulky.ulid
+ com.github.f4b6a3
+ ulid-creator
com.cronutils
diff --git a/impl/core/src/main/java/io/serverlessworkflow/impl/MonotonicUlidWorkflowInstanceIdFactory.java b/impl/core/src/main/java/io/serverlessworkflow/impl/MonotonicUlidWorkflowInstanceIdFactory.java
index 20a722a22..673be14a8 100644
--- a/impl/core/src/main/java/io/serverlessworkflow/impl/MonotonicUlidWorkflowInstanceIdFactory.java
+++ b/impl/core/src/main/java/io/serverlessworkflow/impl/MonotonicUlidWorkflowInstanceIdFactory.java
@@ -15,9 +15,8 @@
*/
package io.serverlessworkflow.impl;
-import de.huxhorn.sulky.ulid.ULID;
-import java.security.SecureRandom;
-import java.util.concurrent.atomic.AtomicReference;
+import com.github.f4b6a3.ulid.UlidFactory;
+import java.util.concurrent.ThreadLocalRandom;
/**
* A {@link WorkflowInstanceIdFactory} implementation that generates Monotonic ULIDs as workflow
@@ -25,17 +24,14 @@
*/
public class MonotonicUlidWorkflowInstanceIdFactory implements WorkflowInstanceIdFactory {
- private final ULID ulid;
- private final AtomicReference currentUlid;
+ private final UlidFactory factory;
public MonotonicUlidWorkflowInstanceIdFactory() {
- this.ulid = new ULID(new SecureRandom());
- this.currentUlid = new AtomicReference<>(ulid.nextValue());
+ factory = UlidFactory.newMonotonicInstance(() -> ThreadLocalRandom.current().nextLong());
}
+ @Override
public String get() {
- return currentUlid
- .getAndUpdate(previousUlid -> ulid.nextMonotonicValue(previousUlid))
- .toString();
+ return factory.create().toString();
}
}
diff --git a/impl/pom.xml b/impl/pom.xml
index 148d4e95e..8399933f5 100644
--- a/impl/pom.xml
+++ b/impl/pom.xml
@@ -10,7 +10,7 @@
pom
2.4.240
- 8.3.0
+ 5.2.4
4.0.0
1.6.2
4.0.2
@@ -136,9 +136,9 @@
${version.net.thisptr}
- de.huxhorn.sulky
- de.huxhorn.sulky.ulid
- ${version.de.huxhorn.sulky}
+ com.github.f4b6a3
+ ulid-creator
+ ${version.com.github.f4b6a3}
jakarta.ws.rs
diff --git a/impl/test/src/test/java/io/serverlessworkflow/impl/test/WorkflowInstanceIdTest.java b/impl/test/src/test/java/io/serverlessworkflow/impl/test/WorkflowInstanceIdTest.java
new file mode 100644
index 000000000..76583affd
--- /dev/null
+++ b/impl/test/src/test/java/io/serverlessworkflow/impl/test/WorkflowInstanceIdTest.java
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2020-Present The Serverless Workflow Specification Authors
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.serverlessworkflow.impl.test;
+
+import static io.serverlessworkflow.api.WorkflowReader.readWorkflowFromClasspath;
+import static org.assertj.core.api.Assertions.assertThat;
+
+import io.serverlessworkflow.impl.WorkflowApplication;
+import io.serverlessworkflow.impl.WorkflowDefinition;
+import io.serverlessworkflow.impl.WorkflowInstance;
+import java.io.IOException;
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+public class WorkflowInstanceIdTest {
+
+ @Test
+ void testWorkflowInstanceHasValidUlidId() throws IOException {
+ try (WorkflowApplication application = WorkflowApplication.builder().build()) {
+ WorkflowDefinition definition =
+ application.workflowDefinition(
+ readWorkflowFromClasspath("workflows-samples/simple-expression.yaml"));
+
+ WorkflowInstance instance = definition.instance(Map.of());
+ String id = instance.id();
+
+ // Verify ULID format: 26 characters, Crockford Base32
+ assertThat(id).hasSize(26);
+ assertThat(id).matches("[0-7][0-9A-HJKMNP-TV-Z]{25}");
+
+ // Verify uniqueness across instances
+ String id2 = definition.instance(Map.of()).id();
+ assertThat(id).isNotEqualTo(id2);
+ }
+ }
+}