Skip to content

Commit e994bad

Browse files
Respond to PR comments
1 parent da0391a commit e994bad

6 files changed

Lines changed: 193 additions & 9 deletions

File tree

temporal-sdk/src/main/java/io/temporal/nexus/TemporalNexusClient.java

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.temporal.client.WorkflowOptions;
55
import io.temporal.common.Experimental;
66
import io.temporal.workflow.Functions;
7+
import java.lang.reflect.Type;
78

89
/**
910
* Nexus-aware client wrapping {@link WorkflowClient}. Provides methods for interacting with
@@ -217,6 +218,45 @@ <T, A1, A2, A3, A4, A5, R> TemporalOperationResult<R> startWorkflow(
217218
A5 arg5,
218219
WorkflowOptions options);
219220

221+
/**
222+
* Starts a six-argument workflow that returns a value.
223+
*
224+
* <p>Example:
225+
*
226+
* <pre>{@code
227+
* client.startWorkflow(MyWorkflow.class, MyWorkflow::run, arg1, arg2, arg3, arg4, arg5, arg6, options)
228+
* }</pre>
229+
*
230+
* @param workflowClass the workflow interface class
231+
* @param workflowMethod unbound method reference to the workflow method
232+
* @param arg1 first workflow argument
233+
* @param arg2 second workflow argument
234+
* @param arg3 third workflow argument
235+
* @param arg4 fourth workflow argument
236+
* @param arg5 fifth workflow argument
237+
* @param arg6 sixth workflow argument
238+
* @param options workflow start options (must include workflowId)
239+
* @param <T> the workflow interface type
240+
* @param <A1> the type of the first workflow argument
241+
* @param <A2> the type of the second workflow argument
242+
* @param <A3> the type of the third workflow argument
243+
* @param <A4> the type of the fourth workflow argument
244+
* @param <A5> the type of the fifth workflow argument
245+
* @param <A6> the type of the sixth workflow argument
246+
* @param <R> the workflow return type
247+
* @return an async {@link TemporalOperationResult} with the workflow-run operation token
248+
*/
249+
<T, A1, A2, A3, A4, A5, A6, R> TemporalOperationResult<R> startWorkflow(
250+
Class<T> workflowClass,
251+
Functions.Func7<T, A1, A2, A3, A4, A5, A6, R> workflowMethod,
252+
A1 arg1,
253+
A2 arg2,
254+
A3 arg3,
255+
A4 arg4,
256+
A5 arg5,
257+
A6 arg6,
258+
WorkflowOptions options);
259+
220260
/**
221261
* Starts a zero-argument workflow with no return value.
222262
*
@@ -380,6 +420,44 @@ <T, A1, A2, A3, A4, A5> TemporalOperationResult<Void> startWorkflow(
380420
A5 arg5,
381421
WorkflowOptions options);
382422

423+
/**
424+
* Starts a six-argument workflow with no return value.
425+
*
426+
* <p>Example:
427+
*
428+
* <pre>{@code
429+
* client.startWorkflow(MyWorkflow.class, MyWorkflow::execute, arg1, arg2, arg3, arg4, arg5, arg6, options)
430+
* }</pre>
431+
*
432+
* @param workflowClass the workflow interface class
433+
* @param workflowMethod unbound method reference to the workflow method
434+
* @param arg1 first workflow argument
435+
* @param arg2 second workflow argument
436+
* @param arg3 third workflow argument
437+
* @param arg4 fourth workflow argument
438+
* @param arg5 fifth workflow argument
439+
* @param arg6 sixth workflow argument
440+
* @param options workflow start options (must include workflowId)
441+
* @param <T> the workflow interface type
442+
* @param <A1> the type of the first workflow argument
443+
* @param <A2> the type of the second workflow argument
444+
* @param <A3> the type of the third workflow argument
445+
* @param <A4> the type of the fourth workflow argument
446+
* @param <A5> the type of the fifth workflow argument
447+
* @param <A6> the type of the sixth workflow argument
448+
* @return an async {@link TemporalOperationResult} with the workflow-run operation token
449+
*/
450+
<T, A1, A2, A3, A4, A5, A6> TemporalOperationResult<Void> startWorkflow(
451+
Class<T> workflowClass,
452+
Functions.Proc7<T, A1, A2, A3, A4, A5, A6> workflowMethod,
453+
A1 arg1,
454+
A2 arg2,
455+
A3 arg3,
456+
A4 arg4,
457+
A5 arg5,
458+
A6 arg6,
459+
WorkflowOptions options);
460+
383461
/**
384462
* Starts a workflow using an untyped workflow type name.
385463
*
@@ -398,4 +476,35 @@ <T, A1, A2, A3, A4, A5> TemporalOperationResult<Void> startWorkflow(
398476
*/
399477
<R> TemporalOperationResult<R> startWorkflow(
400478
String workflowType, Class<R> resultClass, WorkflowOptions options, Object... args);
479+
480+
/**
481+
* Starts a workflow using an untyped workflow type name, with both a result class and a generic
482+
* {@link Type}. Use this overload when the workflow returns a generic type (e.g. {@code
483+
* List<String>}) so the result can be deserialized correctly.
484+
*
485+
* <p>Example:
486+
*
487+
* <pre>{@code
488+
* client.startWorkflow(
489+
* "MyWorkflow",
490+
* List.class,
491+
* new TypeToken<List<String>>() {}.getType(),
492+
* options,
493+
* input)
494+
* }</pre>
495+
*
496+
* @param workflowType the workflow type name string
497+
* @param resultClass the expected result class
498+
* @param resultType the expected result {@link Type} (carries generic parameters)
499+
* @param options workflow start options (must include workflowId)
500+
* @param args workflow arguments
501+
* @param <R> the workflow return type
502+
* @return an async {@link TemporalOperationResult} with the workflow-run operation token
503+
*/
504+
<R> TemporalOperationResult<R> startWorkflow(
505+
String workflowType,
506+
Class<R> resultClass,
507+
Type resultType,
508+
WorkflowOptions options,
509+
Object... args);
401510
}

