27
27
import java .util .Objects ;
28
28
import javax .annotation .Nonnull ;
29
29
30
- class NexusTaskToken {
30
+ public class NexusTaskToken {
31
31
32
- @ Nonnull private final ExecutionId executionId ;
33
- private final long scheduledEventId ;
32
+ @ Nonnull private final NexusOperationRef ref ;
34
33
private final int attempt ;
34
+ private final boolean isCancel ;
35
35
36
36
NexusTaskToken (
37
37
@ Nonnull String namespace ,
38
38
@ Nonnull WorkflowExecution execution ,
39
39
long scheduledEventId ,
40
- int attempt ) {
40
+ int attempt ,
41
+ boolean isCancel ) {
41
42
this (
42
43
new ExecutionId (Objects .requireNonNull (namespace ), Objects .requireNonNull (execution )),
43
44
scheduledEventId ,
44
- attempt );
45
+ attempt ,
46
+ isCancel );
45
47
}
46
48
47
49
NexusTaskToken (
48
50
@ Nonnull String namespace ,
49
51
@ Nonnull String workflowId ,
50
52
@ Nonnull String runId ,
51
53
long scheduledEventId ,
52
- int attempt ) {
54
+ int attempt ,
55
+ boolean isCancel ) {
53
56
this (
54
57
namespace ,
55
58
WorkflowExecution .newBuilder ()
56
59
.setWorkflowId (Objects .requireNonNull (workflowId ))
57
60
.setRunId (Objects .requireNonNull (runId ))
58
61
.build (),
59
62
scheduledEventId ,
60
- attempt );
63
+ attempt ,
64
+ isCancel );
61
65
}
62
66
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 );
67
73
}
68
74
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 ;
71
79
}
72
80
73
- public long getScheduledEventId () {
74
- return scheduledEventId ;
81
+ public NexusOperationRef getOperationRef () {
82
+ return ref ;
75
83
}
76
84
77
85
public long getAttempt () {
78
86
return attempt ;
79
87
}
80
88
89
+ public boolean isCancel () {
90
+ return isCancel ;
91
+ }
92
+
81
93
/** Used for task tokens. */
82
94
public ByteString toBytes () {
83
95
try (ByteArrayOutputStream bout = new ByteArrayOutputStream ();
84
96
DataOutputStream out = new DataOutputStream (bout )) {
97
+ ExecutionId executionId = ref .getExecutionId ();
85
98
out .writeUTF (executionId .getNamespace ());
86
99
WorkflowExecution execution = executionId .getExecution ();
87
100
out .writeUTF (execution .getWorkflowId ());
88
101
out .writeUTF (execution .getRunId ());
89
- out .writeLong (scheduledEventId );
102
+ out .writeLong (ref . getScheduledEventId () );
90
103
out .writeInt (attempt );
104
+ out .writeBoolean (isCancel );
91
105
return ByteString .copyFrom (bout .toByteArray ());
92
106
} catch (IOException e ) {
93
107
throw Status .INTERNAL .withCause (e ).withDescription (e .getMessage ()).asRuntimeException ();
94
108
}
95
109
}
96
110
97
- static NexusTaskToken fromBytes (ByteString serialized ) {
111
+ public static NexusTaskToken fromBytes (ByteString serialized ) {
98
112
ByteArrayInputStream bin = new ByteArrayInputStream (serialized .toByteArray ());
99
113
DataInputStream in = new DataInputStream (bin );
100
114
try {
@@ -103,7 +117,8 @@ static NexusTaskToken fromBytes(ByteString serialized) {
103
117
String runId = in .readUTF ();
104
118
long scheduledEventId = in .readLong ();
105
119
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 );
107
122
} catch (IOException e ) {
108
123
throw Status .INVALID_ARGUMENT
109
124
.withCause (e )
0 commit comments