|
1 | 1 | package io.temporal.client; |
2 | 2 |
|
| 3 | +import io.grpc.Deadline; |
| 4 | +import io.temporal.client.NexusClientInterceptor.DeleteNexusOperationExecutionInput; |
| 5 | +import io.temporal.client.NexusClientInterceptor.DescribeNexusOperationExecutionInput; |
| 6 | +import io.temporal.client.NexusClientInterceptor.DescribeNexusOperationExecutionOutput; |
| 7 | +import io.temporal.client.NexusClientInterceptor.RequestCancelNexusOperationExecutionInput; |
| 8 | +import io.temporal.client.NexusClientInterceptor.TerminateNexusOperationExecutionInput; |
3 | 9 | import java.lang.reflect.Type; |
4 | 10 | import java.util.concurrent.CompletableFuture; |
| 11 | +import java.util.concurrent.TimeUnit; |
5 | 12 | import javax.annotation.Nullable; |
6 | 13 |
|
7 | | -public class NexusClientHandleImpl<R> implements NexusClientHandle<R> { |
| 14 | +public class NexusClientHandleImpl implements NexusClientHandle { |
8 | 15 |
|
9 | | - private final NexusClientInterceptor interceptor; |
| 16 | + // Default deadline applied to per-handle RPCs that need one (describe). Long-poll callers |
| 17 | + // should reach for a typed result API once it exists, which can take a caller-supplied |
| 18 | + // deadline. |
| 19 | + private static final long DEFAULT_DEADLINE_SECONDS = 30; |
10 | 20 |
|
11 | | - public NexusClientHandleImpl(NexusClientInterceptor interceptor) { |
| 21 | + private final NexusClientInterceptor interceptor; |
| 22 | + private final String operationId; |
| 23 | + private final @Nullable String runId; |
| 24 | + |
| 25 | + public NexusClientHandleImpl( |
| 26 | + NexusClientInterceptor interceptor, String operationId, @Nullable String runId) { |
| 27 | + if (interceptor == null) { |
| 28 | + throw new IllegalArgumentException("interceptor is required"); |
| 29 | + } |
| 30 | + if (operationId == null) { |
| 31 | + throw new IllegalArgumentException("operationId is required"); |
| 32 | + } |
12 | 33 | this.interceptor = interceptor; |
| 34 | + this.operationId = operationId; |
| 35 | + this.runId = runId; |
13 | 36 | } |
14 | 37 |
|
15 | | - public <T> NexusClientHandle<T> fromUntyped( |
16 | | - UntypedNexusClientHandle handle, Class<T> resultClass) { |
17 | | - return null; |
18 | | - } |
19 | | - |
20 | | - public <T> NexusClientHandle<T> fromUntyped( |
21 | | - UntypedNexusClientHandle handle, Class<T> resultClass, @Nullable Type resultType) { |
22 | | - return null; |
23 | | - } |
24 | | - |
25 | | - public R getResult() { |
26 | | - return null; |
| 38 | + @Override |
| 39 | + public String getNexusOperationId() { |
| 40 | + return operationId; |
27 | 41 | } |
28 | 42 |
|
29 | | - public CompletableFuture<R> getResultAsync() { |
30 | | - return null; |
| 43 | + @Override |
| 44 | + public @Nullable String getNexusOperationRunId() { |
| 45 | + return runId; |
31 | 46 | } |
32 | 47 |
|
33 | 48 | @Override |
34 | | - public @Nullable String getNexusOperationRunId() { |
35 | | - return ""; |
| 49 | + public NexusClientOperationExecutionDescription describe() { |
| 50 | + DescribeNexusOperationExecutionInput input = |
| 51 | + new DescribeNexusOperationExecutionInput( |
| 52 | + operationId, |
| 53 | + runId, |
| 54 | + /* includeInput= */ false, |
| 55 | + /* includeOutcome= */ true, |
| 56 | + Deadline.after(DEFAULT_DEADLINE_SECONDS, TimeUnit.SECONDS)); |
| 57 | + DescribeNexusOperationExecutionOutput output = |
| 58 | + interceptor.describeNexusOperationExecution(input); |
| 59 | + return output.getDescription(); |
36 | 60 | } |
37 | 61 |
|
38 | 62 | @Override |
39 | | - public <R> R getResult(Class<R> resultClass) { |
40 | | - return null; |
| 63 | + public void cancel() { |
| 64 | + cancel(null); |
41 | 65 | } |
42 | 66 |
|
43 | 67 | @Override |
44 | | - public <R> R getResult(Class<R> resultClass, @Nullable Type resultType) { |
45 | | - return null; |
| 68 | + public void cancel(@Nullable String reason) { |
| 69 | + interceptor.requestCancelNexusOperationExecution( |
| 70 | + new RequestCancelNexusOperationExecutionInput(operationId, runId, reason)); |
46 | 71 | } |
47 | 72 |
|
48 | 73 | @Override |
49 | | - public <R> CompletableFuture<R> getResultAsync(Class<R> resultClass) { |
50 | | - return null; |
| 74 | + public void terminate() { |
| 75 | + terminate(null); |
51 | 76 | } |
52 | 77 |
|
53 | 78 | @Override |
54 | | - public <R> CompletableFuture<R> getResultAsync(Class<R> resultClass, @Nullable Type resultType) { |
55 | | - return null; |
| 79 | + public void terminate(@Nullable String reason) { |
| 80 | + interceptor.terminateNexusOperationExecution( |
| 81 | + new TerminateNexusOperationExecutionInput(operationId, runId, reason)); |
56 | 82 | } |
57 | 83 |
|
58 | 84 | @Override |
59 | | - public NexusClientOperationExecutionDescription describe() { |
60 | | - return null; |
| 85 | + public void delete() { |
| 86 | + interceptor.deleteNexusOperationExecution( |
| 87 | + new DeleteNexusOperationExecutionInput(operationId, runId)); |
61 | 88 | } |
62 | 89 |
|
63 | 90 | @Override |
64 | | - public void cancel() {} |
| 91 | + public <R> R getResult(Class<R> resultClass) { |
| 92 | + throw new UnsupportedOperationException( |
| 93 | + "getResult is not yet implemented — pending DataConverter support on NexusClientOperationOptions" |
| 94 | + + " and a poll-until-completion strategy"); |
| 95 | + } |
65 | 96 |
|
66 | 97 | @Override |
67 | | - public void cancel(@Nullable String reason) {} |
| 98 | + public <R> R getResult(Class<R> resultClass, @Nullable Type resultType) { |
| 99 | + throw new UnsupportedOperationException( |
| 100 | + "getResult is not yet implemented — pending DataConverter support on NexusClientOperationOptions" |
| 101 | + + " and a poll-until-completion strategy"); |
| 102 | + } |
68 | 103 |
|
69 | 104 | @Override |
70 | | - public void terminate() {} |
| 105 | + public <R> CompletableFuture<R> getResultAsync(Class<R> resultClass) { |
| 106 | + throw new UnsupportedOperationException( |
| 107 | + "getResultAsync is not yet implemented — pending DataConverter support on NexusClientOperationOptions" |
| 108 | + + " and a poll-until-completion strategy"); |
| 109 | + } |
71 | 110 |
|
72 | 111 | @Override |
73 | | - public void terminate(@Nullable String reason) {} |
| 112 | + public <R> CompletableFuture<R> getResultAsync(Class<R> resultClass, @Nullable Type resultType) { |
| 113 | + throw new UnsupportedOperationException( |
| 114 | + "getResultAsync is not yet implemented — pending DataConverter support on NexusClientOperationOptions" |
| 115 | + + " and a poll-until-completion strategy"); |
| 116 | + } |
74 | 117 | } |
0 commit comments