temporal-sdk/src/main/java/io/temporal/nexus/TemporalNexusClientImpl.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import io.temporal.internal.client.NexusStartWorkflowResponse;
1111
import io.temporal.internal.nexus.NexusStartWorkflowHelper;
1212
import io.temporal.workflow.Functions;
13+
import java.lang.reflect.Type;
1314
import java.util.Objects;
1415
import java.util.concurrent.atomic.AtomicBoolean;
1516

@@ -112,6 +113,23 @@ public <T, A1, A2, A3, A4, A5, R> TemporalOperationResult<R> startWorkflow(
112113
() -> workflowMethod.apply(stub, arg1, arg2, arg3, arg4, arg5)));
113114
}
114115

116+
@Override
117+
public <T, A1, A2, A3, A4, A5, A6, R> TemporalOperationResult<R> startWorkflow(
118+
Class<T> workflowClass,
119+
Functions.Func7<T, A1, A2, A3, A4, A5, A6, R> workflowMethod,
120+
A1 arg1,
121+
A2 arg2,
122+
A3 arg3,
123+
A4 arg4,
124+
A5 arg5,
125+
A6 arg6,
126+
WorkflowOptions options) {
127+
T stub = client.newWorkflowStub(workflowClass, options);
128+
return invokeAndReturn(
129+
WorkflowHandle.fromWorkflowMethod(
130+
() -> workflowMethod.apply(stub, arg1, arg2, arg3, arg4, arg5, arg6)));
131+
}
132+
115133
// ---------- Void (Proc) overloads ----------
116134

117135
@Override
@@ -188,11 +206,38 @@ public <T, A1, A2, A3, A4, A5> TemporalOperationResult<Void> startWorkflow(
188206
() -> workflowMethod.apply(stub, arg1, arg2, arg3, arg4, arg5)));
189207
}
190208

209+
@Override
210+
public <T, A1, A2, A3, A4, A5, A6> TemporalOperationResult<Void> startWorkflow(
211+
Class<T> workflowClass,
212+
Functions.Proc7<T, A1, A2, A3, A4, A5, A6> workflowMethod,
213+
A1 arg1,
214+
A2 arg2,
215+
A3 arg3,
216+
A4 arg4,
217+
A5 arg5,
218+
A6 arg6,
219+
WorkflowOptions options) {
220+
T stub = client.newWorkflowStub(workflowClass, options);
221+
return invokeAndReturn(
222+
WorkflowHandle.fromWorkflowMethod(
223+
() -> workflowMethod.apply(stub, arg1, arg2, arg3, arg4, arg5, arg6)));
224+
}
225+
191226
// ---------- Untyped ----------
192227

