Skip to content

Commit cb6a1f7

Browse files
committed
Javadoc for ActivityClientCallsInterceptor
1 parent 4ea8ea4 commit cb6a1f7

1 file changed

Lines changed: 91 additions & 12 deletions

File tree

temporal-sdk/src/main/java/io/temporal/common/interceptors/ActivityClientCallsInterceptor.java

Lines changed: 91 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,115 @@
3030
@Experimental
3131
public interface ActivityClientCallsInterceptor {
3232

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+
*/
3342
StartActivityOutput startActivity(StartActivityInput input)
3443
throws ActivityAlreadyStartedException;
3544

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+
*/
3655
<R> GetActivityResultOutput<R> getActivityResult(GetActivityResultInput<R> input)
3756
throws ActivityFailedException;
3857

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+
*/
5167
DescribeActivityOutput describeActivity(DescribeActivityInput input);
5268

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+
*/
5376
CancelActivityOutput cancelActivity(CancelActivityInput input);
5477

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+
*/
5585
TerminateActivityOutput terminateActivity(TerminateActivityInput input);
5686

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+
*/
5795
ListActivitiesOutput listActivities(ListActivitiesInput input);
5896

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+
*/
59105
ListActivitiesPaginatedOutput listActivitiesPaginated(ListActivitiesPaginatedInput input);
60106

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+
*/
61113
CountActivitiesOutput countActivities(CountActivitiesInput input);
62114

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+
63142
@Experimental
64143
final class StartActivityInput {
65144
private final String activityType;

0 commit comments

Comments
 (0)