15
15
*/
16
16
package io .serverlessworkflow .impl ;
17
17
18
+ import com .github .f4b6a3 .ulid .UlidCreator ;
18
19
import io .serverlessworkflow .api .types .Document ;
19
20
import io .serverlessworkflow .api .types .Workflow ;
20
21
import io .serverlessworkflow .impl .executors .DefaultTaskExecutorFactory ;
21
22
import io .serverlessworkflow .impl .executors .TaskExecutorFactory ;
22
23
import io .serverlessworkflow .impl .expressions .ExpressionFactory ;
23
24
import io .serverlessworkflow .impl .expressions .JQExpressionFactory ;
25
+ import io .serverlessworkflow .impl .expressions .RuntimeDescriptor ;
24
26
import io .serverlessworkflow .impl .jsonschema .DefaultSchemaValidatorFactory ;
25
27
import io .serverlessworkflow .impl .jsonschema .SchemaValidatorFactory ;
26
28
import io .serverlessworkflow .impl .resources .DefaultResourceLoaderFactory ;
@@ -37,22 +39,28 @@ public class WorkflowApplication implements AutoCloseable {
37
39
private final ExpressionFactory exprFactory ;
38
40
private final ResourceLoaderFactory resourceLoaderFactory ;
39
41
private final SchemaValidatorFactory schemaValidatorFactory ;
42
+ private final WorkflowIdFactory idFactory ;
40
43
private final Collection <WorkflowExecutionListener > listeners ;
41
44
private final Map <WorkflowId , WorkflowDefinition > definitions ;
42
45
private final WorkflowPositionFactory positionFactory ;
46
+ private final RuntimeDescriptorFactory runtimeDescriptorFactory ;
43
47
44
48
public WorkflowApplication (
45
49
TaskExecutorFactory taskFactory ,
46
50
ExpressionFactory exprFactory ,
47
51
ResourceLoaderFactory resourceLoaderFactory ,
48
52
SchemaValidatorFactory schemaValidatorFactory ,
49
53
WorkflowPositionFactory positionFactory ,
54
+ WorkflowIdFactory idFactory ,
55
+ RuntimeDescriptorFactory runtimeDescriptorFactory ,
50
56
Collection <WorkflowExecutionListener > listeners ) {
51
57
this .taskFactory = taskFactory ;
52
58
this .exprFactory = exprFactory ;
53
59
this .resourceLoaderFactory = resourceLoaderFactory ;
54
60
this .schemaValidatorFactory = schemaValidatorFactory ;
55
61
this .positionFactory = positionFactory ;
62
+ this .idFactory = idFactory ;
63
+ this .runtimeDescriptorFactory = runtimeDescriptorFactory ;
56
64
this .listeners = listeners ;
57
65
this .definitions = new ConcurrentHashMap <>();
58
66
}
@@ -81,13 +89,20 @@ public Collection<WorkflowExecutionListener> listeners() {
81
89
return listeners ;
82
90
}
83
91
92
+ public WorkflowIdFactory idFactory () {
93
+ return idFactory ;
94
+ }
95
+
84
96
public static class Builder {
85
97
private TaskExecutorFactory taskFactory = DefaultTaskExecutorFactory .get ();
86
98
private ExpressionFactory exprFactory = JQExpressionFactory .get ();
87
99
private Collection <WorkflowExecutionListener > listeners ;
88
100
private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory .get ();
89
101
private SchemaValidatorFactory schemaValidatorFactory = DefaultSchemaValidatorFactory .get ();
90
- private WorkflowPositionFactory positionFactory = DefaultWorkflowPositionFactory .get ();
102
+ private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition ();
103
+ private WorkflowIdFactory idFactory = () -> UlidCreator .getMonotonicUlid ().toString ();
104
+ private RuntimeDescriptorFactory descriptorFactory =
105
+ () -> new RuntimeDescriptor ("reference impl" , "1.0.0_alpha" , Collections .emptyMap ());
91
106
92
107
private Builder () {}
93
108
@@ -124,13 +139,25 @@ public Builder withSchemaValidatorFactory(SchemaValidatorFactory factory) {
124
139
return this ;
125
140
}
126
141
142
+ public Builder withIdFactory (WorkflowIdFactory factory ) {
143
+ this .idFactory = factory ;
144
+ return this ;
145
+ }
146
+
147
+ public Builder withDescriptorFactory (RuntimeDescriptorFactory factory ) {
148
+ this .descriptorFactory = factory ;
149
+ return this ;
150
+ }
151
+
127
152
public WorkflowApplication build () {
128
153
return new WorkflowApplication (
129
154
taskFactory ,
130
155
exprFactory ,
131
156
resourceLoaderFactory ,
132
157
schemaValidatorFactory ,
133
158
positionFactory ,
159
+ idFactory ,
160
+ descriptorFactory ,
134
161
listeners == null
135
162
? Collections .emptySet ()
136
163
: Collections .unmodifiableCollection (listeners ));
@@ -159,4 +186,8 @@ public void close() throws Exception {
159
186
public WorkflowPositionFactory positionFactory () {
160
187
return positionFactory ;
161
188
}
189
+
190
+ public RuntimeDescriptorFactory runtimeDescriptorFactory () {
191
+ return runtimeDescriptorFactory ;
192
+ }
162
193
}
0 commit comments