Skip to content

Commit 673d7b1

Browse files
authored
Merge pull request #2 from h3nrique/main
Update to avoid casts.
2 parents b14d1a8 + ce4fde7 commit 673d7b1

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ protected static ActorRef of(SpawnClient client, String system, String name, Str
9191
* @return an Optional containing, or not, the response object to the Action call
9292
* @since 0.0.1
9393
*/
94-
public <T extends GeneratedMessageV3> Optional<Object> invoke(String action, Class<T> outputType) throws Exception {
95-
Optional<Object> res = invokeActor(action, Empty.getDefaultInstance(), outputType, Optional.empty());
94+
public <T extends GeneratedMessageV3> Optional<T> invoke(String action, Class<T> outputType) throws Exception {
95+
Optional<T> res = invokeActor(action, Empty.getDefaultInstance(), outputType, Optional.empty());
9696
if(res.isPresent() ){
9797
return Optional.of(outputType.cast(res.get()));
9898
}
@@ -111,8 +111,8 @@ public <T extends GeneratedMessageV3> Optional<Object> invoke(String action, Cl
111111
* @return an Optional containing, or not, the response object to the Action call
112112
* @since 0.0.1
113113
*/
114-
public <T extends GeneratedMessageV3> Optional<Object> invoke(String action, Class<T> outputType, InvocationOpts opts) throws Exception {
115-
Optional<Object> res = invokeActor(action, Empty.getDefaultInstance(), outputType, Optional.ofNullable(opts));
114+
public <T extends GeneratedMessageV3> Optional<T> invoke(String action, Class<T> outputType, InvocationOpts opts) throws Exception {
115+
Optional<T> res = invokeActor(action, Empty.getDefaultInstance(), outputType, Optional.ofNullable(opts));
116116
if(res.isPresent() ){
117117
return Optional.of(outputType.cast(res.get()));
118118
}
@@ -130,8 +130,8 @@ public <T extends GeneratedMessageV3> Optional<Object> invoke(String action, Cl
130130
* @return an Optional containing, or not, the response object to the Action call
131131
* @since 0.0.1
132132
*/
133-
public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<Object> invoke(String action, S value, Class<T> outputType) throws Exception {
134-
Optional<Object> res = invokeActor(action, value, outputType, Optional.empty());
133+
public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T> invoke(String action, S value, Class<T> outputType) throws Exception {
134+
Optional<T> res = invokeActor(action, value, outputType, Optional.empty());
135135
if(res.isPresent() ){
136136
return Optional.of(outputType.cast(res.get()));
137137
}
@@ -151,8 +151,8 @@ public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<Obj
151151
* @return an Optional containing, or not, the response object to the Action call
152152
* @since 0.0.1
153153
*/
154-
public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<Object> invoke(String action, S value, Class<T> outputType, InvocationOpts opts) throws Exception {
155-
Optional<Object> res = invokeActor(action, value, outputType, Optional.ofNullable(opts));
154+
public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T> invoke(String action, S value, Class<T> outputType, InvocationOpts opts) throws Exception {
155+
Optional<T> res = invokeActor(action, value, outputType, Optional.ofNullable(opts));
156156
if(res.isPresent() ){
157157
return Optional.of(outputType.cast(res.get()));
158158
}
@@ -248,7 +248,7 @@ public boolean isUnNamedActor() {
248248
return false;
249249
}
250250

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

src/test/java/io/eigr/spawn/SpawnTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ public void testApp() throws Exception {
4242
.setLanguage("erlang")
4343
.build();
4444

45-
Optional<Object> maybeReply =
45+
Optional<Actor.Reply> maybeReply =
4646
joeActor.invoke("setLanguage", msg, Actor.Reply.class);
4747

4848
if (maybeReply.isPresent()) {
49-
Actor.Reply reply = (Actor.Reply) maybeReply.get();
49+
Actor.Reply reply = maybeReply.get();
5050
assertNotNull(reply);
5151
assertEquals("Hello From Java", reply.getResponse());
5252
}

0 commit comments

Comments
 (0)