From 1e2f3f2a9c2838180100a91ddbe538a8167b63c1 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sat, 24 Feb 2024 21:34:19 -0500 Subject: [PATCH 1/4] Scratchpad --- .../io/temporal/samples/hello/Scratchpad.java | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 core/src/main/java/io/temporal/samples/hello/Scratchpad.java diff --git a/core/src/main/java/io/temporal/samples/hello/Scratchpad.java b/core/src/main/java/io/temporal/samples/hello/Scratchpad.java new file mode 100644 index 000000000..95c06de1c --- /dev/null +++ b/core/src/main/java/io/temporal/samples/hello/Scratchpad.java @@ -0,0 +1,74 @@ +package io.temporal.samples.hello; + +import io.temporal.activity.ActivityInterface; +import io.temporal.activity.ActivityOptions; +import io.temporal.api.enums.v1.WorkflowIdReusePolicy; +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.serviceclient.WorkflowServiceStubs; +import io.temporal.worker.Worker; +import io.temporal.worker.WorkerFactory; +import io.temporal.workflow.Workflow; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; +import java.time.Duration; + +public class Scratchpad { + static final String TASK_QUEUE = "ScratchpadTaskQueue"; + static final String WORKFLOW_ID = "ScratchpadWorkflow"; + + @WorkflowInterface + public interface MyWorkflow { + @WorkflowMethod + String getGreeting(String name); + } + + @ActivityInterface + public interface MyActivities { + String composeGreeting(String greeting, String name); + } + + public static class MyWorkflowImpl implements MyWorkflow { + + private final MyActivities activities = + Workflow.newActivityStub( + MyActivities.class, + ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(2)).build()); + + @Override + public String getGreeting(String name) { + return activities.composeGreeting("Hello", name); + } + } + + static class MyActivitiesImpl implements MyActivities { + @Override + public String composeGreeting(String greeting, String name) { + return greeting + " " + name + "!"; + } + } + + public static void main(String[] args) { + WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + WorkflowClient client = WorkflowClient.newInstance(service); + WorkerFactory factory = WorkerFactory.newInstance(client); + Worker worker = factory.newWorker(TASK_QUEUE); + worker.registerWorkflowImplementationTypes(MyWorkflowImpl.class); + worker.registerActivitiesImplementations(new MyActivitiesImpl()); + factory.start(); + MyWorkflow workflow = + client.newWorkflowStub( + MyWorkflow.class, + WorkflowOptions.newBuilder() + .setWorkflowId(WORKFLOW_ID) + .setTaskQueue(TASK_QUEUE) + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING) + .build()); + + String greeting = workflow.getGreeting("World"); + + System.out.println(greeting); + System.exit(0); + } +} From 6c67a07fad3ef429464df2f5bf3862fbdcfba285 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Sun, 29 Sep 2024 17:56:22 -0400 Subject: [PATCH 2/4] basic sample --- .../java/io/temporal/samples/basic/Makefile | 9 ++++ .../io/temporal/samples/basic/MyActivity.java | 30 +++++++++++ .../samples/basic/MyActivityImpl.java | 27 ++++++++++ .../io/temporal/samples/basic/MyStarter.java | 33 ++++++++++++ .../io/temporal/samples/basic/MyWorker.java | 42 ++++++++++++++++ .../io/temporal/samples/basic/MyWorkflow.java | 33 ++++++++++++ .../samples/basic/MyWorkflowImpl.java | 50 +++++++++++++++++++ 7 files changed, 224 insertions(+) create mode 100644 core/src/main/java/io/temporal/samples/basic/Makefile create mode 100644 core/src/main/java/io/temporal/samples/basic/MyActivity.java create mode 100644 core/src/main/java/io/temporal/samples/basic/MyActivityImpl.java create mode 100644 core/src/main/java/io/temporal/samples/basic/MyStarter.java create mode 100644 core/src/main/java/io/temporal/samples/basic/MyWorker.java create mode 100644 core/src/main/java/io/temporal/samples/basic/MyWorkflow.java create mode 100644 core/src/main/java/io/temporal/samples/basic/MyWorkflowImpl.java diff --git a/core/src/main/java/io/temporal/samples/basic/Makefile b/core/src/main/java/io/temporal/samples/basic/Makefile new file mode 100644 index 000000000..a08a3d125 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/basic/Makefile @@ -0,0 +1,9 @@ +worker: + cd $$(git rev-parse --show-toplevel) && \ + ./gradlew -q execute -P mainClass=io.temporal.samples.basic.MyWorker + +run: + cd $$(git rev-parse --show-toplevel) && \ + ./gradlew -q execute -P mainClass=io.temporal.samples.basic.MyStarter + +.PHONY: run worker diff --git a/core/src/main/java/io/temporal/samples/basic/MyActivity.java b/core/src/main/java/io/temporal/samples/basic/MyActivity.java new file mode 100644 index 000000000..a1d6709d4 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/basic/MyActivity.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.basic; + +import io.temporal.activity.ActivityInterface; +import io.temporal.activity.ActivityMethod; + +@ActivityInterface +public interface MyActivity { + + @ActivityMethod + int myActivityMethod(); +} diff --git a/core/src/main/java/io/temporal/samples/basic/MyActivityImpl.java b/core/src/main/java/io/temporal/samples/basic/MyActivityImpl.java new file mode 100644 index 000000000..9ba8e9bcf --- /dev/null +++ b/core/src/main/java/io/temporal/samples/basic/MyActivityImpl.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.basic; + +public class MyActivityImpl implements MyActivity { + @Override + public int myActivityMethod() { + return 7; + } +} diff --git a/core/src/main/java/io/temporal/samples/basic/MyStarter.java b/core/src/main/java/io/temporal/samples/basic/MyStarter.java new file mode 100644 index 000000000..b4f17d115 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/basic/MyStarter.java @@ -0,0 +1,33 @@ +package io.temporal.samples.basic; + +import io.temporal.api.enums.v1.WorkflowIdReusePolicy; +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.serviceclient.WorkflowServiceStubs; + +public class MyStarter { + + static final String WORKFLOW_ID = "wid"; + + public static void main(String[] args) throws Exception { + + WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + + WorkflowClient client = WorkflowClient.newInstance(service); + + WorkflowOptions workflowOptions = + WorkflowOptions.newBuilder() + .setTaskQueue(MyWorker.TASK_QUEUE) + .setWorkflowId(WORKFLOW_ID) + .setWorkflowIdReusePolicy( + WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING) + .build(); + MyWorkflow workflow = client.newWorkflowStub(MyWorkflow.class, workflowOptions); + + WorkflowClient.start(workflow::run); + + int result = workflow.myUpdate(); + System.out.println(result); + System.exit(0); + } +} diff --git a/core/src/main/java/io/temporal/samples/basic/MyWorker.java b/core/src/main/java/io/temporal/samples/basic/MyWorker.java new file mode 100644 index 000000000..e30be7173 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/basic/MyWorker.java @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.basic; + +import io.temporal.client.WorkflowClient; +import io.temporal.serviceclient.WorkflowServiceStubs; +import io.temporal.worker.Worker; +import io.temporal.worker.WorkerFactory; + +public class MyWorker { + static final String TASK_QUEUE = "tq"; + + public static void main(String[] args) throws Exception { + + WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + + WorkflowClient client = WorkflowClient.newInstance(service); + + WorkerFactory factory = WorkerFactory.newInstance(client); + Worker worker = factory.newWorker(TASK_QUEUE); + worker.registerWorkflowImplementationTypes(MyWorkflowImpl.class); + worker.registerActivitiesImplementations(new MyActivityImpl()); + factory.start(); + } +} diff --git a/core/src/main/java/io/temporal/samples/basic/MyWorkflow.java b/core/src/main/java/io/temporal/samples/basic/MyWorkflow.java new file mode 100644 index 000000000..15bed82cf --- /dev/null +++ b/core/src/main/java/io/temporal/samples/basic/MyWorkflow.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.basic; + +import io.temporal.workflow.UpdateMethod; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; + +@WorkflowInterface +public interface MyWorkflow { + @WorkflowMethod + void run(); + + @UpdateMethod + int myUpdate(); +} diff --git a/core/src/main/java/io/temporal/samples/basic/MyWorkflowImpl.java b/core/src/main/java/io/temporal/samples/basic/MyWorkflowImpl.java new file mode 100644 index 000000000..12752f26b --- /dev/null +++ b/core/src/main/java/io/temporal/samples/basic/MyWorkflowImpl.java @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed on + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +package io.temporal.samples.basic; + +import io.temporal.activity.ActivityOptions; +import io.temporal.common.RetryOptions; +import io.temporal.workflow.Workflow; +import java.time.Duration; + +public class MyWorkflowImpl implements MyWorkflow { + + private final MyActivity activity = + Workflow.newActivityStub( + MyActivity.class, + ActivityOptions.newBuilder() + .setStartToCloseTimeout(Duration.ofSeconds(2)) + .setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) + .build()); + + private boolean done; + + @Override + public void run() { + Workflow.await(() -> done); + } + + @Override + public int myUpdate() { + int result = activity.myActivityMethod(); + done = true; + return result; + } +} From 98fac0c481041e44c718e325f17c79a377ca6299 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Mon, 7 Oct 2024 08:13:15 -0400 Subject: [PATCH 3/4] Restart worker automatically --- core/src/main/java/io/temporal/samples/basic/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/io/temporal/samples/basic/Makefile b/core/src/main/java/io/temporal/samples/basic/Makefile index a08a3d125..2c8535ace 100644 --- a/core/src/main/java/io/temporal/samples/basic/Makefile +++ b/core/src/main/java/io/temporal/samples/basic/Makefile @@ -1,6 +1,6 @@ worker: - cd $$(git rev-parse --show-toplevel) && \ - ./gradlew -q execute -P mainClass=io.temporal.samples.basic.MyWorker + ls *.java | entr -r \ + sh -c 'cd $$(git rev-parse --show-toplevel) && ./gradlew -q execute -P mainClass=io.temporal.samples.basic.MyWorker' run: cd $$(git rev-parse --show-toplevel) && \ From 20877270c9b723d40d9762ab5ceeacc04a39872e Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Mon, 7 Oct 2024 11:55:22 -0400 Subject: [PATCH 4/4] workflow timeout and update --- .../io/temporal/samples/basic/MyStarter.java | 1 + .../samples/basic/MyWorkflowImpl.java | 3 +- .../temporal/samples/workflowtimeout/Makefile | 9 +++++ .../samples/workflowtimeout/MyActivity.java | 11 ++++++ .../workflowtimeout/MyActivityImpl.java | 8 ++++ .../samples/workflowtimeout/MyStarter.java | 38 +++++++++++++++++++ .../samples/workflowtimeout/MyWorker.java | 23 +++++++++++ .../samples/workflowtimeout/MyWorkflow.java | 14 +++++++ .../workflowtimeout/MyWorkflowImpl.java | 34 +++++++++++++++++ 9 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 core/src/main/java/io/temporal/samples/workflowtimeout/Makefile create mode 100644 core/src/main/java/io/temporal/samples/workflowtimeout/MyActivity.java create mode 100644 core/src/main/java/io/temporal/samples/workflowtimeout/MyActivityImpl.java create mode 100644 core/src/main/java/io/temporal/samples/workflowtimeout/MyStarter.java create mode 100644 core/src/main/java/io/temporal/samples/workflowtimeout/MyWorker.java create mode 100644 core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflow.java create mode 100644 core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflowImpl.java diff --git a/core/src/main/java/io/temporal/samples/basic/MyStarter.java b/core/src/main/java/io/temporal/samples/basic/MyStarter.java index b4f17d115..c6b00acc9 100644 --- a/core/src/main/java/io/temporal/samples/basic/MyStarter.java +++ b/core/src/main/java/io/temporal/samples/basic/MyStarter.java @@ -21,6 +21,7 @@ public static void main(String[] args) throws Exception { .setWorkflowId(WORKFLOW_ID) .setWorkflowIdReusePolicy( WorkflowIdReusePolicy.WORKFLOW_ID_REUSE_POLICY_TERMINATE_IF_RUNNING) + .setWorkflowRunTimeout(java.time.Duration.ofSeconds(2)) .build(); MyWorkflow workflow = client.newWorkflowStub(MyWorkflow.class, workflowOptions); diff --git a/core/src/main/java/io/temporal/samples/basic/MyWorkflowImpl.java b/core/src/main/java/io/temporal/samples/basic/MyWorkflowImpl.java index 12752f26b..9d04f3925 100644 --- a/core/src/main/java/io/temporal/samples/basic/MyWorkflowImpl.java +++ b/core/src/main/java/io/temporal/samples/basic/MyWorkflowImpl.java @@ -34,7 +34,7 @@ public class MyWorkflowImpl implements MyWorkflow { .setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) .build()); - private boolean done; + private boolean done = false; @Override public void run() { @@ -43,6 +43,7 @@ public void run() { @Override public int myUpdate() { + Workflow.sleep(Duration.ofSeconds(4)); int result = activity.myActivityMethod(); done = true; return result; diff --git a/core/src/main/java/io/temporal/samples/workflowtimeout/Makefile b/core/src/main/java/io/temporal/samples/workflowtimeout/Makefile new file mode 100644 index 000000000..2c8535ace --- /dev/null +++ b/core/src/main/java/io/temporal/samples/workflowtimeout/Makefile @@ -0,0 +1,9 @@ +worker: + ls *.java | entr -r \ + sh -c 'cd $$(git rev-parse --show-toplevel) && ./gradlew -q execute -P mainClass=io.temporal.samples.basic.MyWorker' + +run: + cd $$(git rev-parse --show-toplevel) && \ + ./gradlew -q execute -P mainClass=io.temporal.samples.basic.MyStarter + +.PHONY: run worker diff --git a/core/src/main/java/io/temporal/samples/workflowtimeout/MyActivity.java b/core/src/main/java/io/temporal/samples/workflowtimeout/MyActivity.java new file mode 100644 index 000000000..05ce12c83 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/workflowtimeout/MyActivity.java @@ -0,0 +1,11 @@ +package io.temporal.samples.workflowtimeout; + +import io.temporal.activity.ActivityInterface; +import io.temporal.activity.ActivityMethod; + +@ActivityInterface +public interface MyActivity { + + @ActivityMethod + int myActivityMethod(); +} diff --git a/core/src/main/java/io/temporal/samples/workflowtimeout/MyActivityImpl.java b/core/src/main/java/io/temporal/samples/workflowtimeout/MyActivityImpl.java new file mode 100644 index 000000000..0a66ea77d --- /dev/null +++ b/core/src/main/java/io/temporal/samples/workflowtimeout/MyActivityImpl.java @@ -0,0 +1,8 @@ +package io.temporal.samples.workflowtimeout; + +public class MyActivityImpl implements MyActivity { + @Override + public int myActivityMethod() { + return 7; + } +} diff --git a/core/src/main/java/io/temporal/samples/workflowtimeout/MyStarter.java b/core/src/main/java/io/temporal/samples/workflowtimeout/MyStarter.java new file mode 100644 index 000000000..f71148790 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/workflowtimeout/MyStarter.java @@ -0,0 +1,38 @@ +package io.temporal.samples.workflowtimeout; + +import io.temporal.api.enums.v1.WorkflowIdConflictPolicy; +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.serviceclient.WorkflowServiceStubs; + +public class MyStarter { + + static final String WORKFLOW_ID = "wid"; + + public static void main(String[] args) throws Exception { + + WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + + WorkflowClient client = WorkflowClient.newInstance(service); + + WorkflowOptions workflowOptions = + WorkflowOptions.newBuilder() + .setTaskQueue(MyWorker.TASK_QUEUE) + .setWorkflowId(WORKFLOW_ID) + .setWorkflowIdConflictPolicy( + WorkflowIdConflictPolicy.WORKFLOW_ID_CONFLICT_POLICY_TERMINATE_EXISTING) + .setWorkflowExecutionTimeout(java.time.Duration.ofSeconds(2)) + .build(); + MyWorkflow workflow = client.newWorkflowStub(MyWorkflow.class, workflowOptions); + + WorkflowClient.start(workflow::run); + + int upResult = workflow.myUpdate(); + System.out.println("upResult: " + upResult); + + int wfResult = workflow.run(); + System.out.println("wfResult: " + wfResult); + + System.exit(0); + } +} diff --git a/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorker.java b/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorker.java new file mode 100644 index 000000000..0c20a264d --- /dev/null +++ b/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorker.java @@ -0,0 +1,23 @@ +package io.temporal.samples.workflowtimeout; + +import io.temporal.client.WorkflowClient; +import io.temporal.serviceclient.WorkflowServiceStubs; +import io.temporal.worker.Worker; +import io.temporal.worker.WorkerFactory; + +public class MyWorker { + static final String TASK_QUEUE = "tq"; + + public static void main(String[] args) throws Exception { + + WorkflowServiceStubs service = WorkflowServiceStubs.newLocalServiceStubs(); + + WorkflowClient client = WorkflowClient.newInstance(service); + + WorkerFactory factory = WorkerFactory.newInstance(client); + Worker worker = factory.newWorker(TASK_QUEUE); + worker.registerWorkflowImplementationTypes(MyWorkflowImpl.class); + worker.registerActivitiesImplementations(new MyActivityImpl()); + factory.start(); + } +} diff --git a/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflow.java b/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflow.java new file mode 100644 index 000000000..b1ab8a990 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflow.java @@ -0,0 +1,14 @@ +package io.temporal.samples.workflowtimeout; + +import io.temporal.workflow.UpdateMethod; +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; + +@WorkflowInterface +public interface MyWorkflow { + @WorkflowMethod + int run(); + + @UpdateMethod + int myUpdate(); +} diff --git a/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflowImpl.java b/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflowImpl.java new file mode 100644 index 000000000..db43b55a7 --- /dev/null +++ b/core/src/main/java/io/temporal/samples/workflowtimeout/MyWorkflowImpl.java @@ -0,0 +1,34 @@ +package io.temporal.samples.workflowtimeout; + +import io.temporal.activity.ActivityOptions; +import io.temporal.common.RetryOptions; +import io.temporal.workflow.Workflow; +import java.time.Duration; + +public class MyWorkflowImpl implements MyWorkflow { + + private final MyActivity activity = + Workflow.newActivityStub( + MyActivity.class, + ActivityOptions.newBuilder() + .setStartToCloseTimeout(Duration.ofSeconds(2)) + .setRetryOptions(RetryOptions.newBuilder().setMaximumAttempts(1).build()) + .build()); + + // private boolean done; + + @Override + public int run() { + Workflow.sleep(Duration.ofSeconds(3)); + // Workflow.await(() -> done); + return 8; + } + + @Override + public int myUpdate() { + Workflow.sleep(Duration.ofSeconds(2)); + int result = activity.myActivityMethod(); + // done = true; + return result; + } +}