Skip to content

Commit 4464db2

Browse files
author
Artur Ciocanu
committed
Convert workflow abstract class to interface
Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>
1 parent 59602f1 commit 4464db2

File tree

14 files changed

+31
-31
lines changed

14 files changed

+31
-31
lines changed

examples/src/main/java/io/dapr/examples/unittesting/DaprWorkflowExampleTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class DaprWorkflowExampleTest {
4242
private static final String noTimeoutWorkflow = "DemoWorkflowNoTimeout";
4343
private static final String workflowDefaultId = "demo-workflow-123";
4444

45-
private class DemoWorkflow extends Workflow {
45+
private class DemoWorkflow implements Workflow {
4646

4747
@Override
4848
public WorkflowStub create() {

examples/src/main/java/io/dapr/examples/workflows/chain/DemoChainWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
1818

19-
public class DemoChainWorkflow extends Workflow {
19+
public class DemoChainWorkflow implements Workflow {
2020
@Override
2121
public WorkflowStub create() {
2222
return ctx -> {

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
1818

19-
public class DemoChildWorkflow extends Workflow {
19+
public class DemoChildWorkflow implements Workflow {
2020
@Override
2121
public WorkflowStub create() {
2222
return ctx -> {

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
1818

19-
public class DemoWorkflow extends Workflow {
19+
public class DemoWorkflow implements Workflow {
2020
@Override
2121
public WorkflowStub create() {
2222
return ctx -> {

examples/src/main/java/io/dapr/examples/workflows/continueasnew/DemoContinueAsNewWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.time.Duration;
2020

21-
public class DemoContinueAsNewWorkflow extends Workflow {
21+
public class DemoContinueAsNewWorkflow implements Workflow {
2222
/*
2323
Compared with a CRON schedule, this periodic workflow example will never overlap.
2424
For example, a CRON schedule that executes a cleanup every hour will execute it at 1:00, 2:00, 3:00 etc.

examples/src/main/java/io/dapr/examples/workflows/externalevent/DemoExternalEventWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
1818

19-
public class DemoExternalEventWorkflow extends Workflow {
19+
public class DemoExternalEventWorkflow implements Workflow {
2020
@Override
2121
public WorkflowStub create() {
2222
return ctx -> {

examples/src/main/java/io/dapr/examples/workflows/faninout/DemoFanInOutWorkflow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.List;
2121
import java.util.stream.Collectors;
2222

23-
public class DemoFanInOutWorkflow extends Workflow {
23+
public class DemoFanInOutWorkflow implements Workflow {
2424
@Override
2525
public WorkflowStub create() {
2626
return ctx -> {

sdk-workflows/src/main/java/io/dapr/workflows/Workflow.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@
2121
/**
2222
* Common interface for workflow implementations.
2323
*/
24-
public abstract class Workflow {
25-
public Workflow() {
26-
}
27-
24+
public interface Workflow {
2825
/**
2926
* Executes the workflow logic.
3027
*
3128
* @return A WorkflowStub.
3229
*/
33-
public abstract WorkflowStub create();
30+
WorkflowStub create();
3431

3532
/**
3633
* Executes the workflow logic.
@@ -39,7 +36,7 @@ public Workflow() {
3936
* getting information about the current
4037
* workflow instance.
4138
*/
42-
public void run(WorkflowContext ctx) {
39+
default void run(WorkflowContext ctx) {
4340
WorkflowStub stub = this.create();
4441

4542
if (!this.isSagaEnabled()) {
@@ -68,7 +65,7 @@ public void run(WorkflowContext ctx) {
6865
}
6966
}
7067

71-
public boolean isSagaEnabled() {
68+
default boolean isSagaEnabled() {
7269
return this.getSagaOption() != null;
7370
}
7471

@@ -77,7 +74,7 @@ public boolean isSagaEnabled() {
7774
*
7875
* @return saga configuration
7976
*/
80-
public SagaOption getSagaOption() {
77+
default SagaOption getSagaOption() {
8178
// by default, saga is disabled
8279
return null;
8380
}

sdk-workflows/src/main/java/io/dapr/workflows/WorkflowActivityContext.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
114
package io.dapr.workflows;
215

316
public interface WorkflowActivityContext {

sdk-workflows/src/test/java/io/dapr/workflows/WorkflowTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public void testWorkflow_WithSaga_compensateFaile() {
162162
verify(sagaContext, times(1)).compensate();
163163
}
164164

165-
public static class WorkflowWithoutSaga extends Workflow {
165+
public static class WorkflowWithoutSaga implements Workflow {
166166
private final WorkflowStub stub;
167167

168168
public WorkflowWithoutSaga(WorkflowStub stub) {
@@ -175,7 +175,7 @@ public WorkflowStub create() {
175175
}
176176
}
177177

178-
public static class WorkflowWithSaga extends Workflow {
178+
public static class WorkflowWithSaga implements Workflow {
179179
private final WorkflowStub stub;
180180

181181
public WorkflowWithSaga(WorkflowStub stub) {

0 commit comments

Comments
 (0)