I guess this is due to the await block. Is there better way to do it? Need to make the boolean isWorkflowDone thread safe from multiple access from threads. Please provide your valuable feedback.
public class GenericWorkflowImpl implements GenericWorkflow {
private boolean isWorkflowDone = false;
private final RetryOptions retryoptions = RetryOptions.newBuilder()
.setInitialInterval(Duration.ofSeconds(1))
.setMaximumInterval(Duration.ofSeconds(100))
.setBackoffCoefficient(2)
.setMaximumAttempts(10)
.build();
private final ActivityOptions options = ActivityOptions.newBuilder()
.setStartToCloseTimeout(Duration.ofSeconds(30))
.setRetryOptions(retryoptions)
.setCancellationType(ActivityCancellationType.TRY_CANCEL)
.build();
private final GenericActivity genericActivity = Workflow.newActivityStub(GenericActivity.class, options);
@Override
public void start(final WorkflowType workflowType, final String taskType, final TaskInfo payload) {
genericActivity.createNewTask(workflowType, taskType, payload);
Workflow.await(() -> isWorkflowDone);
}
@Override
public void approveChange() {
genericActivity.approveTaskChange();
genericActivity.updateTaskStatusChange();
this.isWorkflowDone = true;
}
@Override
public void rejectChange() {
CancellationScope scope = Workflow.newCancellationScope(() -> {
genericActivity.updateTaskStatusChange();
});
scope.run();
scope.cancel();
}
}