@@ -38,7 +38,6 @@ class WorkflowExternalInvocationHandler implements InvocationHandler {
38
38
private final AtomicReference <UntypedWorkflowStubImpl > untyped = new AtomicReference <>();
39
39
private final WorkflowOptions options ;
40
40
private final DataConverter dataConverter ;
41
- private final AtomicReference <WorkflowExecution > execution = new AtomicReference <>();
42
41
private final GenericWorkflowClientExternal genericClient ;
43
42
private String workflowType ;
44
43
@@ -79,7 +78,6 @@ public static void closeAsyncInvocation() {
79
78
}
80
79
this .genericClient = genericClient ;
81
80
this .untyped .set (new UntypedWorkflowStubImpl (genericClient , dataConverter , execution ));
82
- this .execution .set (execution );
83
81
this .options = null ;
84
82
this .dataConverter = dataConverter ;
85
83
}
@@ -104,18 +102,16 @@ public Object invoke(Object proxy, Method method, Object[] args) {
104
102
if (workflowMethod != null ) {
105
103
WorkflowOptions mergedOptions = WorkflowOptions .merge (workflowMethod , options );
106
104
// We do allow duplicated calls if policy is not AllowDuplicate. Semantic is to wait for result.
107
- if (execution .get () != null ) { // stub is reused
105
+ UntypedWorkflowStubImpl workflowStub = untyped .get ();
106
+ if (workflowStub != null ) { // stub is reused
108
107
if (mergedOptions .getWorkflowIdReusePolicy () == WorkflowIdReusePolicy .AllowDuplicate ) {
109
108
throw new DuplicateWorkflowException (
110
- execution . get (), workflowType , "Cannot call @WorkflowMethod more than once per stub instance" );
109
+ workflowStub . getExecution (), workflowType , "Cannot call @WorkflowMethod more than once per stub instance" );
111
110
}
112
- return getUntyped () .getResult (method .getReturnType ());
111
+ return workflowStub .getResult (method .getReturnType ());
113
112
}
114
113
return startWorkflow (method , workflowMethod , mergedOptions , args );
115
114
}
116
- if (execution .get () == null ) {
117
- throw new IllegalStateException ("Workflow not started yet" );
118
- }
119
115
if (queryMethod != null ) {
120
116
return queryWorkflow (method , queryMethod , args );
121
117
}
@@ -172,20 +168,20 @@ private Object startWorkflow(Method method, WorkflowMethod workflowMethod,
172
168
if (untyped .get () == null ) {
173
169
untyped .set (new UntypedWorkflowStubImpl (genericClient , dataConverter , workflowType , mergedOptions ));
174
170
}
171
+ UntypedWorkflowStubImpl workflowStub = getUntyped ();
175
172
try {
176
- execution . set ( getUntyped (). startWithOptions (mergedOptions , args ) );
173
+ workflowStub . startWithOptions (mergedOptions , args );
177
174
} catch (DuplicateWorkflowException e ) {
178
- execution .set (e .getExecution ());
179
175
// We do allow duplicated calls if policy is not AllowDuplicate. Semantic is to wait for result.
180
176
if (mergedOptions .getWorkflowIdReusePolicy () == WorkflowIdReusePolicy .AllowDuplicate ) {
181
177
throw e ;
182
178
}
183
179
}
184
180
AtomicReference <WorkflowExecution > async = asyncResult .get ();
185
181
if (async != null ) {
186
- async .set (execution . get ());
182
+ async .set (workflowStub . getExecution ());
187
183
return null ;
188
184
}
189
- return getUntyped () .getResult (method .getReturnType ());
185
+ return workflowStub .getResult (method .getReturnType ());
190
186
}
191
187
}
0 commit comments