Skip to content

Commit ae816e0

Browse files
committed
Refactor and adjusts in docs
1 parent d750c45 commit ae816e0

File tree

7 files changed

+259
-95
lines changed

7 files changed

+259
-95
lines changed

README.md

Lines changed: 138 additions & 43 deletions
Large diffs are not rendered by default.

src/main/java/io/eigr/spawn/api/Value.java

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.eigr.spawn.api.actors.workflows.Pipe;
77
import io.eigr.spawn.api.actors.workflows.SideEffect;
88

9+
import java.util.ArrayList;
910
import java.util.List;
1011
import java.util.Objects;
1112
import java.util.Optional;
@@ -14,6 +15,8 @@ public final class Value<S extends GeneratedMessageV3, R extends GeneratedMessag
1415

1516
private S state;
1617
private R response;
18+
19+
private boolean checkpoint;
1720
private Optional<Broadcast<?>> broadcast;
1821
private Optional<Forward> forward;
1922
private Optional<Pipe> pipe;
@@ -24,6 +27,7 @@ public final class Value<S extends GeneratedMessageV3, R extends GeneratedMessag
2427
private Value() {
2528
this.state = null;
2629
this.response = null;
30+
this.checkpoint = false;
2731
this.broadcast = Optional.empty();
2832
this.forward = Optional.empty();
2933
this.pipe = Optional.empty();
@@ -34,20 +38,26 @@ private Value() {
3438
private Value(
3539
R response,
3640
S state,
41+
boolean checkpoint,
3742
Optional<Broadcast<?>> broadcast,
3843
Optional<Forward> forward,
3944
Optional<Pipe> pipe,
4045
Optional<List<SideEffect>> effects,
4146
ResponseType type) {
4247
this.response = response;
4348
this.state = state;
49+
this.checkpoint = checkpoint;
4450
this.broadcast = broadcast;
4551
this.forward = forward;
4652
this.pipe = pipe;
4753
this.effects = effects;
4854
this.type = type;
4955
}
5056

57+
public static <S, V> Value at() {
58+
return new Value();
59+
}
60+
5161
public R getResponse() {
5262
return response;
5363
}
@@ -56,6 +66,10 @@ public S getState() {
5666
return state;
5767
}
5868

69+
public boolean getCheckpoint() {
70+
return checkpoint;
71+
}
72+
5973
public Optional<Broadcast<?>> getBroadcast() {
6074
return broadcast;
6175
}
@@ -76,10 +90,6 @@ public ResponseType getType() {
7690
return type;
7791
}
7892

79-
public static <S, V> Value at() {
80-
return new Value();
81-
}
82-
8393
public Value response(R value) {
8494
this.response = value;
8595
return this;
@@ -90,6 +100,12 @@ public Value state(S state) {
90100
return this;
91101
}
92102

103+
public Value state(S state, boolean checkpoint) {
104+
this.state = state;
105+
this.checkpoint = checkpoint;
106+
return this;
107+
}
108+
93109
public Value flow(Broadcast broadcast) {
94110
this.broadcast = Optional.of(broadcast);
95111
return this;
@@ -106,11 +122,16 @@ public Value flow(Pipe pipe) {
106122
}
107123

108124
public Value flow(SideEffect effect) {
125+
List<SideEffect> ef;
109126
if (this.effects.isPresent()) {
110-
List<SideEffect> ef = this.effects.get();
127+
ef = this.effects.get();
128+
ef.add(effect);
129+
} else {
130+
ef = new ArrayList<>();
111131
ef.add(effect);
112-
this.effects = Optional.of(ef);
113132
}
133+
134+
this.effects = Optional.of(ef);
114135
return this;
115136
}
116137

@@ -120,11 +141,11 @@ public Value flow(List<SideEffect> effects) {
120141
}
121142

122143
public Value reply() {
123-
return new Value(this.response, this.state, this.broadcast, this.forward, this.pipe, this.effects, ResponseType.REPLY);
144+
return new Value(this.response, this.state, this.checkpoint, this.broadcast, this.forward, this.pipe, this.effects, ResponseType.REPLY);
124145
}
125146

126147
public Value noReply() {
127-
return new Value(this.response, this.state, this.broadcast, this.forward, this.pipe, this.effects, ResponseType.NO_REPLY);
148+
return new Value(this.response, this.state, this.checkpoint, this.broadcast, this.forward, this.pipe, this.effects, ResponseType.NO_REPLY);
128149
}
129150

130151
public Value empty() {
@@ -135,6 +156,7 @@ public Value empty() {
135156
public String toString() {
136157
final StringBuilder sb = new StringBuilder("Value{");
137158
sb.append("state=").append(state);
159+
sb.append("checkpoint=").append(checkpoint);
138160
sb.append(", value=").append(response);
139161
sb.append(", broadcast=").append(broadcast);
140162
sb.append(", forward=").append(forward);
@@ -152,6 +174,7 @@ public boolean equals(Object o) {
152174
Value<?, ?> value = (Value<?, ?>) o;
153175
return Objects.equals(state, value.state) &&
154176
Objects.equals(response, value.response) &&
177+
Objects.equals(checkpoint, value.checkpoint) &&
155178
Objects.equals(broadcast, value.broadcast) &&
156179
Objects.equals(forward, value.forward) &&
157180
Objects.equals(pipe, value.pipe) &&
@@ -161,7 +184,7 @@ public boolean equals(Object o) {
161184

162185
@Override
163186
public int hashCode() {
164-
return Objects.hash(state, response, broadcast, forward, pipe, effects, type);
187+
return Objects.hash(state, response, checkpoint, broadcast, forward, pipe, effects, type);
165188
}
166189

167190
enum ResponseType {

src/main/java/io/eigr/spawn/api/actors/ActorRef.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ private ActorRef(SpawnClient client, String system, String name, String parent)
4545
spawnActor();
4646
}
4747
}
48-
49-
48+
5049
public static ActorRef of(SpawnClient client, String system, String name) throws Exception {
5150
return new ActorRef(client, system, name);
5251
}
@@ -114,7 +113,8 @@ private void spawnActor() throws Exception {
114113
this.client.spawn(req);
115114
}
116115

117-
private <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Object invokeActor(String cmd, S argument, Class<T> outputType, Optional<InvocationOpts> options) throws Exception {
116+
private <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Object invokeActor(
117+
String cmd, S argument, Class<T> outputType, Optional<InvocationOpts> options) throws Exception {
118118
Protocol.InvocationRequest.Builder invocationRequestBuilder = Protocol.InvocationRequest.newBuilder();
119119

120120
if (options.isPresent()) {
Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,59 @@
11
package io.eigr.spawn.api.actors.workflows;
22

33
import io.eigr.functions.protocol.Protocol;
4+
import io.eigr.spawn.api.actors.ActorRef;
45

56
import java.util.Objects;
7+
import java.util.StringJoiner;
68

79
public final class Forward {
810

9-
private final String actor;
11+
private final ActorRef actor;
1012

11-
private final String command;
13+
private final String action;
1214

13-
private Forward(String actor, String command) {
15+
private Forward(ActorRef actor, String action) {
1416
this.actor = actor;
15-
this.command = command;
17+
this.action = action;
1618
}
1719

18-
public static Forward to(String actor, String command) {
19-
return new Forward(actor, command);
20+
public static Forward to(ActorRef actor, String action) {
21+
return new Forward(actor, action);
2022
}
2123

22-
public String getActor() {
24+
public ActorRef getActor() {
2325
return actor;
2426
}
2527

28+
public String getAction() {
29+
return action;
30+
}
31+
2632
public Protocol.Forward build() {
2733
return Protocol.Forward.newBuilder()
28-
.setActor(this.actor)
29-
.setActionName(this.command)
34+
.setActor(this.actor.getActorName())
35+
.setActionName(this.action)
3036
.build();
3137
}
3238

39+
@Override
40+
public String toString() {
41+
return new StringJoiner(", ", Forward.class.getSimpleName() + "[", "]")
42+
.add("actor='" + actor + "'")
43+
.add("action='" + action + "'")
44+
.toString();
45+
}
46+
3347
@Override
3448
public boolean equals(Object o) {
3549
if (this == o) return true;
3650
if (o == null || getClass() != o.getClass()) return false;
3751
Forward forward = (Forward) o;
38-
return Objects.equals(actor, forward.actor) && Objects.equals(command, forward.command);
52+
return Objects.equals(actor, forward.actor) && Objects.equals(action, forward.action);
3953
}
4054

4155
@Override
4256
public int hashCode() {
43-
return Objects.hash(actor, command);
57+
return Objects.hash(actor, action);
4458
}
4559
}
Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,61 @@
11
package io.eigr.spawn.api.actors.workflows;
22

33
import io.eigr.functions.protocol.Protocol;
4+
import io.eigr.spawn.api.actors.ActorRef;
5+
import org.jetbrains.annotations.NotNull;
46

57
import java.util.Objects;
8+
import java.util.StringJoiner;
69

710
public final class Pipe {
811

9-
private final String actor;
12+
private final ActorRef actor;
1013

11-
private final String command;
14+
private final String action;
1215

13-
private Pipe(String actor, String command) {
16+
private Pipe(ActorRef actor, String action) {
1417
this.actor = actor;
15-
this.command = command;
18+
this.action = action;
1619
}
1720

18-
public static Pipe to(String actor, String command) {
19-
return new Pipe(actor, command);
21+
@NotNull
22+
public static Pipe to(ActorRef actor, String action) {
23+
return new Pipe(actor, action);
2024
}
2125

22-
public String getActor() {
26+
public ActorRef getActor() {
2327
return actor;
2428
}
2529

26-
public String getCommand() {
27-
return command;
30+
public String getAction() {
31+
return action;
2832
}
2933

3034
public Protocol.Pipe build() {
3135
return Protocol.Pipe.newBuilder()
32-
.setActor(this.actor)
33-
.setActionName(this.command)
36+
.setActor(this.actor.getActorName())
37+
.setActionName(this.action)
3438
.build();
3539
}
3640

41+
@Override
42+
public String toString() {
43+
return new StringJoiner(", ", Pipe.class.getSimpleName() + "[", "]")
44+
.add("actor='" + actor + "'")
45+
.add("action='" + action + "'")
46+
.toString();
47+
}
48+
3749
@Override
3850
public boolean equals(Object o) {
3951
if (this == o) return true;
4052
if (o == null || getClass() != o.getClass()) return false;
4153
Pipe pipe = (Pipe) o;
42-
return Objects.equals(actor, pipe.actor) && Objects.equals(command, pipe.command);
54+
return Objects.equals(actor, pipe.actor) && Objects.equals(action, pipe.action);
4355
}
4456

4557
@Override
4658
public int hashCode() {
47-
return Objects.hash(actor, command);
59+
return Objects.hash(actor, action);
4860
}
4961
}

0 commit comments

Comments
 (0)