Skip to content

Commit d3c18dd

Browse files
committed
Cleaned up some inputs
1 parent 96e9abb commit d3c18dd

5 files changed

Lines changed: 62 additions & 151 deletions

File tree

temporal-sdk/src/main/java/io/temporal/client/NexusClientImpl.java

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static io.temporal.internal.WorkflowThreadMarker.enforceNonWorkflowThread;
44

5-
import com.google.protobuf.ByteString;
65
import com.uber.m3.tally.Scope;
76
import io.temporal.common.Experimental;
87
import io.temporal.common.interceptors.NexusClientCallsInterceptor;
@@ -19,14 +18,9 @@
1918
import io.temporal.internal.client.external.GenericWorkflowClientImpl;
2019
import io.temporal.serviceclient.MetricsTag;
2120
import io.temporal.serviceclient.WorkflowServiceStubs;
22-
import java.util.Iterator;
2321
import java.util.List;
24-
import java.util.NoSuchElementException;
25-
import java.util.Spliterator;
26-
import java.util.Spliterators;
2722
import java.util.stream.Collectors;
2823
import java.util.stream.Stream;
29-
import java.util.stream.StreamSupport;
3024
import javax.annotation.Nullable;
3125
import org.slf4j.Logger;
3226
import org.slf4j.LoggerFactory;
@@ -132,16 +126,15 @@ NexusClientCallsInterceptor getNexusClientCallsInvoker() {
132126
return nexusClientCallsInvoker;
133127
}
134128

135-
private static final int DEFAULT_LIST_PAGE_SIZE = 1000;
136-
137129
@Override
138130
public Stream<NexusOperationExecutionMetadata> listNexusOperationExecutions(
139131
@Nullable String query) {
140-
Iterator<NexusOperationExecutionMetadata> iter =
141-
new ListPageIterator(nexusClientCallsInvoker, query, DEFAULT_LIST_PAGE_SIZE);
142-
return StreamSupport.stream(
143-
Spliterators.spliteratorUnknownSize(iter, Spliterator.ORDERED | Spliterator.NONNULL),
144-
false);
132+
// Pagination is handled inside the interceptor invoker; we receive a fully materialized list
133+
// and expose a Stream view of it to honour the public API contract.
134+
ListNexusOperationExecutionsOutput out =
135+
nexusClientCallsInvoker.listNexusOperationExecutions(
136+
new ListNexusOperationExecutionsInput(query));
137+
return out.getOperations().stream().map(NexusOperationExecutionMetadata::fromListInfo);
145138
}
146139

147140
@Override
@@ -158,54 +151,4 @@ public NexusOperationExecutionCount countNexusOperationExecutions(@Nullable Stri
158151
.collect(Collectors.toList());
159152
return new NexusOperationExecutionCount(out.getCount(), publicGroups);
160153
}
161-
162-
/** Lazily fetches pages from the interceptor and flattens them into a single iteration. */
163-
private static final class ListPageIterator implements Iterator<NexusOperationExecutionMetadata> {
164-
private final NexusClientCallsInterceptor invoker;
165-
private final @Nullable String query;
166-
private final int pageSize;
167-
private Iterator<NexusOperationExecutionMetadata> current =
168-
java.util.Collections.emptyIterator();
169-
private @Nullable ByteString nextPageToken = null;
170-
private boolean exhausted = false;
171-
172-
ListPageIterator(NexusClientCallsInterceptor invoker, @Nullable String query, int pageSize) {
173-
this.invoker = invoker;
174-
this.query = query;
175-
this.pageSize = pageSize;
176-
}
177-
178-
@Override
179-
public boolean hasNext() {
180-
while (!current.hasNext() && !exhausted) {
181-
fetchNextPage();
182-
}
183-
return current.hasNext();
184-
}
185-
186-
@Override
187-
public NexusOperationExecutionMetadata next() {
188-
if (!hasNext()) {
189-
throw new NoSuchElementException();
190-
}
191-
return current.next();
192-
}
193-
194-
private void fetchNextPage() {
195-
ListNexusOperationExecutionsOutput page =
196-
invoker.listNexusOperationExecutions(
197-
new ListNexusOperationExecutionsInput(query, pageSize, nextPageToken));
198-
current =
199-
page.getOperations().stream()
200-
.map(NexusOperationExecutionMetadata::fromListInfo)
201-
.iterator();
202-
ByteString token = page.getNextPageToken();
203-
if (token == null || token.isEmpty()) {
204-
exhausted = true;
205-
nextPageToken = null;
206-
} else {
207-
nextPageToken = token;
208-
}
209-
}
210-
}
211154
}

temporal-sdk/src/main/java/io/temporal/client/StartNexusOperationOptions.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ private Builder(StartNexusOperationOptions options) {
5050
this.idConflictPolicy = options.idConflictPolicy;
5151
}
5252

