Skip to content

Commit 71ab56f

Browse files
remove references to io.nexusrpc
1 parent e994bad commit 71ab56f

2 files changed

Lines changed: 121 additions & 12 deletions

File tree

temporal-sdk/src/main/java/io/temporal/nexus/TemporalOperationCancelContext.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@
22

33
import io.nexusrpc.handler.OperationCancelDetails;
44
import io.nexusrpc.handler.OperationContext;
5+
import io.nexusrpc.handler.OperationMethodCancellationListener;
56
import io.temporal.common.Experimental;
7+
import java.time.Instant;
8+
import java.util.Map;
69
import java.util.Objects;
10+
import org.jspecify.annotations.Nullable;
711

812
/**
913
* Context for a Nexus cancel operation request, passed to {@link
@@ -31,18 +35,54 @@ public String getOperation() {
3135
return operationContext.getOperation();
3236
}
3337

38+
/** Returns the headers for this cancel request. The returned map is case-insensitive. */
39+
public Map<String, String> getHeaders() {
40+
return operationContext.getHeaders();
41+
}
42+
43+
/**
44+
* Returns the deadline for the operation handler method. This is the time by which the method
45+
* should complete. This is not the operation's deadline.
46+
*/
47+
public @Nullable Instant getDeadline() {
48+
return operationContext.getDeadline();
49+
}
50+
3451
/** Returns the operation token identifying the operation to cancel. */
3552
public String getOperationToken() {
3653
return operationCancelDetails.getOperationToken();
3754
}
3855

39-
/** Returns the underlying {@link OperationContext} for advanced use cases. */
40-
public OperationContext getOperationContext() {
41-
return operationContext;
56+
/**
57+
* True if the handler method has been cancelled. Note, this is method cancellation, unrelated to
58+
* operation cancellation.
59+
*/
60+
public boolean isMethodCancelled() {
61+
return operationContext.isMethodCancelled();
62+
}
63+
64+
/**
65+
* Reason the handler method was cancelled, or null if not cancelled. Note, this is method
66+
* cancellation, unrelated to operation cancellation.
67+
*/
68+
public @Nullable String getMethodCancellationReason() {
69+
return operationContext.getMethodCancellationReason();
70+
}
71+
72+
/**
73+
* Add a listener for method cancellation. The listener is invoked immediately before this method
74+
* returns if the method is already cancelled. The listener must not block and must not be
75+
* registered from within another cancellation listener.
76+
*/
77+
public void addMethodCancellationListener(OperationMethodCancellationListener listener) {
78+
operationContext.addMethodCancellationListener(listener);
4279
}
4380

44-
/** Returns the underlying {@link OperationCancelDetails} for advanced use cases. */
45-
public OperationCancelDetails getOperationCancelDetails() {
46-
return operationCancelDetails;
81+
/**
82+
* Remove a method cancellation listener, if present. Must not be called from within another
83+
* cancellation listener.
84+
*/
85+
public void removeMethodCancellationListener(OperationMethodCancellationListener listener) {
86+
operationContext.removeMethodCancellationListener(listener);
4787
}
4888
}

temporal-sdk/src/main/java/io/temporal/nexus/TemporalOperationStartContext.java

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package io.temporal.nexus;
22

3+
import io.nexusrpc.Link;
34
import io.nexusrpc.handler.OperationContext;
5+
import io.nexusrpc.handler.OperationMethodCancellationListener;
46
import io.nexusrpc.handler.OperationStartDetails;
57
import io.temporal.common.Experimental;
8+
import java.time.Instant;
9+
import java.util.List;
10+
import java.util.Map;
611
import java.util.Objects;
12+
import org.jspecify.annotations.Nullable;
713

814
/**
915
* Context for a Nexus start operation request, passed to {@link
@@ -31,18 +37,81 @@ public String getOperation() {
3137
return operationContext.getOperation();
3238
}
3339

40+
/** Returns the headers for this operation request. The returned map is case-insensitive. */
41+
public Map<String, String> getHeaders() {
42+
return operationContext.getHeaders();
43+
}
44+
45+
/**
46+
* Returns the deadline for the operation handler method. This is the time by which the method
47+
* should complete. This is not the operation's deadline.
48+
*/
49+
public @Nullable Instant getDeadline() {
50+
return operationContext.getDeadline();
51+
}
52+
3453
/** Returns the request ID for this operation. */
3554
public String getRequestId() {
3655
return operationStartDetails.getRequestId();
3756
}
3857

39-
/** Returns the underlying {@link OperationContext} for advanced use cases. */
40-
public OperationContext getOperationContext() {
41-
return operationContext;
58+
/**
59+
* Optional callback URL for asynchronous operations to deliver results to. If present and the
60+
* implementation is asynchronous, the implementation should ensure this callback is invoked with
61+
* the result upon completion.
62+
*/
63+
public @Nullable String getCallbackUrl() {
64+
return operationStartDetails.getCallbackUrl();
65+
}
66+
67+
/** Headers to use on the callback if {@link #getCallbackUrl} is used. */
68+
public Map<String, String> getCallbackHeaders() {
69+
return operationStartDetails.getCallbackHeaders();
70+
}
71+
72+
/** Links sent by the caller. Handlers may use these as metadata on associated resources. */
73+
public List<Link> getLinks() {
74+
return operationStartDetails.getLinks();
75+
}
76+
77+
/**
78+
* True if the handler method has been cancelled. Note, this is method cancellation, unrelated to
79+
* operation cancellation.
80+
*/
81+
public boolean isMethodCancelled() {
82+
return operationContext.isMethodCancelled();
83+
}
84+
85+
/**
86+
* Reason the handler method was cancelled, or null if not cancelled. Note, this is method
87+
* cancellation, unrelated to operation cancellation.
88+
*/
89+
public @Nullable String getMethodCancellationReason() {
90+
return operationContext.getMethodCancellationReason();
91+
}
92+
93+
/**
94+
* Add a listener for method cancellation. The listener is invoked immediately before this method
95+
* returns if the method is already cancelled. The listener must not block and must not be
96+
* registered from within another cancellation listener.
97+
*/
98+
public void addMethodCancellationListener(OperationMethodCancellationListener listener) {
99+
operationContext.addMethodCancellationListener(listener);
100+
}
101+
102+
/**
103+
* Remove a method cancellation listener, if present. Must not be called from within another
104+
* cancellation listener.
105+
*/
106+
public void removeMethodCancellationListener(OperationMethodCancellationListener listener) {
107+
operationContext.removeMethodCancellationListener(listener);
42108
}
43109

44-
/** Returns the underlying {@link OperationStartDetails} for advanced use cases. */
45-
public OperationStartDetails getOperationStartDetails() {
46-
return operationStartDetails;
110+
/**
111+
* Associates links with the current operation to be propagated back to the caller. Links are only
112+
* attached on successful responses.
113+
*/
114+
public void addResponseLinks(Link... links) {
115+
operationContext.addLinks(links);
47116
}
48117
}

0 commit comments

Comments
 (0)