|
1 | 1 | package io.temporal.nexus; |
2 | 2 |
|
| 3 | +import io.nexusrpc.Link; |
3 | 4 | import io.nexusrpc.handler.OperationContext; |
| 5 | +import io.nexusrpc.handler.OperationMethodCancellationListener; |
4 | 6 | import io.nexusrpc.handler.OperationStartDetails; |
5 | 7 | import io.temporal.common.Experimental; |
| 8 | +import java.time.Instant; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Map; |
6 | 11 | import java.util.Objects; |
| 12 | +import org.jspecify.annotations.Nullable; |
7 | 13 |
|
8 | 14 | /** |
9 | 15 | * Context for a Nexus start operation request, passed to {@link |
@@ -31,18 +37,81 @@ public String getOperation() { |
31 | 37 | return operationContext.getOperation(); |
32 | 38 | } |
33 | 39 |
|
| 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 | + |
34 | 53 | /** Returns the request ID for this operation. */ |
35 | 54 | public String getRequestId() { |
36 | 55 | return operationStartDetails.getRequestId(); |
37 | 56 | } |
38 | 57 |
|
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); |
42 | 108 | } |
43 | 109 |
|
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); |
47 | 116 | } |
48 | 117 | } |
0 commit comments