|
30 | 30 | @Experimental |
31 | 31 | public interface ActivityClientCallsInterceptor { |
32 | 32 |
|
| 33 | + /** |
| 34 | + * Schedules a standalone activity for execution. The activity type name, arguments, and |
| 35 | + * scheduling options are carried in {@code input}. |
| 36 | + * |
| 37 | + * @param input activity type, raw arguments, scheduling options, and propagated header |
| 38 | + * @return output containing the caller-supplied activity ID and the run ID assigned by the server |
| 39 | + * (if the server provides one) |
| 40 | + * @throws ActivityAlreadyStartedException if an activity with the same ID is already running |
| 41 | + */ |
33 | 42 | StartActivityOutput startActivity(StartActivityInput input) |
34 | 43 | throws ActivityAlreadyStartedException; |
35 | 44 |
|
| 45 | + /** |
| 46 | + * Synchronously long-polls the server until the activity completes, then deserializes and returns |
| 47 | + * the result. Loops automatically on empty long-poll responses (server-side timeout with no |
| 48 | + * outcome yet). Blocks the calling thread for the duration. |
| 49 | + * |
| 50 | + * @param input activity ID, optional run ID, and result class and generic type |
| 51 | + * @param <R> the expected result type |
| 52 | + * @return output wrapping the deserialized activity result |
| 53 | + * @throws ActivityFailedException if the activity failed or was cancelled |
| 54 | + */ |
36 | 55 | <R> GetActivityResultOutput<R> getActivityResult(GetActivityResultInput<R> input) |
37 | 56 | throws ActivityFailedException; |
38 | 57 |
|
39 | | - default <R> CompletableFuture<GetActivityResultOutput<R>> getActivityResultAsync( |
40 | | - GetActivityResultInput<R> input) { |
41 | | - return CompletableFuture.supplyAsync( |
42 | | - () -> { |
43 | | - try { |
44 | | - return getActivityResult(input); |
45 | | - } catch (ActivityFailedException e) { |
46 | | - throw new java.util.concurrent.CompletionException(e); |
47 | | - } |
48 | | - }); |
49 | | - } |
50 | | - |
| 58 | + /** |
| 59 | + * Returns the current execution description for a standalone activity. If a long-poll token from |
| 60 | + * a prior call is present in {@code input}, the server blocks until the description changes or |
| 61 | + * the poll times out, enabling efficient change detection. |
| 62 | + * |
| 63 | + * @param input activity ID, optional run ID, and optional long-poll token from a prior call |
| 64 | + * @return output containing the {@link ActivityExecutionDescription}; the fresh long-poll token |
| 65 | + * for the next call is stored inside the returned {@link ActivityExecutionDescription} |
| 66 | + */ |
51 | 67 | DescribeActivityOutput describeActivity(DescribeActivityInput input); |
52 | 68 |
|
| 69 | + /** |
| 70 | + * Requests cooperative cancellation of a running standalone activity. The activity will receive a |
| 71 | + * cancellation request on its next heartbeat; it may choose to honour or ignore it. |
| 72 | + * |
| 73 | + * @param input activity ID, optional run ID, and optional human-readable cancellation reason |
| 74 | + * @return an empty output object (reserved for future use) |
| 75 | + */ |
53 | 76 | CancelActivityOutput cancelActivity(CancelActivityInput input); |
54 | 77 |
|
| 78 | + /** |
| 79 | + * Forcefully terminates a running standalone activity. Unlike cancellation, termination is |
| 80 | + * immediate and cannot be caught or suppressed by the activity. |
| 81 | + * |
| 82 | + * @param input activity ID, optional run ID, and optional human-readable termination reason |
| 83 | + * @return an empty output object (reserved for future use) |
| 84 | + */ |
55 | 85 | TerminateActivityOutput terminateActivity(TerminateActivityInput input); |
56 | 86 |
|
| 87 | + /** |
| 88 | + * Returns a lazy {@link java.util.stream.Stream} of activity execution metadata matching the |
| 89 | + * Visibility query in {@code input}. Pages are fetched from the server on demand as the stream is |
| 90 | + * consumed. |
| 91 | + * |
| 92 | + * @param input Visibility query string and listing options (e.g. page-size limit) |
| 93 | + * @return output wrapping a stream of {@link ActivityExecutionMetadata} |
| 94 | + */ |
57 | 95 | ListActivitiesOutput listActivities(ListActivitiesInput input); |
58 | 96 |
|
| 97 | + /** |
| 98 | + * Returns a single page of activity execution metadata matching the Visibility query in {@code |
| 99 | + * input}. The returned {@link ActivityListPage} includes a token that can be passed back in a |
| 100 | + * subsequent call to retrieve the next page. |
| 101 | + * |
| 102 | + * @param input Visibility query string, optional next-page token, and pagination options |
| 103 | + * @return output containing the page of results and a next-page token ({@code null} if last page) |
| 104 | + */ |
59 | 105 | ListActivitiesPaginatedOutput listActivitiesPaginated(ListActivitiesPaginatedInput input); |
60 | 106 |
|
| 107 | + /** |
| 108 | + * Returns the count of activity executions matching the Visibility query in {@code input}. |
| 109 | + * |
| 110 | + * @param input Visibility query string and count options |
| 111 | + * @return output wrapping the {@link ActivityExecutionCount} |
| 112 | + */ |
61 | 113 | CountActivitiesOutput countActivities(CountActivitiesInput input); |
62 | 114 |
|
| 115 | + /** |
| 116 | + * Asynchronously polls for the activity result without blocking the calling thread. Returns a |
| 117 | + * {@link CompletableFuture} that completes with the deserialized result when the activity |
| 118 | + * succeeds, or completes exceptionally with {@link ActivityFailedException} on failure, or {@link |
| 119 | + * java.util.concurrent.TimeoutException} if the deadline in {@code input} expires before the |
| 120 | + * activity completes. |
| 121 | + * |
| 122 | + * <p>The default implementation wraps {@link #getActivityResult} in a {@link |
| 123 | + * CompletableFuture#supplyAsync} call. Interceptors that want true non-blocking behavior should |
| 124 | + * override this method. |
| 125 | + * |
| 126 | + * @param input activity ID, optional run ID, result class and generic type, and timeout |
| 127 | + * @param <R> the expected result type |
| 128 | + * @return a future that completes with output wrapping the deserialized activity result |
| 129 | + */ |
| 130 | + default <R> CompletableFuture<GetActivityResultOutput<R>> getActivityResultAsync( |
| 131 | + GetActivityResultInput<R> input) { |
| 132 | + return CompletableFuture.supplyAsync( |
| 133 | + () -> { |
| 134 | + try { |
| 135 | + return getActivityResult(input); |
| 136 | + } catch (ActivityFailedException e) { |
| 137 | + throw new java.util.concurrent.CompletionException(e); |
| 138 | + } |
| 139 | + }); |
| 140 | + } |
| 141 | + |
63 | 142 | @Experimental |
64 | 143 | final class StartActivityInput { |
65 | 144 | private final String activityType; |
|
0 commit comments