Skip to content

Commit 8a224cf

Browse files
authored
Add binaryChecksum support to JDK (#605)
1 parent a6660ee commit 8a224cf

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
package com.uber.cadence.common;
19+
20+
public final class BinaryChecksum {
21+
22+
private static String binaryChecksum;
23+
24+
private BinaryChecksum() {}
25+
26+
public static String getBinaryChecksum() {
27+
// TODO: should set the binaryChecksum to some auto generated value if it's empty
28+
return binaryChecksum;
29+
}
30+
31+
public static synchronized void setBinaryChecksum(String checksum) {
32+
if (binaryChecksum != null || checksum == null || checksum.isEmpty()) {
33+
return;
34+
}
35+
binaryChecksum = checksum;
36+
}
37+
}

src/main/java/com/uber/cadence/internal/worker/WorkflowPollTask.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.uber.cadence.PollForDecisionTaskResponse;
2323
import com.uber.cadence.ServiceBusyError;
2424
import com.uber.cadence.TaskList;
25+
import com.uber.cadence.common.BinaryChecksum;
2526
import com.uber.cadence.internal.metrics.MetricsTag;
2627
import com.uber.cadence.internal.metrics.MetricsType;
2728
import com.uber.cadence.serviceclient.IWorkflowService;
@@ -64,6 +65,7 @@ public PollForDecisionTaskResponse poll() throws TException {
6465
PollForDecisionTaskRequest pollRequest = new PollForDecisionTaskRequest();
6566
pollRequest.setDomain(domain);
6667
pollRequest.setIdentity(identity);
68+
pollRequest.setBinaryChecksum(BinaryChecksum.getBinaryChecksum());
6769

6870
TaskList tl = new TaskList();
6971
tl.setName(taskList);

src/main/java/com/uber/cadence/internal/worker/WorkflowWorker.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.uber.cadence.WorkflowExecutionStartedEventAttributes;
3434
import com.uber.cadence.WorkflowQuery;
3535
import com.uber.cadence.WorkflowType;
36+
import com.uber.cadence.common.BinaryChecksum;
3637
import com.uber.cadence.common.WorkflowExecutionHistory;
3738
import com.uber.cadence.internal.common.RpcRetryer;
3839
import com.uber.cadence.internal.common.WorkflowExecutionUtils;
@@ -248,6 +249,7 @@ private void sendReply(
248249
if (taskCompleted != null) {
249250
taskCompleted.setIdentity(options.getIdentity());
250251
taskCompleted.setTaskToken(task.getTaskToken());
252+
taskCompleted.setBinaryChecksum(BinaryChecksum.getBinaryChecksum());
251253
RpcRetryer.retry(
252254
() -> {
253255
RespondDecisionTaskCompletedResponse taskCompletedResponse = null;
@@ -321,6 +323,7 @@ private void sendReply(
321323
if (taskFailed != null) {
322324
taskFailed.setIdentity(options.getIdentity());
323325
taskFailed.setTaskToken(task.getTaskToken());
326+
taskFailed.setBinaryChecksum(BinaryChecksum.getBinaryChecksum());
324327
RpcRetryer.retry(() -> service.RespondDecisionTaskFailed(taskFailed));
325328
} else {
326329
RespondQueryTaskCompletedRequest queryCompleted = response.getQueryCompleted();
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Modifications copyright (C) 2017 Uber Technologies, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. A copy of the License is
8+
* located at
9+
*
10+
* http://aws.amazon.com/apache2.0
11+
*
12+
* or in the "license" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
package com.uber.cadence.common;
19+
20+
import org.junit.Assert;
21+
import org.junit.Test;
22+
23+
public class BinaryChecksumTest {
24+
@Test
25+
public void testSetBinaryChecksum() {
26+
BinaryChecksum.setBinaryChecksum("123");
27+
BinaryChecksum.setBinaryChecksum("456");
28+
Assert.assertEquals("123", BinaryChecksum.getBinaryChecksum());
29+
}
30+
}

0 commit comments

Comments
 (0)