-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathExecutingService.java
More file actions
117 lines (89 loc) · 2.53 KB
/
ExecutingService.java
File metadata and controls
117 lines (89 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package dev.dbos.transact.execution;
import dev.dbos.transact.DBOS;
import dev.dbos.transact.workflow.Step;
import dev.dbos.transact.workflow.Workflow;
import java.time.Duration;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
interface ExecutingService {
String workflowMethod(String input);
String workflowMethodWithStep(String input);
String stepOne(String input);
String stepTwo(String input);
void sleepingWorkflow(double seconds);
void stepWithNoReturn();
class MyAppException extends Exception {
public MyAppException() {
super("You asked for it");
}
}
void stepThatThrows() throws MyAppException;
void workflowWithNoResultSteps();
}
class ExecutingServiceImpl implements ExecutingService {
private static final Logger logger = LoggerFactory.getLogger(ExecutingServiceImpl.class);
private final DBOS dbos;
private ExecutingService self;
public int step1Count = 0;
public int step2Count = 0;
public ExecutingServiceImpl(DBOS dbos) {
this.dbos = dbos;
}
public void setSelf(ExecutingService self) {
this.self = self;
}
@Override
@Workflow(name = "workflowMethod")
public String workflowMethod(String input) {
return input + input;
}
@Override
@Workflow(name = "workflowMethodWithStep")
public String workflowMethodWithStep(String input) {
String step1Response = self.stepOne("stepOne");
String step2Response = self.stepTwo("stepTwo");
return input + step1Response + step2Response;
}
@Override
@Step(name = "stepOne")
public String stepOne(String input) {
++step1Count;
return input;
}
@Override
@Step(name = "stepTwo")
public String stepTwo(String input) {
++step2Count;
return input;
}
@Override
@Workflow(name = "sleepingWorkflow")
public void sleepingWorkflow(double seconds) {
dbos.sleep(Duration.ofMillis((long) (seconds * 1000)));
}
public int callsToNoReturnStep = 0;
@Override
@Step(name = "noReturn")
public void stepWithNoReturn() {
++callsToNoReturnStep;
return;
}
public int callsToThrowStep = 0;
@Override
@Step(name = "throws")
public void stepThatThrows() throws MyAppException {
++callsToThrowStep;
throw new MyAppException();
}
@Override
@Workflow(name = "workflowWithNoResults")
public void workflowWithNoResultSteps() {
try {
self.stepThatThrows();
} catch (MyAppException e) {
self.stepWithNoReturn();
} catch (Exception e) {
logger.error("Caught an unexpected exception of type: {}", e.getClass().getName(), e);
}
}
}