2727import java .util .Objects ;
2828import javax .annotation .Nonnull ;
2929
30- class NexusTaskToken {
30+ public class NexusTaskToken {
3131
32- @ Nonnull private final ExecutionId executionId ;
33- private final long scheduledEventId ;
32+ @ Nonnull private final NexusOperationRef ref ;
3433 private final int attempt ;
34+ private final boolean isCancel ;
3535
3636 NexusTaskToken (
3737 @ Nonnull String namespace ,
3838 @ Nonnull WorkflowExecution execution ,
3939 long scheduledEventId ,
40- int attempt ) {
40+ int attempt ,
41+ boolean isCancel ) {
4142 this (
4243 new ExecutionId (Objects .requireNonNull (namespace ), Objects .requireNonNull (execution )),
4344 scheduledEventId ,
44- attempt );
45+ attempt ,
46+ isCancel );
4547 }
4648
4749 NexusTaskToken (
4850 @ Nonnull String namespace ,
4951 @ Nonnull String workflowId ,
5052 @ Nonnull String runId ,
5153 long scheduledEventId ,
52- int attempt ) {
54+ int attempt ,
55+ boolean isCancel ) {
5356 this (
5457 namespace ,
5558 WorkflowExecution .newBuilder ()
5659 .setWorkflowId (Objects .requireNonNull (workflowId ))
5760 .setRunId (Objects .requireNonNull (runId ))
5861 .build (),
5962 scheduledEventId ,
60- attempt );
63+ attempt ,
64+ isCancel );
6165 }
6266
63- NexusTaskToken (@ Nonnull ExecutionId executionId , long scheduledEventId , int attempt ) {
64- this .executionId = Objects .requireNonNull (executionId );
65- this .scheduledEventId = scheduledEventId ;
66- this .attempt = attempt ;
67+ NexusTaskToken (
68+ @ Nonnull ExecutionId executionId , long scheduledEventId , int attempt , boolean isCancel ) {
69+ this (
70+ new NexusOperationRef (Objects .requireNonNull (executionId ), scheduledEventId ),
71+ attempt ,
72+ isCancel );
6773 }
6874
69- public ExecutionId getExecutionId () {
70- return executionId ;
75+ public NexusTaskToken (@ Nonnull NexusOperationRef ref , int attempt , boolean isCancel ) {
76+ this .ref = Objects .requireNonNull (ref );
77+ this .attempt = attempt ;
78+ this .isCancel = isCancel ;
7179 }
7280
73- public long getScheduledEventId () {
74- return scheduledEventId ;
81+ public NexusOperationRef getOperationRef () {
82+ return ref ;
7583 }
7684
7785 public long getAttempt () {
7886 return attempt ;
7987 }
8088
89+ public boolean isCancel () {
90+ return isCancel ;
91+ }
92+
8193 /** Used for task tokens. */
8294 public ByteString toBytes () {
8395 try (ByteArrayOutputStream bout = new ByteArrayOutputStream ();
8496 DataOutputStream out = new DataOutputStream (bout )) {
97+ ExecutionId executionId = ref .getExecutionId ();
8598 out .writeUTF (executionId .getNamespace ());
8699 WorkflowExecution execution = executionId .getExecution ();
87100 out .writeUTF (execution .getWorkflowId ());
88101 out .writeUTF (execution .getRunId ());
89- out .writeLong (scheduledEventId );
102+ out .writeLong (ref . getScheduledEventId () );
90103 out .writeInt (attempt );
104+ out .writeBoolean (isCancel );
91105 return ByteString .copyFrom (bout .toByteArray ());
92106 } catch (IOException e ) {
93107 throw Status .INTERNAL .withCause (e ).withDescription (e .getMessage ()).asRuntimeException ();
94108 }
95109 }
96110
97- static NexusTaskToken fromBytes (ByteString serialized ) {
111+ public static NexusTaskToken fromBytes (ByteString serialized ) {
98112 ByteArrayInputStream bin = new ByteArrayInputStream (serialized .toByteArray ());
99113 DataInputStream in = new DataInputStream (bin );
100114 try {
@@ -103,7 +117,8 @@ static NexusTaskToken fromBytes(ByteString serialized) {
103117 String runId = in .readUTF ();
104118 long scheduledEventId = in .readLong ();
105119 int attempt = in .readInt ();
106- return new NexusTaskToken (namespace , workflowId , runId , scheduledEventId , attempt );
120+ boolean isCancel = in .readBoolean ();
121+ return new NexusTaskToken (namespace , workflowId , runId , scheduledEventId , attempt , isCancel );
107122 } catch (IOException e ) {
108123 throw Status .INVALID_ARGUMENT
109124 .withCause (e )
0 commit comments