Skip to content

Commit 492c4b0

Browse files
committed
Exceptions refactoring.
1 parent e147f48 commit 492c4b0

File tree

3 files changed

+32
-7
lines changed

3 files changed

+32
-7
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.eigr.functions.protocol.actors.ActorOuterClass;
1010
import io.eigr.spawn.api.exceptions.ActorCreationException;
1111
import io.eigr.spawn.api.exceptions.ActorInvocationException;
12+
import io.eigr.spawn.api.exceptions.ActorNotFoundException;
1213
import io.eigr.spawn.api.exceptions.SpawnException;
1314
import io.eigr.spawn.internal.transport.client.SpawnClient;
1415

@@ -119,7 +120,7 @@ private static void spawnActor(ActorOuterClass.ActorId actorId, SpawnClient clie
119120
* @return an Optional containing, or not, the response object to the Action call
120121
* @since 0.0.1
121122
*/
122-
public <T extends GeneratedMessageV3> Optional<T> invoke(String action, Class<T> outputType) throws SpawnException {
123+
public <T extends GeneratedMessageV3> Optional<T> invoke(String action, Class<T> outputType) throws ActorInvocationException {
123124
Optional<T> res = invokeActor(action, Empty.getDefaultInstance(), outputType, Optional.empty());
124125
return res.map(outputType::cast);
125126

@@ -137,7 +138,7 @@ public <T extends GeneratedMessageV3> Optional<T> invoke(String action, Class<T>
137138
* @return an Optional containing, or not, the response object to the Action call
138139
* @since 0.0.1
139140
*/
140-
public <T extends GeneratedMessageV3> Optional<T> invoke(String action, Class<T> outputType, InvocationOpts opts) throws SpawnException {
141+
public <T extends GeneratedMessageV3> Optional<T> invoke(String action, Class<T> outputType, InvocationOpts opts) throws ActorInvocationException {
141142
Optional<T> res = invokeActor(action, Empty.getDefaultInstance(), outputType, Optional.ofNullable(opts));
142143
return res.map(outputType::cast);
143144

@@ -154,7 +155,7 @@ public <T extends GeneratedMessageV3> Optional<T> invoke(String action, Class<T>
154155
* @return an Optional containing, or not, the response object to the Action call
155156
* @since 0.0.1
156157
*/
157-
public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T> invoke(String action, S value, Class<T> outputType) throws SpawnException {
158+
public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T> invoke(String action, S value, Class<T> outputType) throws ActorInvocationException {
158159
Optional<T> res = invokeActor(action, value, outputType, Optional.empty());
159160
return res.map(outputType::cast);
160161

@@ -173,7 +174,7 @@ public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T>
173174
* @return an Optional containing, or not, the response object to the Action call
174175
* @since 0.0.1
175176
*/
176-
public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T> invoke(String action, S value, Class<T> outputType, InvocationOpts opts) throws SpawnException {
177+
public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T> invoke(String action, S value, Class<T> outputType, InvocationOpts opts) throws ActorInvocationException {
177178
Optional<T> res = invokeActor(action, value, outputType, Optional.ofNullable(opts));
178179
return res.map(outputType::cast);
179180

@@ -187,7 +188,7 @@ public <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T>
187188
* @param action name of the action to be called.
188189
* @since 0.0.1
189190
*/
190-
public <T extends GeneratedMessageV3> void invokeAsync(String action) throws SpawnException {
191+
public <T extends GeneratedMessageV3> void invokeAsync(String action) throws ActorInvocationException {
191192
InvocationOpts opts = InvocationOpts.builder().async(true).build();
192193
invokeActor(action, Empty.getDefaultInstance(), null, Optional.of(opts));
193194
}
@@ -313,7 +314,7 @@ private <T extends GeneratedMessageV3, S extends GeneratedMessageV3> Optional<T>
313314
this.getActorName(), status.getMessage());
314315
throw new ActorInvocationException(msg);
315316
case ACTOR_NOT_FOUND:
316-
throw new ActorInvocationException("Actor not found.");
317+
throw new ActorNotFoundException("Actor not found.");
317318
case OK:
318319
if (resp.hasValue() && Objects.nonNull(outputType)) {
319320
try {

src/main/java/io/eigr/spawn/api/exceptions/ActorInvocationException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package io.eigr.spawn.api.exceptions;
22

3-
public final class ActorInvocationException extends SpawnException {
3+
public class ActorInvocationException extends SpawnException {
44

55
public ActorInvocationException() {
66
super();
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package io.eigr.spawn.api.exceptions;
2+
3+
/**
4+
* Actor Registration Exception.
5+
*
6+
* @author Paulo H3nrique Alves
7+
*/
8+
public class ActorNotFoundException extends ActorInvocationException {
9+
10+
public ActorNotFoundException() {
11+
super();
12+
}
13+
public ActorNotFoundException(String s) {
14+
super(s);
15+
}
16+
17+
public ActorNotFoundException(String message, Throwable cause) {
18+
super(message, cause);
19+
}
20+
21+
public ActorNotFoundException(Throwable cause) {
22+
super(cause);
23+
}
24+
}

0 commit comments

Comments
 (0)