Skip to content

Commit b8dbe8c

Browse files
committed
Add lookup option
1 parent e6fe124 commit b8dbe8c

File tree

6 files changed

+39
-57
lines changed

6 files changed

+39
-57
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ The second thing we have to do is add the spawn dependency to the project.
9393
<dependency>
9494
<groupId>com.github.eigr</groupId>
9595
<artifactId>spawn-java-std-sdk</artifactId>
96-
<version>v0.8.3</version>
96+
<version>v0.8.5</version>
9797
</dependency>
9898
```
9999
We're also going to configure a few things for our application build to work, including compiling the protobuf files.
@@ -127,7 +127,7 @@ See below a full example of the pom.xml file:
127127
<dependency>
128128
<groupId>com.github.eigr</groupId>
129129
<artifactId>spawn-java-std-sdk</artifactId>
130-
<version>v0.8.3</version>
130+
<version>v0.8.5</version>
131131
</dependency>
132132
<dependency>
133133
<groupId>ch.qos.logback</groupId>

pom.xml

Lines changed: 1 addition & 1 deletion
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.8.3</version>
7+
<version>0.8.5</version>
88
<name>spawn-java-std-sdk</name>
99
<url>http://maven.apache.org</url>
1010

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

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,36 @@ public final class ActorIdentity {
99
private final String name;
1010
private final Optional<String> maybeParent;
1111

12-
private ActorIdentity(String system, String name, String parent){
12+
private final boolean lookup;
13+
14+
private ActorIdentity(String system, String name, String parent, boolean lookup){
1315
this.system = system;
1416
this.name = name;
1517
this.maybeParent = Optional.ofNullable(parent);
18+
this.lookup = lookup;
1619
}
1720

18-
private ActorIdentity(String system, String name){
21+
private ActorIdentity(String system, String name, boolean lookup){
1922
this.system = system;
2023
this.name = name;
2124
this.maybeParent = Optional.empty();
25+
this.lookup = lookup;
2226
}
2327

2428
public static ActorIdentity of(String system, String name) {
25-
return new ActorIdentity(system, name);
29+
return new ActorIdentity(system, name, true);
2630
}
2731

2832
public static ActorIdentity of(String system, String name, String parent) {
29-
return new ActorIdentity(system, name, parent);
33+
return new ActorIdentity(system, name, parent, true);
34+
}
35+
36+
public static ActorIdentity of(String system, String name, boolean lookup) {
37+
return new ActorIdentity(system, name, lookup);
38+
}
39+
40+
public static ActorIdentity of(String system, String name, String parent, boolean lookup) {
41+
return new ActorIdentity(system, name, parent, lookup);
3042
}
3143

3244
public String getSystem() {
@@ -49,17 +61,21 @@ public boolean isParent() {
4961
return this.maybeParent.isPresent();
5062
}
5163

64+
public boolean hasLookup() {
65+
return lookup;
66+
}
67+
5268
@Override
5369
public boolean equals(Object o) {
5470
if (this == o) return true;
5571
if (o == null || getClass() != o.getClass()) return false;
56-
ActorIdentity actorIdentity = (ActorIdentity) o;
57-
return system.equals(actorIdentity.system) && name.equals(actorIdentity.name) && maybeParent.equals(actorIdentity.maybeParent);
72+
ActorIdentity that = (ActorIdentity) o;
73+
return lookup == that.lookup && system.equals(that.system) && name.equals(that.name) && maybeParent.equals(that.maybeParent);
5874
}
5975

6076
@Override
6177
public int hashCode() {
62-
return Objects.hash(system, name, maybeParent);
78+
return Objects.hash(system, name, maybeParent, lookup);
6379
}
6480

6581
@Override
@@ -68,6 +84,7 @@ public String toString() {
6884
.add("system='" + system + "'")
6985
.add("name='" + name + "'")
7086
.add("maybeParent=" + maybeParent)
87+
.add("lookup=" + lookup)
7188
.toString();
7289
}
7390
}

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

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -29,54 +29,23 @@ private ActorRef(ActorOuterClass.ActorId actorId, SpawnClient client) {
2929
this.actorId = actorId;
3030
}
3131

32-
/**
33-
* <p>This method is responsible for creating instances of the ActorRef class
34-
* </p>
35-
*
36-
* @param client is the client part of the Spawn protocol and is responsible for communicating with the Proxy.
37-
* @param identity ActorIdentity name of the actor that this ActorRef instance should represent
38-
* @return the ActorRef instance
39-
* @since 0.0.1
40-
*/
41-
protected static ActorRef of(SpawnClient client, Cache<ActorOuterClass.ActorId, ActorRef> cache, ActorIdentity identity) throws ActorCreationException {
42-
ActorOuterClass.ActorId actorId;
43-
44-
if (identity.isParent()) {
45-
actorId = buildActorId(identity.getSystem(), identity.getName(), identity.getParent());
46-
47-
spawnActor(actorId, client);
48-
} else {
49-
actorId = buildActorId(identity.getSystem(), identity.getName());
50-
}
51-
52-
ActorRef ref = cache.getIfPresent(actorId);
53-
if (Objects.nonNull(ref)) {
54-
return ref;
55-
}
56-
57-
ref = new ActorRef(actorId, client);
58-
cache.put(actorId, ref);
59-
return ref;
60-
}
61-
6232
/**
6333
* <p>This method is responsible for creating instances of the ActorRef class when Actor is a UnNamed actor.
6434
* </p>
6535
*
6636
* @param client is the client part of the Spawn protocol and is responsible for communicating with the Proxy.
6737
* @param identity ActorIdentity name of the actor that this ActorRef instance should represent
68-
* @param dispatchParent call proxy to spawn proxy or not
6938
* @return the ActorRef instance
7039
* @since 0.0.1
7140
*/
72-
protected static ActorRef of(SpawnClient client, Cache<ActorOuterClass.ActorId, ActorRef> cache, ActorIdentity identity, boolean dispatchParent) throws ActorCreationException {
41+
protected static ActorRef of(SpawnClient client, Cache<ActorOuterClass.ActorId, ActorRef> cache, ActorIdentity identity) throws ActorCreationException {
7342
ActorOuterClass.ActorId actorId = buildActorId(identity.getSystem(), identity.getName(), identity.getParent());
7443
ActorRef ref = cache.getIfPresent(actorId);
7544
if (Objects.nonNull(ref)) {
7645
return ref;
7746
}
7847

79-
if (dispatchParent) {
48+
if (identity.hasLookup()) {
8049
spawnActor(actorId, client);
8150
}
8251

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ public int getTerminationGracePeriodSeconds() {
9393
*
9494
* @param identity the name of the actor that this ActorRef instance should represent
9595
* @return the ActorRef instance
96-
* @throws {@link io.eigr.spawn.api.exceptions.ActorCreationException}
9796
* @since 0.0.1
9897
*/
9998
public ActorRef createActorRef(ActorIdentity identity) throws ActorCreationException {
@@ -123,7 +122,14 @@ public Stream<ActorRef> createMultiActorRefs(List<ActorIdentity> identities) thr
123122

124123
return identities.stream().map(identity -> {
125124
try {
126-
return identity.isParent() ? ActorRef.of(this.client, this.actorIdCache, identity, false) : ActorRef.of(this.client, this.actorIdCache, identity);
125+
if (identity.isParent()) {
126+
return ActorRef.of(
127+
this.client,
128+
this.actorIdCache,
129+
ActorIdentity.of(identity.getSystem(), identity.getName(), identity.getParent(), false));
130+
}
131+
132+
return ActorRef.of(this.client, this.actorIdCache, identity);
127133
} catch (ActorCreationException e) {
128134
throw new SpawnFailureException(e);
129135
}

src/main/java/io/eigr/spawn/internal/transport/client/OkHttpSpawnClient.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,16 @@ public final class OkHttpSpawnClient implements SpawnClient {
2424
private final int proxyPort;
2525
private final OkHttpClient client;
2626

27-
private final OkHttpClient spawnClient;
28-
2927
public OkHttpSpawnClient(String system, String proxyHost, int proxyPort) {
3028
this.system = system;
3129
this.proxyHost = proxyHost;
3230
this.proxyPort = proxyPort;
3331
this.client = new OkHttpClient.Builder()
34-
.connectTimeout(60, TimeUnit.SECONDS)
35-
.readTimeout(60, TimeUnit.SECONDS)
36-
.writeTimeout(60, TimeUnit.SECONDS)
37-
.callTimeout(200, TimeUnit.SECONDS)
38-
.retryOnConnectionFailure(true)
39-
.connectionPool(new ConnectionPool(256, 100, TimeUnit.SECONDS))
40-
.build();
41-
42-
this.spawnClient = new OkHttpClient.Builder()
4332
.connectTimeout(120, TimeUnit.SECONDS)
4433
.readTimeout(120, TimeUnit.SECONDS)
4534
.writeTimeout(120, TimeUnit.SECONDS)
4635
.callTimeout(400, TimeUnit.SECONDS)
36+
.retryOnConnectionFailure(true)
4737
.connectionPool(new ConnectionPool(256, 100, TimeUnit.SECONDS))
4838
.build();
4939
}
@@ -73,7 +63,7 @@ public Protocol.SpawnResponse spawn(Protocol.SpawnRequest registration) throws A
7363
.url(makeSpawnURLFrom(registration.getActors(0).getSystem()))
7464
.post(body).build();
7565

76-
Call call = spawnClient.newCall(request);
66+
Call call = client.newCall(request);
7767
try (Response response = call.execute()) {
7868
assert response.body() != null;
7969
return io.eigr.functions.protocol.Protocol.SpawnResponse.parseFrom(

0 commit comments

Comments
 (0)