53-
/**
54-
* Required. Unique identifier for this operation within its namespace.
55-
*/
53+
/** Required. Unique identifier for this operation within its namespace. */
5654
public Builder setId(@Nonnull String id) {
5755
Objects.requireNonNull(id, "id");
5856
if (id.isEmpty()) {

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

Lines changed: 17 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.temporal.common.interceptors;
22

3-
import com.google.protobuf.ByteString;
43
import io.grpc.Deadline;
54
import io.temporal.api.common.v1.Payload;
65
import io.temporal.api.enums.v1.NexusOperationWaitStage;
@@ -45,19 +44,17 @@ StartNexusOperationExecutionOutput startNexusOperationExecution(
4544
/**
4645
* Returns a point-in-time snapshot of a standalone Nexus operation execution.
4746
*
48-
* @param input operation ID, optional run ID, and flags controlling whether to include input and
49-
* outcome payloads
47+
* @param input operation ID and optional run ID
5048
* @return output wrapping the {@link NexusOperationExecutionDescription}
5149
*/
5250
DescribeNexusOperationExecutionOutput describeNexusOperationExecution(
5351
DescribeNexusOperationExecutionInput input);
5452

5553
/**
56-
* Synchronously long-polls the server until the Nexus operation reaches the wait stage requested
57-
* in {@code input}, then returns the outcome. Blocks the calling thread for the duration.
54+
* Synchronously long-polls the server until the Nexus operation reaches a terminal stage, then
55+
* returns the outcome. Blocks the calling thread for the duration.
5856
*
59-
* @param input operation ID, optional run ID, target wait stage, and the deadline bounding the
60-
* poll
57+
* @param input operation ID, optional run ID, and the deadline bounding the poll
6158
* @return output containing the run ID, wait stage reached, operation token, and either the
6259
* result payload or failure (when the operation has reached a terminal stage)
6360
*/
@@ -68,20 +65,19 @@ PollNexusOperationExecutionOutput pollNexusOperationExecution(
6865
* Asynchronous variant of {@link #pollNexusOperationExecution} that returns a future without
6966
* blocking the calling thread.
7067
*
71-
* @param input operation ID, optional run ID, target wait stage, and the deadline bounding the
72-
* poll
68+
* @param input operation ID, optional run ID, and the deadline bounding the poll
7369
* @return a future that completes with the poll output, or completes exceptionally if the poll
7470
* fails or the deadline expires
7571
*/
7672
CompletableFuture<PollNexusOperationExecutionOutput> pollNexusOperationExecutionAsync(
7773
PollNexusOperationExecutionInput input);
7874

7975
/**
80-
* Lists standalone Nexus operation executions matching a Visibility query, with paging support.
76+
* Lists standalone Nexus operation executions matching a Visibility query. Pagination is handled
77+
* internally by the SDK; the returned output contains the full materialized result set.
8178
*
82-
* @param input Visibility query string, page size, and optional next-page token from a prior call
83-
* @return output wrapping the matching operations and the next-page token (empty when the result
84-
* set is exhausted)
79+
* @param input Visibility query string
80+
* @return output wrapping the matching operations
8581
*/
8682
ListNexusOperationExecutionsOutput listNexusOperationExecutions(
8783
ListNexusOperationExecutionsInput input);
@@ -199,15 +195,10 @@ public boolean isStarted() {
199195
final class DescribeNexusOperationExecutionInput {
200196
private final String operationId;
201197
private final @Nullable String runId;
202-
private final boolean includeInput;
203-
private final boolean includeOutcome;
204198

205-
public DescribeNexusOperationExecutionInput(
206-
String operationId, @Nullable String runId, boolean includeInput, boolean includeOutcome) {
199+
public DescribeNexusOperationExecutionInput(String operationId, @Nullable String runId) {
207200
this.operationId = operationId;
208201
this.runId = runId;
209-
this.includeInput = includeInput;
210-
this.includeOutcome = includeOutcome;
211202
}
212203

213204
public String getOperationId() {
@@ -217,14 +208,6 @@ public String getOperationId() {
217208
public Optional<String> getRunId() {
218209
return Optional.ofNullable(runId);
219210
}
220-
221-
public boolean isIncludeInput() {
222-
return includeInput;
223-
}
224-
225-
public boolean isIncludeOutcome() {
226-
return includeOutcome;
227-
}
228211
}
229212

230213
final class DescribeNexusOperationExecutionOutput {
@@ -242,17 +225,12 @@ public NexusOperationExecutionDescription getDescription() {
242225
final class PollNexusOperationExecutionInput {
243226
private final String operationId;
244227
private final @Nullable String runId;
245-
private final NexusOperationWaitStage waitStage;
246228
private final @Nonnull Deadline deadline;
247229

248230
public PollNexusOperationExecutionInput(
249-
String operationId,
250-
@Nullable String runId,
251-
NexusOperationWaitStage waitStage,
252-
@Nonnull Deadline deadline) {
231+
String operationId, @Nullable String runId, @Nonnull Deadline deadline) {
253232
this.operationId = operationId;
254233
this.runId = runId;
255-
this.waitStage = waitStage;
256234
this.deadline = deadline;
257235
}
258236

@@ -264,10 +242,6 @@ public Optional<String> getRunId() {
264242
return Optional.ofNullable(runId);
265243
}
266244

267-
public NexusOperationWaitStage getWaitStage() {
268-
return waitStage;
269-
}
270-
271245
public Deadline getDeadline() {
272246
return deadline;
273247
}
@@ -316,46 +290,30 @@ public Optional<Failure> getFailure() {
316290

317291
final class ListNexusOperationExecutionsInput {
318292
private final @Nullable String query;
319-
private final int pageSize;
320-
private final @Nullable ByteString nextPageToken;
321293

322-
public ListNexusOperationExecutionsInput(
323-
@Nullable String query, int pageSize, @Nullable ByteString nextPageToken) {
294+
public ListNexusOperationExecutionsInput(@Nullable String query) {
324295
this.query = query;
325-
this.pageSize = pageSize;
326-
this.nextPageToken = nextPageToken;
327296
}
328297

329298
public Optional<String> getQuery() {
330299
return Optional.ofNullable(query);
331300
}
332-
333-
public int getPageSize() {
334-
return pageSize;
335-
}
336-
337-
public Optional<ByteString> getNextPageToken() {
338-
return Optional.ofNullable(nextPageToken);
339-
}
340301
}
341302

303+
/**
304+
* Result of a list call. Holds the full materialized result set; pagination is handled inside the
305+
* SDK and not exposed through the interceptor surface.
306+
*/
342307
final class ListNexusOperationExecutionsOutput {
343308
private final List<NexusOperationExecutionListInfo> operations;
344-
private final ByteString nextPageToken;
345309

346-
public ListNexusOperationExecutionsOutput(
347-
List<NexusOperationExecutionListInfo> operations, ByteString nextPageToken) {
310+
public ListNexusOperationExecutionsOutput(List<NexusOperationExecutionListInfo> operations) {
348311
this.operations = Collections.unmodifiableList(operations);
349-
this.nextPageToken = nextPageToken;
350312
}
351313

352314
public List<NexusOperationExecutionListInfo> getOperations() {
353315
return operations;
354316
}
355-
356-
public ByteString getNextPageToken() {
357-
return nextPageToken;
358-
}
359317
}
360318

361319
final class CountNexusOperationExecutionsInput {

temporal-sdk/src/main/java/io/temporal/internal/client/NexusOperationHandleImpl.java

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,7 @@ public String getNexusOperationId() {
6969
@Override
7070
public NexusOperationExecutionDescription describe() {
7171
DescribeNexusOperationExecutionInput input =
72-
new DescribeNexusOperationExecutionInput(
73-
operationId, runId, /* includeInput= */ false, /* includeOutcome= */ true);
72+
new DescribeNexusOperationExecutionInput(operationId, runId);
7473
DescribeNexusOperationExecutionOutput output =
7574
interceptor.describeNexusOperationExecution(input);
7675
return output.getDescription();
@@ -161,11 +160,7 @@ private PollNexusOperationExecutionOutput pollSyncUntilCompletedOrDeadline(Deadl
161160
throws TimeoutException {
162161
while (true) {
163162
PollNexusOperationExecutionInput pollInput =
164-
new PollNexusOperationExecutionInput(
165-
operationId,
166-
runId,
167-
NexusOperationWaitStage.NEXUS_OPERATION_WAIT_STAGE_CLOSED,
168-
deadline);
163+
new PollNexusOperationExecutionInput(operationId, runId, deadline);
169164
PollNexusOperationExecutionOutput out;
170165
try {
171166
out = interceptor.pollNexusOperationExecution(pollInput);
@@ -184,11 +179,7 @@ private PollNexusOperationExecutionOutput pollSyncUntilCompletedOrDeadline(Deadl
184179
private CompletableFuture<PollNexusOperationExecutionOutput> pollAsyncUntilCompletedOrDeadline(
185180
Deadline deadline) {
186181
PollNexusOperationExecutionInput pollInput =
187-
new PollNexusOperationExecutionInput(
188-
operationId,
189-
runId,
190-
NexusOperationWaitStage.NEXUS_OPERATION_WAIT_STAGE_CLOSED,
191-
deadline);
182+
new PollNexusOperationExecutionInput(operationId, runId, deadline);
192183
CompletableFuture<PollNexusOperationExecutionOutput> pollFuture;
193184
try {
194185
pollFuture = interceptor.pollNexusOperationExecutionAsync(pollInput);

0 commit comments

Comments
 (0)