Skip to content

Commit ffef5ef

Browse files
committed
Fix. Call to unnamed actor
1 parent e285523 commit ffef5ef

File tree

3 files changed

+20
-11
lines changed

3 files changed

+20
-11
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ The second thing we have to do is add the spawn dependency to the project.
9090
<dependency>
9191
<groupId>com.github.eigr</groupId>
9292
<artifactId>spawn-java-std-sdk</artifactId>
93-
<version>v0.3.4</version>
93+
<version>v0.3.5</version>
9494
</dependency>
9595
```
9696
We're also going to configure a few things for our application build to work, including compiling the protobuf files.
@@ -124,7 +124,7 @@ See below a full example of the pom.xml file:
124124
<dependency>
125125
<groupId>com.github.eigr</groupId>
126126
<artifactId>spawn-java-std-sdk</artifactId>
127-
<version>v0.3.4</version>
127+
<version>v0.3.5</version>
128128
</dependency>
129129
<dependency>
130130
<groupId>ch.qos.logback</groupId>

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>io.eigr.spawn</groupId>
55
<artifactId>spawn-java-std-sdk</artifactId>
66
<packaging>jar</packaging>
7-
<version>0.3.4</version>
7+
<version>0.3.5</version>
88
<name>spawn-java-std-sdk</name>
99
<url>http://maven.apache.org</url>
1010

src/main/java/io/eigr/spawn/internal/handlers/ActorServiceHandler.java

+17-8
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
import io.eigr.spawn.api.Value;
1313
import io.eigr.spawn.api.actors.ActorContext;
1414
import io.eigr.spawn.api.actors.ActorFactory;
15-
import io.eigr.spawn.api.exceptions.ActorInvokeException;
1615
import io.eigr.spawn.api.actors.workflows.Broadcast;
1716
import io.eigr.spawn.api.actors.workflows.Forward;
1817
import io.eigr.spawn.api.actors.workflows.Pipe;
1918
import io.eigr.spawn.api.actors.workflows.SideEffect;
19+
import io.eigr.spawn.api.exceptions.ActorInvokeException;
2020
import io.eigr.spawn.internal.Entity;
2121
import org.slf4j.Logger;
2222
import org.slf4j.LoggerFactory;
@@ -63,10 +63,10 @@ public void handle(HttpExchange exchange) throws IOException {
6363

6464
if ("POST".equals(exchange.getRequestMethod())) {
6565
Protocol.ActorInvocationResponse response = handleRequest(exchange);
66-
try(OutputStream os = exchange.getResponseBody()) {
66+
try (OutputStream os = exchange.getResponseBody()) {
6767
byte[] bytes = response.toByteArray();
6868
exchange.getResponseHeaders().set("Content-Type", "application/octet-stream");
69-
exchange. sendResponseHeaders(200, bytes.length);
69+
exchange.sendResponseHeaders(200, bytes.length);
7070
os.write(bytes);
7171
}
7272
}
@@ -80,11 +80,12 @@ private Protocol.ActorInvocationResponse handleRequest(HttpExchange exchange) th
8080
ActorId actorId = actorInvocationRequest.getActor();
8181
String actor = actorId.getName();
8282
String system = actorId.getSystem();
83+
String parent = actorId.getParent();
8384
String commandName = actorInvocationRequest.getActionName();
8485

8586
Any value = actorInvocationRequest.getValue();
8687

87-
Optional<Value> maybeValueResponse = callAction(system, actor, commandName, value, context);
88+
Optional<Value> maybeValueResponse = callAction(system, actor, parent, commandName, value, context);
8889
log.info("Actor {} return ActorInvocationResponse for command {}. Result value: {}",
8990
actor, commandName, maybeValueResponse);
9091

@@ -114,8 +115,8 @@ private Protocol.ActorInvocationResponse handleRequest(HttpExchange exchange) th
114115
throw new ActorInvokeException("Action result is null");
115116
}
116117

117-
private Optional<Value> callAction(String system, String actor, String commandName, Any value, Protocol.Context context) {
118-
Optional<Entity> optionalEntity = getEntityByActor(actor);
118+
private Optional<Value> callAction(String system, String actor, String parent, String commandName, Any value, Protocol.Context context) {
119+
Optional<Entity> optionalEntity = getEntityByActor(actor, parent);
119120
if (optionalEntity.isPresent()) {
120121
Entity entity = optionalEntity.get();
121122

@@ -183,10 +184,18 @@ private Object buildInstanceByArg(Entity entity) throws NoSuchMethodException, I
183184
return constructor.newInstance();
184185
}
185186

186-
private Optional<Entity> getEntityByActor(String actor) {
187-
return this.entities.stream()
187+
private Optional<Entity> getEntityByActor(String actor, String parent) {
188+
Optional<Entity> entity = this.entities.stream()
188189
.filter(e -> e.getActorName().equalsIgnoreCase(actor))
189190
.findFirst();
191+
192+
if (entity.isPresent()) {
193+
return entity;
194+
}
195+
196+
return this.entities.stream()
197+
.filter(e -> e.getActorName().equalsIgnoreCase(parent))
198+
.findFirst();
190199
}
191200

192201
private Protocol.Workflow buildWorkflow(Value valueResponse) {

0 commit comments

Comments
 (0)