File tree 3 files changed +29
-3
lines changed
main/java/com/uber/cadence
test/java/com/uber/cadence/workflow
3 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 20
20
import com .uber .cadence .QueryRejectCondition ;
21
21
import com .uber .cadence .WorkflowExecution ;
22
22
import com .uber .cadence .internal .common .QueryResponse ;
23
+ import java .lang .reflect .InvocationHandler ;
24
+ import java .lang .reflect .Proxy ;
23
25
import java .lang .reflect .Type ;
24
26
import java .util .Optional ;
25
27
import java .util .concurrent .CompletableFuture ;
@@ -44,12 +46,20 @@ public interface WorkflowStub {
44
46
* @return untyped workflow stub for the same workflow instance.
45
47
*/
46
48
static <T > WorkflowStub fromTyped (T typed ) {
47
- if (!(typed instanceof Supplier )) {
49
+ if (!(typed instanceof Proxy )) {
48
50
throw new IllegalArgumentException (
49
51
"arguments must be created through WorkflowClient.newWorkflowStub" );
50
52
}
53
+
54
+ InvocationHandler handler = Proxy .getInvocationHandler (typed );
55
+
56
+ if (!(handler instanceof Supplier )) {
57
+ throw new IllegalArgumentException (
58
+ "arguments must be created through WorkflowClient.newWorkflowStub" );
59
+ }
60
+
51
61
@ SuppressWarnings ("unchecked" )
52
- Supplier <WorkflowStub > supplier = (Supplier <WorkflowStub >) typed ;
62
+ Supplier <WorkflowStub > supplier = (Supplier <WorkflowStub >) handler ;
53
63
return supplier .get ();
54
64
}
55
65
Original file line number Diff line number Diff line change 38
38
import java .lang .reflect .InvocationHandler ;
39
39
import java .lang .reflect .Method ;
40
40
import java .util .Optional ;
41
+ import java .util .function .Supplier ;
41
42
42
43
/**
43
44
* Dynamic implementation of a strongly typed workflow interface that can be used to start, signal
44
45
* and query workflows from external processes.
45
46
*/
46
- class WorkflowInvocationHandler implements InvocationHandler {
47
+ class WorkflowInvocationHandler implements InvocationHandler , Supplier <WorkflowStub > {
48
+
49
+ @ Override
50
+ public WorkflowStub get () {
51
+ return untyped ;
52
+ }
47
53
48
54
public enum InvocationType {
49
55
SYNC ,
Original file line number Diff line number Diff line change @@ -1395,6 +1395,16 @@ public void testStart() {
1395
1395
assertEquals ("1234" , stubP4 .query ());
1396
1396
assertEquals ("12345" , stubP5 .query ());
1397
1397
assertEquals ("123456" , stubP6 .query ());
1398
+
1399
+ // Test execution from untyped stub.
1400
+ workflowOptions =
1401
+ newWorkflowOptionsBuilder (taskList ).setWorkflowId (UUID .randomUUID ().toString ()).build ();
1402
+ TestMultiargsWorkflowsFunc stub2 =
1403
+ workflowClient .newWorkflowStub (TestMultiargsWorkflowsFunc .class , workflowOptions );
1404
+ WorkflowStub untypedStub = WorkflowStub .fromTyped (stub2 );
1405
+ untypedStub .start ();
1406
+ String result = untypedStub .getResult (String .class );
1407
+ assertEquals ("func" , result );
1398
1408
}
1399
1409
1400
1410
@ Test
You can’t perform that action at this time.
0 commit comments