193228
@Override
194229
public <R> TemporalOperationResult<R> startWorkflow(
195230
String workflowType, Class<R> resultClass, WorkflowOptions options, Object... args) {
231+
return startWorkflow(workflowType, resultClass, null, options, args);
232+
}
233+
234+
@Override
235+
public <R> TemporalOperationResult<R> startWorkflow(
236+
String workflowType,
237+
Class<R> resultClass,
238+
Type resultType,
239+
WorkflowOptions options,
240+
Object... args) {
196241
WorkflowStub stub = client.newUntypedWorkflowStub(workflowType, options);
197242
WorkflowHandle<R> handle = WorkflowHandle.fromWorkflowStub(stub, resultClass, args);
198243
return invokeAndReturn(handle);

temporal-sdk/src/main/java/io/temporal/nexus/TemporalOperationHandler.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package io.temporal.nexus;
22

33
import io.nexusrpc.handler.*;
4-
import io.nexusrpc.handler.OperationHandler;
54
import io.temporal.client.WorkflowClient;
65
import io.temporal.common.Experimental;
76
import io.temporal.internal.nexus.CurrentNexusOperationContext;

temporal-sdk/src/main/java/io/temporal/nexus/TemporalOperationResult.java

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,31 @@ public boolean isAsync() {
6161
}
6262

6363
/**
64-
* Returns the synchronous result value, or null if this is an async result.
64+
* Returns the synchronous result value.
6565
*
66-
* @return the sync result value, or null
66+
* @return the sync result value (may be null if the operation produced a null sync value)
67+
* @throws IllegalStateException if this is an async result; check {@link #isSync()} first
6768
*/
6869
@Nullable
6970
public R getSyncResult() {
71+
if (!isSync) {
72+
throw new IllegalStateException(
73+
"getSyncResult() called on async result; use getAsyncOperationToken() instead");
74+
}
7075
return syncResult;
7176
}
7277

7378
/**
74-
* Returns the async operation token, or null if this is a sync result.
79+
* Returns the async operation token.
7580
*
76-
* @return the operation token, or null
81+
* @return the operation token
82+
* @throws IllegalStateException if this is a sync result; check {@link #isAsync()} first
7783
*/
78-
@Nullable
7984
public String getAsyncOperationToken() {
85+
if (isSync) {
86+
throw new IllegalStateException(
87+
"getAsyncOperationToken() called on sync result; use getSyncResult() instead");
88+
}
8089
return asyncOperationToken;
8190
}
8291
}

temporal-sdk/src/test/java/io/temporal/workflow/nexus/GenericHandlerTypedProcTest.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public String execute(String input) {
4545

4646
TestNexusServiceProc serviceStub =
4747
Workflow.newNexusServiceStub(TestNexusServiceProc.class, serviceOptions);
48-
for (int i = 0; i < 6; i++) {
48+
for (int i = 0; i < 7; i++) {
4949
serviceStub.operation(i);
5050
}
5151
return "done";
@@ -114,6 +114,17 @@ public OperationHandler<Integer, Void> operation() {
114114
4,
115115
5,
116116
options);
117+
case 6:
118+
return client.startWorkflow(
119+
TestMultiArgWorkflowFunctions.Test6ArgWorkflowProc.class,
120+
TestMultiArgWorkflowFunctions.Test6ArgWorkflowProc::proc6,
121+
"input",
122+
2,
123+
3,
124+
4,
125+
5,
126+
6,
127+
options);
117128
default:
118129
throw new IllegalArgumentException("unexpected input: " + input);
119130
}

temporal-sdk/src/test/java/io/temporal/workflow/nexus/GenericHandlerTypedStartWorkflowTest.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void typedStartWorkflowTests() {
3030
TestWorkflows.TestWorkflow1 workflowStub =
3131
testWorkflowRule.newWorkflowStubTimeoutOptions(TestWorkflows.TestWorkflow1.class);
3232
String result = workflowStub.execute(testWorkflowRule.getTaskQueue());
33-
Assert.assertEquals("funcinputinput2input23input234input2345", result);
33+
Assert.assertEquals("funcinputinput2input23input234input2345input23456", result);
3434
}
3535

3636
public static class TestNexus implements TestWorkflows.TestWorkflow1 {
@@ -46,7 +46,7 @@ public String execute(String input) {
4646
TestNexusServiceGeneric serviceStub =
4747
Workflow.newNexusServiceStub(TestNexusServiceGeneric.class, serviceOptions);
4848
StringBuilder result = new StringBuilder();
49-
for (int i = 0; i < 6; i++) {
49+
for (int i = 0; i < 7; i++) {
5050
result.append(serviceStub.operation(i));
5151
}
5252
return result.toString();
@@ -115,6 +115,17 @@ public OperationHandler<Integer, String> operation() {
115115
4,
116116
5,
117117
options);
118+
case 6:
119+
return client.startWorkflow(
120+
TestMultiArgWorkflowFunctions.Test6ArgWorkflowFunc.class,
121+
TestMultiArgWorkflowFunctions.Test6ArgWorkflowFunc::func6,
122+
"input",
123+
2,
124+
3,
125+
4,
126+
5,
127+
6,
128+
options);
118129
default:
119130
throw new IllegalArgumentException("unexpected input: " + input);
120131
}

0 commit comments

Comments
 (0)