99import java .util .ArrayList ;
1010import java .util .Collections ;
1111import java .util .List ;
12+ import javax .annotation .Nonnull ;
1213
1314public class InternalNexusOperationContext {
1415 private final String namespace ;
@@ -18,22 +19,19 @@ public class InternalNexusOperationContext {
1819 private final WorkflowClient client ;
1920 NexusOperationOutboundCallsInterceptor outboundCalls ;
2021 // Links extracted from the inbound Nexus task. Stored once at the task-handler boundary so the
21- // workflow client (signal, signalWithStart) can attach them to outgoing requests via
22- // SignalWorkflowExecutionRequest. links.
22+ // workflow client can attach them to the outgoing requests it issues (e.g. signal,
23+ // signalWithStart) via the request's links field .
2324 private List <Link > nexusOperationLinks = Collections .emptyList ();
24- // Backlinks returned by outbound RPCs the operation handler issues (currently
25- // SignalWorkflowExecutionResponse.link and SignalWithStartWorkflowExecutionResponse.signal_link).
26- // One entry per outbound RPC that returned a link. Drained by the task handler when building
27- // StartOperationResponse so each RPC the handler issued gets a corresponding link on the caller
28- // workflow's history event.
25+ // Backlinks returned by outbound RPCs the operation handler issues (such as
26+ // SignalWorkflowExecutionResponse.link or SignalWithStartWorkflowExecutionResponse.signal_link).
27+ // One entry per outbound RPC that returned a link. Drained
28+ // by the task handler when building StartOperationResponse so each RPC the handler issued gets a
29+ // corresponding link on the caller workflow's history event.
2930 //
3031 // This context is only safe for use from the single thread that runs the operation handler (the
31- // Nexus task executor's thread). The mutators below assert this contract; a stray cross-thread
32- // call fails fast rather than silently corrupting the ArrayList .
32+ // Nexus task executor's thread); the backing ArrayList is not synchronized. Handlers must not
33+ // mutate it from other threads .
3334 private final List <Link > responseBacklinks = new ArrayList <>();
34- // Captured at construction (on the Nexus task executor's thread) and used to fail fast on any
35- // cross-thread mutation. See note on responseBacklinks.
36- private final Thread ownerThread ;
3735
3836 public InternalNexusOperationContext (
3937 String namespace ,
@@ -46,7 +44,6 @@ public InternalNexusOperationContext(
4644 this .endpoint = endpoint ;
4745 this .metricScope = metricScope ;
4846 this .client = client ;
49- this .ownerThread = Thread .currentThread ();
5047 }
5148
5249 public Scope getMetricsScope () {
@@ -88,15 +85,15 @@ public void setNexusOperationLinks(List<Link> links) {
8885 this .nexusOperationLinks = links == null ? Collections .emptyList () : links ;
8986 }
9087
91- /** Links from the inbound Nexus task; empty if none. Never null. */
92- public List <Link > getNexusOperationLinks () {
93- return nexusOperationLinks ;
88+ /** Links from the inbound Nexus task; empty if none. */
89+ public @ Nonnull List <Link > getNexusOperationLinks () {
90+ return Collections . unmodifiableList ( nexusOperationLinks ) ;
9491 }
9592
9693 /**
97- * Append a backlink returned by an outbound RPC the operation handler issued (signal or
98- * signalWithStart). The task handler drains the list when building the operation's
99- * StartOperationResponse.
94+ * Append a backlink returned by an outbound RPC the operation handler issued (e.g. signal,
95+ * signalWithStart, etc ). The task handler drains the list when building the
96+ * operation's StartOperationResponse.
10097 */
10198 public void addBacklink (Link link ) {
10299 if (link != null ) {
@@ -105,10 +102,13 @@ public void addBacklink(Link link) {
105102 }
106103
107104 /**
108- * Backlinks from every outbound RPC the handler issued. Never null; may be empty. Returned as an
109- * unmodifiable view; callers must not attempt to mutate.
105+ * Backlinks from every outbound RPC the handler issued. Returned as an unmodifiable view; callers
106+ * must not attempt to mutate. Entries are accumulated while the operation handler runs (the call
107+ * that flows through {@link
108+ * io.temporal.common.interceptors.NexusOperationInboundCallsInterceptor#startOperation}) and are
109+ * drained afterward by the task handler when building the StartOperationResponse.
110110 */
111- public List <Link > getBacklinks () {
111+ public @ Nonnull List <Link > getBacklinks () {
112112 return Collections .unmodifiableList (responseBacklinks );
113113 }
114114
0 commit comments