|
29 | 29 | import io.serverlessworkflow.impl.events.EventConsumer; |
30 | 30 | import io.serverlessworkflow.impl.events.EventPublisher; |
31 | 31 | import io.serverlessworkflow.impl.events.InMemoryEvents; |
| 32 | +import io.serverlessworkflow.impl.executors.CallableTaskProxyBuilder; |
32 | 33 | import io.serverlessworkflow.impl.executors.DefaultTaskExecutorFactory; |
33 | 34 | import io.serverlessworkflow.impl.executors.TaskExecutorFactory; |
34 | 35 | import io.serverlessworkflow.impl.expressions.ExpressionFactory; |
|
48 | 49 | import java.util.Collections; |
49 | 50 | import java.util.HashMap; |
50 | 51 | import java.util.HashSet; |
| 52 | +import java.util.List; |
51 | 53 | import java.util.Map; |
52 | 54 | import java.util.Optional; |
53 | 55 | import java.util.ServiceLoader; |
@@ -83,6 +85,7 @@ public class WorkflowApplication implements AutoCloseable { |
83 | 85 | private final Optional<URITemplateResolver> templateResolver; |
84 | 86 | private final Optional<FunctionReader> functionReader; |
85 | 87 | private final URI defaultCatalogURI; |
| 88 | + private final Collection<CallableTaskProxyBuilder> callableProxyBuilders; |
86 | 89 |
|
87 | 90 | private WorkflowApplication(Builder builder) { |
88 | 91 | this.taskFactory = builder.taskFactory; |
@@ -110,6 +113,7 @@ private WorkflowApplication(Builder builder) { |
110 | 113 | this.functionReader = builder.functionReader; |
111 | 114 | this.defaultCatalogURI = builder.defaultCatalogURI; |
112 | 115 | this.id = builder.id; |
| 116 | + this.callableProxyBuilders = builder.callableProxyBuilders; |
113 | 117 | } |
114 | 118 |
|
115 | 119 | public TaskExecutorFactory taskFactory() { |
@@ -170,10 +174,10 @@ public SchemaValidator getValidator(SchemaInline inline) { |
170 | 174 | private String id; |
171 | 175 | private TaskExecutorFactory taskFactory; |
172 | 176 | private Collection<ExpressionFactory> exprFactories = new HashSet<>(); |
173 | | - private Collection<WorkflowExecutionListener> listeners = |
174 | | - ServiceLoader.load(WorkflowExecutionListener.class).stream() |
175 | | - .map(Provider::get) |
176 | | - .collect(Collectors.toList()); |
| 177 | + private List<WorkflowExecutionListener> listeners = |
| 178 | + loadFromServiceLoader(WorkflowExecutionListener.class); |
| 179 | + private List<CallableTaskProxyBuilder> callableProxyBuilders = |
| 180 | + loadFromServiceLoader(CallableTaskProxyBuilder.class); |
177 | 181 | private ResourceLoaderFactory resourceLoaderFactory = DefaultResourceLoaderFactory.get(); |
178 | 182 | private SchemaValidatorFactory schemaValidatorFactory; |
179 | 183 | private WorkflowPositionFactory positionFactory = () -> new QueueWorkflowPosition(); |
@@ -211,6 +215,11 @@ public Builder withListener(WorkflowExecutionListener listener) { |
211 | 215 | return this; |
212 | 216 | } |
213 | 217 |
|
| 218 | + public Builder withCallableProxy(CallableTaskProxyBuilder builder) { |
| 219 | + callableProxyBuilders.add(builder); |
| 220 | + return this; |
| 221 | + } |
| 222 | + |
214 | 223 | public Builder withTaskExecutorFactory(TaskExecutorFactory factory) { |
215 | 224 | this.taskFactory = factory; |
216 | 225 | return this; |
@@ -369,11 +378,17 @@ public WorkflowApplication build() { |
369 | 378 | if (defaultCatalogURI == null) { |
370 | 379 | defaultCatalogURI = URI.create("https://github.com/serverlessworkflow/catalog"); |
371 | 380 | } |
| 381 | + Collections.sort(listeners); |
| 382 | + Collections.sort(callableProxyBuilders); |
372 | 383 | if (id == null) { |
373 | 384 | id = idFactory.get(); |
374 | 385 | } |
375 | 386 | return new WorkflowApplication(this); |
376 | 387 | } |
| 388 | + |
| 389 | + private <T> List<T> loadFromServiceLoader(Class<T> clazz) { |
| 390 | + return ServiceLoader.load(clazz).stream().map(Provider::get).collect(Collectors.toList()); |
| 391 | + } |
377 | 392 | } |
378 | 393 |
|
379 | 394 | public Map<WorkflowDefinitionId, WorkflowDefinition> workflowDefinitions() { |
@@ -474,4 +489,8 @@ public <T> Optional<T> additionalObject( |
474 | 489 | return Optional.ofNullable(additionalObjects.get(name)) |
475 | 490 | .map(v -> (T) v.apply(workflowContext, taskContext)); |
476 | 491 | } |
| 492 | + |
| 493 | + public Collection<CallableTaskProxyBuilder> callableProxyBuilders() { |
| 494 | + return callableProxyBuilders; |
| 495 | + } |
477 | 496 | } |
0 commit comments