Skip to content

Commit b634e47

Browse files
committed
Renaming to RequestLink and ResponseLink
1 parent d49bce3 commit b634e47

6 files changed

Lines changed: 154 additions & 145 deletions

File tree

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

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,10 @@ public WorkflowStartOutput start(WorkflowStartInput input) {
105105
// If this start is being issued from inside a Nexus operation handler, stash only the
106106
// forward operation->workflow link from the start response so NexusStartWorkflowHelper can
107107
// attach it to the WorkflowExecutionStarted event. Unlike signal/signalWithStart, start
108-
// deliberately does NOT add a backlink here: the operation->workflow relationship is already
109-
// captured by the forward link, so re-adding response.getLink() as a backlink would duplicate
110-
// it on the caller's history event. Do not "restore symmetry" by calling addBacklink here.
108+
// deliberately does NOT add a response link here: the operation->workflow relationship is
109+
// already captured by the forward link, so re-adding response.getLink() as a response link
110+
// would duplicate it on the caller's history event. Do not "restore symmetry" by calling
111+
// addResponseLink here.
111112
if (CurrentNexusOperationContext.isNexusContext()) {
112113
CurrentNexusOperationContext.get().setStartWorkflowResponseLink(response.getLink());
113114
}
@@ -130,7 +131,7 @@ public WorkflowSignalOutput signal(WorkflowSignalInput input) {
130131
// Nexus task links so the SignalWorkflowExecution history event links back to the caller.
131132
boolean inNexusContext = CurrentNexusOperationContext.isNexusContext();
132133
if (inNexusContext) {
133-
request.addAllLinks(CurrentNexusOperationContext.get().getNexusOperationLinks());
134+
request.addAllLinks(CurrentNexusOperationContext.get().getRequestLinks());
134135
}
135136

136137
DataConverter dataConverterWitSignalContext =
@@ -143,10 +144,10 @@ public WorkflowSignalOutput signal(WorkflowSignalInput input) {
143144
Optional<Payloads> inputArgs = dataConverterWitSignalContext.toPayloads(input.getArguments());
144145
inputArgs.ifPresent(request::setInput);
145146
SignalWorkflowExecutionResponse response = genericClient.signal(request.build());
146-
// Server >=1.31 with EnableCHASMSignalBacklinks returns a backlink pointing at the signal
147+
// Server >=1.31 with EnableCHASMSignalBacklinks returns a response link pointing at the signal
147148
// event; older servers leave it unset. Propagate when present.
148149
if (inNexusContext && response.hasLink()) {
149-
CurrentNexusOperationContext.get().addBacklink(response.getLink());
150+
CurrentNexusOperationContext.get().addResponseLink(response.getLink());
150151
}
151152
return new WorkflowSignalOutput();
152153
}
@@ -174,7 +175,7 @@ public WorkflowSignalWithStartOutput signalWithStart(WorkflowSignalWithStartInpu
174175
// WorkflowExecutionSignaled events on the callee link back to the caller.
175176
boolean inNexusContext = CurrentNexusOperationContext.isNexusContext();
176177
if (inNexusContext) {
177-
requestBuilder.addAllLinks(CurrentNexusOperationContext.get().getNexusOperationLinks());
178+
requestBuilder.addAllLinks(CurrentNexusOperationContext.get().getRequestLinks());
178179
}
179180
SignalWithStartWorkflowExecutionRequest request = requestBuilder.build();
180181
SignalWithStartWorkflowExecutionResponse response = genericClient.signalWithStart(request);
@@ -183,10 +184,10 @@ public WorkflowSignalWithStartOutput signalWithStart(WorkflowSignalWithStartInpu
183184
.setRunId(response.getRunId())
184185
.setWorkflowId(request.getWorkflowId())
185186
.build();
186-
// Server >=1.31 with EnableCHASMSignalBacklinks returns a backlink pointing at the signal
187+
// Server >=1.31 with EnableCHASMSignalBacklinks returns a response link pointing at the signal
187188
// event; older servers leave it unset. Propagate when present.
188189
if (inNexusContext && response.hasSignalLink()) {
189-
CurrentNexusOperationContext.get().addBacklink(response.getSignalLink());
190+
CurrentNexusOperationContext.get().addResponseLink(response.getSignalLink());
190191
}
191192
// TODO currently SignalWithStartWorkflowExecutionResponse doesn't have eagerWorkflowTask.
192193
// We should wire it when it's implemented server-side.

temporal-sdk/src/main/java/io/temporal/internal/nexus/InternalNexusOperationContext.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,22 @@ public class InternalNexusOperationContext {
2121
// Link returned by the StartWorkflowExecution response when the operation is backed by a workflow
2222
// (workflow-run operations). Read by NexusStartWorkflowHelper to attach the forward
2323
// operation->workflow link, fabricating a WORKFLOW_EXECUTION_STARTED link when the server omits
24-
// one. Distinct from the signal backlinks below.
24+
// one. Distinct from the response links below.
2525
Link startWorkflowResponseLink;
2626
// Links extracted from the inbound Nexus task. Stored once at the task-handler boundary so the
2727
// workflow client can attach them to the outgoing requests it issues (e.g. signal,
2828
// signalWithStart) via the request's links field.
29-
private List<Link> nexusOperationLinks = Collections.emptyList();
30-
// Backlinks returned by outbound RPCs the operation handler issues (such as
29+
private List<Link> requestLinks = Collections.emptyList();
30+
// Links returned by outbound RPCs the operation handler issues (such as
3131
// SignalWorkflowExecutionResponse.link or SignalWithStartWorkflowExecutionResponse.signal_link).
3232
// One entry per outbound RPC that returned a link. Drained
3333
// by the task handler when building StartOperationResponse so each RPC the handler issued gets a
3434
// corresponding link on the caller workflow's history event.
3535
//
3636
// A handler may issue RPCs from multiple threads, so every read and write of this list is guarded
37-
// by backlinksLock and getBacklinks() returns a defensive copy taken under the lock.
38-
private final Object backlinksLock = new Object();
39-
private final List<Link> responseBacklinks = new ArrayList<>();
37+
// by responseLinksLock and getResponseLinks() returns a defensive copy taken under the lock.
38+
private final Object responseLinksLock = new Object();
39+
private final List<Link> responseLinks = new ArrayList<>();
4040

4141
public InternalNexusOperationContext(
4242
String namespace,
@@ -86,13 +86,13 @@ public NexusOperationContext getUserFacingContext() {
8686
* Set the {@code common.v1.Link}s extracted from the inbound Nexus task so they can be attached
8787
* to RPCs issued by the operation handler.
8888
*/
89-
public void setNexusOperationLinks(List<Link> links) {
90-
this.nexusOperationLinks = links == null ? Collections.emptyList() : links;
89+
public void setRequestLinks(List<Link> links) {
90+
this.requestLinks = links == null ? Collections.emptyList() : links;
9191
}
9292

9393
/** Links from the inbound Nexus task; empty if none. */
94-
public @Nonnull List<Link> getNexusOperationLinks() {
95-
return Collections.unmodifiableList(nexusOperationLinks);
94+
public @Nonnull List<Link> getRequestLinks() {
95+
return Collections.unmodifiableList(requestLinks);
9696
}
9797

9898
public void setStartWorkflowResponseLink(Link link) {
@@ -104,28 +104,28 @@ public Link getStartWorkflowResponseLink() {
104104
}
105105

106106
/**
107-
* Append a backlink returned by an outbound RPC the operation handler issued (e.g. signal,
107+
* Append a response link returned by an outbound RPC the operation handler issued (e.g. signal,
108108
* signalWithStart, etc). The task handler drains the list when building the operation's
109109
* StartOperationResponse.
110110
*/
111-
public void addBacklink(Link link) {
111+
public void addResponseLink(Link link) {
112112
if (link != null) {
113-
synchronized (backlinksLock) {
114-
responseBacklinks.add(link);
113+
synchronized (responseLinksLock) {
114+
responseLinks.add(link);
115115
}
116116
}
117117
}
118118

119119
/**
120-
* Backlinks from every outbound RPC the handler issued. Returned as an unmodifiable view; callers
121-
* must not attempt to mutate. Entries are accumulated while the operation handler runs (the call
122-
* that flows through {@link
120+
* Response links from every outbound RPC the handler issued. Returned as an unmodifiable view;
121+
* callers must not attempt to mutate. Entries are accumulated while the operation handler runs
122+
* (the call that flows through {@link
123123
* io.temporal.common.interceptors.NexusOperationInboundCallsInterceptor#startOperation}) and are
124124
* drained afterward by the task handler when building the StartOperationResponse.
125125
*/
126-
public @Nonnull List<Link> getBacklinks() {
127-
synchronized (backlinksLock) {
128-
return Collections.unmodifiableList(new ArrayList<>(responseBacklinks));
126+
public @Nonnull List<Link> getResponseLinks() {
127+
synchronized (responseLinksLock) {
128+
return Collections.unmodifiableList(new ArrayList<>(responseLinks));
129129
}
130130
}
131131

temporal-sdk/src/main/java/io/temporal/internal/nexus/NexusTaskHandlerImpl.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ private StartOperationResponse handleStartOperation(
317317
link.getUrl());
318318
}
319319
});
320-
CurrentNexusOperationContext.get().setNexusOperationLinks(inboundCommonLinks);
320+
CurrentNexusOperationContext.get().setRequestLinks(inboundCommonLinks);
321321

322322
HandlerInputContent.Builder input =
323323
HandlerInputContent.newBuilder().setDataStream(task.getPayload().toByteString().newInput());
@@ -329,27 +329,27 @@ private StartOperationResponse handleStartOperation(
329329
OperationStartResult<HandlerResultContent> result =
330330
startOperation(context, operationStartDetails.build(), input.build());
331331
// If any RPCs the handler issued (e.g. signal, signalWithStart, etc) returned
332-
// backlinks, propagate them to the caller so the caller workflow's history event links to
333-
// each event on the callee. Same set of backlinks applies to both sync and async response
334-
// variants.
335-
List<io.temporal.api.nexus.v1.Link> backlinks = new ArrayList<>();
336-
for (io.temporal.api.common.v1.Link backlink :
337-
CurrentNexusOperationContext.get().getBacklinks()) {
338-
if (!backlink.hasWorkflowEvent()) {
332+
// response links, propagate them to the caller so the caller workflow's history event links
333+
// to each event on the callee. Same set of response links applies to both sync and async
334+
// response variants.
335+
List<io.temporal.api.nexus.v1.Link> responseLinks = new ArrayList<>();
336+
for (io.temporal.api.common.v1.Link responseLink :
337+
CurrentNexusOperationContext.get().getResponseLinks()) {
338+
if (!responseLink.hasWorkflowEvent()) {
339339
continue;
340340
}
341341
io.temporal.api.nexus.v1.Link converted =
342-
LinkConverter.workflowEventToNexusLink(backlink.getWorkflowEvent());
342+
LinkConverter.workflowEventToNexusLink(responseLink.getWorkflowEvent());
343343
if (converted != null) {
344-
backlinks.add(converted);
344+
responseLinks.add(converted);
345345
}
346346
}
347347

348348
if (result.isSync()) {
349349
startResponseBuilder.setSyncSuccess(
350350
StartOperationResponse.Sync.newBuilder()
351351
.setPayload(Payload.parseFrom(result.getSyncResult().getDataBytes()))
352-
.addAllLinks(backlinks)
352+
.addAllLinks(responseLinks)
353353
.build());
354354
} else {
355355
startResponseBuilder.setAsyncSuccess(
@@ -365,7 +365,7 @@ private StartOperationResponse handleStartOperation(
365365
.setUrl(link.getUri().toString())
366366
.build())
367367
.collect(Collectors.toList()))
368-
.addAllLinks(backlinks)
368+
.addAllLinks(responseLinks)
369369
.build());
370370
}
371371
} catch (OperationException e) {

0 commit comments

Comments
 (0)