File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed
src/main/java/com/uber/cadence Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -94,12 +94,17 @@ void setWorkflowImplementationTypes(
9494 }
9595
9696 <R > void addWorkflowImplementationFactory (Class <R > clazz , Functions .Func <R > factory ) {
97- workflowImplementationFactories .put (clazz , factory );
9897 WorkflowImplementationOptions unitTestingOptions =
9998 new WorkflowImplementationOptions .Builder ()
10099 .setNonDeterministicWorkflowPolicy (FailWorkflow )
101100 .build ();
102- addWorkflowImplementationType (unitTestingOptions , clazz );
101+ addWorkflowImplementationFactory (unitTestingOptions , clazz , factory );
102+ }
103+
104+ <R > void addWorkflowImplementationFactory (
105+ WorkflowImplementationOptions options , Class <R > clazz , Functions .Func <R > factory ) {
106+ workflowImplementationFactories .put (clazz , factory );
107+ addWorkflowImplementationType (options , clazz );
103108 }
104109
105110 private void addWorkflowImplementationType (
Original file line number Diff line number Diff line change @@ -98,6 +98,11 @@ public void setWorkflowImplementationTypes(
9898 factory .setWorkflowImplementationTypes (options , workflowImplementationTypes );
9999 }
100100
101+ public <R > void addWorkflowImplementationFactory (
102+ WorkflowImplementationOptions options , Class <R > clazz , Func <R > factory ) {
103+ this .factory .addWorkflowImplementationFactory (options , clazz , factory );
104+ }
105+
101106 public <R > void addWorkflowImplementationFactory (Class <R > clazz , Func <R > factory ) {
102107 this .factory .addWorkflowImplementationFactory (clazz , factory );
103108 }
Original file line number Diff line number Diff line change @@ -235,6 +235,23 @@ public void registerWorkflowImplementationTypes(
235235 workflowWorker .setWorkflowImplementationTypes (options , workflowImplementationClasses );
236236 }
237237
238+ /**
239+ * Configures a factory to use when an instance of a workflow implementation is created.
240+ * !IMPORTANT to provide newly created instances, each time factory is applied.
241+ *
242+ * <p>Unless mocking a workflow execution use {@link
243+ * #registerWorkflowImplementationTypes(Class[])}.
244+ *
245+ * @param workflowInterface Workflow interface that this factory implements
246+ * @param factory factory that when called creates a new instance of the workflow implementation
247+ * object.
248+ * @param <R> type of the workflow object to create.
249+ */
250+ public <R > void addWorkflowImplementationFactory (
251+ WorkflowImplementationOptions options , Class <R > workflowInterface , Func <R > factory ) {
252+ workflowWorker .addWorkflowImplementationFactory (options , workflowInterface , factory );
253+ }
254+
238255 /**
239256 * Configures a factory to use when an instance of a workflow implementation is created. The only
240257 * valid use for this method is unit testing, specifically to instantiate mocks that implement
You can’t perform that action at this time.
0 commit comments