11package com .uber .cadence .samples .hello ;
22
3+ import static com .uber .cadence .samples .common .SampleConstants .DOMAIN ;
4+
35import com .uber .cadence .activity .ActivityMethod ;
46import com .uber .cadence .client .WorkflowClient ;
57import com .uber .cadence .client .WorkflowOptions ;
68import com .uber .cadence .worker .Worker ;
79import com .uber .cadence .workflow .*;
8-
910import java .time .Duration ;
1011
11- import static com .uber .cadence .samples .common .SampleConstants .DOMAIN ;
12-
13- /**
14- * Demonstrates implementing saga transaction and compensation logic using Cadence.
15- */
12+ /** Demonstrates implementing saga transaction and compensation logic using Cadence. */
1613public class HelloSaga {
1714 static final String TASK_LIST = "HelloSaga" ;
1815
@@ -24,6 +21,7 @@ public interface ChildWorkflowOperation {
2421 public static class ChildWorkflowOperationImpl implements ChildWorkflowOperation {
2522 ActivityOperation activity = Workflow .newActivityStub (ActivityOperation .class );
2623
24+ @ Override
2725 public void execute (int amount ) {
2826 activity .execute (amount );
2927 }
@@ -37,6 +35,7 @@ public interface ChildWorkflowCompensation {
3735 public static class ChildWorkflowCompensationImpl implements ChildWorkflowCompensation {
3836 ActivityOperation activity = Workflow .newActivityStub (ActivityOperation .class );
3937
38+ @ Override
4039 public void compensate (int amount ) {
4140 activity .compensate (amount );
4241 }
@@ -52,22 +51,23 @@ public interface ActivityOperation {
5251
5352 public static class ActivityOperationImpl implements ActivityOperation {
5453
54+ @ Override
5555 public void execute (int amount ) {
5656 System .out .println ("ActivityOperationImpl.execute() is called with amount " + amount );
5757 }
5858
59+ @ Override
5960 public void compensate (int amount ) {
6061 System .out .println ("ActivityCompensationImpl.compensate() is called with amount " + amount );
6162 }
6263 }
6364
6465 public interface SagaWorkflow {
6566 /**
66- * Main saga workflow.
67- * Here we execute activity operation twice (first from a child workflow, second directly using
68- * activity stub), add three compensation functions, and then throws some exception in workflow code.
69- * When we catch the exception, saga.compensate will run the compensation functions according
70- * to the policy specified in SagaOptions.
67+ * Main saga workflow. Here we execute activity operation twice (first from a child workflow,
68+ * second directly using activity stub), add three compensation functions, and then throws some
69+ * exception in workflow code. When we catch the exception, saga.compensate will run the
70+ * compensation functions according to the policy specified in SagaOptions.
7171 */
7272 @ WorkflowMethod
7373 void execute ();
@@ -83,7 +83,8 @@ public void execute() {
8383 // The following demonstrate how to compensate sync invocations.
8484 ChildWorkflowOperation op1 = Workflow .newChildWorkflowStub (ChildWorkflowOperation .class );
8585 op1 .execute (10 );
86- ChildWorkflowCompensation c1 = Workflow .newChildWorkflowStub (ChildWorkflowCompensation .class );
86+ ChildWorkflowCompensation c1 =
87+ Workflow .newChildWorkflowStub (ChildWorkflowCompensation .class );
8788 saga .addCompensation (c1 ::compensate , -10 );
8889
8990 // The following demonstrate how to compensate async invocations.
@@ -94,7 +95,8 @@ public void execute() {
9495 // The following demonstrate the ability of supplying arbitrary lambda as a saga
9596 // compensation function. In production code please always use Workflow.getLogger
9697 // to log messages in workflow code.
97- saga .addCompensation (() -> System .out .println ("Other compensation logic in main workflow." ));
98+ saga .addCompensation (
99+ () -> System .out .println ("Other compensation logic in main workflow." ));
98100 throw new RuntimeException ("some error" );
99101
100102 } catch (Exception e ) {
0 commit comments