Skip to content

Commit 35cbbea

Browse files
committed
Use new exceptions
1 parent 9c7b77e commit 35cbbea

File tree

3 files changed

+23
-13
lines changed

3 files changed

+23
-13
lines changed

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

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
import io.eigr.spawn.api.actors.annotations.stateless.StatelessNamedActor;
1111
import io.eigr.spawn.api.actors.annotations.stateless.StatelessPooledActor;
1212
import io.eigr.spawn.api.actors.annotations.stateless.StatelessUnNamedActor;
13+
import io.eigr.spawn.api.exceptions.ActorCreationException;
14+
import io.eigr.spawn.api.exceptions.ActorRegistrationException;
15+
import io.eigr.spawn.api.exceptions.SpawnException;
1316
import io.eigr.spawn.internal.Entity;
1417
import io.eigr.spawn.internal.transport.client.OkHttpSpawnClient;
1518
import io.eigr.spawn.internal.transport.client.SpawnClient;
@@ -75,9 +78,10 @@ public String getSystem() {
7578
* @param system ActorSystem name of the actor that this ActorRef instance should represent
7679
* @param name the name of the actor that this ActorRef instance should represent
7780
* @return the ActorRef instance
81+
* @throws {@link io.eigr.spawn.api.exceptions.ActorCreationException}
7882
* @since 0.0.1
7983
*/
80-
public ActorRef createActorRef(String system, String name) throws Exception {
84+
public ActorRef createActorRef(String system, String name) throws ActorCreationException {
8185
return ActorRef.of(this.client, system, name);
8286
}
8387

@@ -89,9 +93,10 @@ public ActorRef createActorRef(String system, String name) throws Exception {
8993
* @param name the name of the actor that this ActorRef instance should represent
9094
* @param parent the name of the unnamed parent actor
9195
* @return the ActorRef instance
96+
* @throws {@link io.eigr.spawn.api.exceptions.ActorCreationException}
9297
* @since 0.0.1
9398
*/
94-
public ActorRef createActorRef(String system, String name, String parent) throws Exception {
99+
public ActorRef createActorRef(String system, String name, String parent) throws ActorCreationException {
95100
return ActorRef.of(this.client, system, name, parent);
96101
}
97102

@@ -105,14 +110,18 @@ public void start() throws Exception {
105110
registerActorSystem();
106111
}
107112

108-
private void startServer() throws IOException {
109-
HttpServer httpServer = HttpServer.create(new InetSocketAddress(this.host, this.port), 0);
110-
httpServer.createContext(HTTP_ACTORS_ACTIONS_URI, new ActorServiceHandler(this, this.entities));
111-
httpServer.setExecutor(this.executor);
112-
httpServer.start();
113+
private void startServer() throws SpawnException {
114+
try {
115+
HttpServer httpServer = HttpServer.create(new InetSocketAddress(this.host, this.port), 0);
116+
httpServer.createContext(HTTP_ACTORS_ACTIONS_URI, new ActorServiceHandler(this, this.entities));
117+
httpServer.setExecutor(this.executor);
118+
httpServer.start();
119+
}catch (IOException ex) {
120+
throw new SpawnException(ex);
121+
}
113122
}
114123

115-
private void registerActorSystem() throws Exception {
124+
private void registerActorSystem() throws ActorRegistrationException {
116125
ActorOuterClass.Registry registry = ActorOuterClass.Registry.newBuilder()
117126
.putAllActors(getActors(this.entities))
118127
.build();

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
package io.eigr.spawn;
22

3-
import io.eigr.spawn.api.InvocationOpts;
4-
import io.eigr.spawn.api.Spawn;
53
import io.eigr.spawn.api.ActorRef;
4+
import io.eigr.spawn.api.Spawn;
65
import io.eigr.spawn.api.TransportOpts;
6+
import io.eigr.spawn.api.exceptions.ActorCreationException;
7+
import io.eigr.spawn.api.exceptions.ActorInvocationException;
78
import io.eigr.spawn.java.test.domain.Actor;
89
import io.eigr.spawn.test.actors.JoeActor;
910
import org.junit.Before;
1011
import org.junit.Test;
1112

12-
import java.time.Duration;
1313
import java.util.Optional;
1414

1515
import static org.junit.Assert.assertEquals;
@@ -36,7 +36,7 @@ public void before() throws Exception {
3636
}
3737

3838
@Test
39-
public void testApp() throws Exception {
39+
public void testApp() throws ActorCreationException, ActorInvocationException {
4040
ActorRef joeActor = spawnSystem.createActorRef("spawn-system", "test_joe");
4141
assertNotNull(joeActor);
4242

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.eigr.spawn.api.actors.workflows.Forward;
99
import io.eigr.spawn.api.actors.workflows.Pipe;
1010
import io.eigr.spawn.api.actors.workflows.SideEffect;
11+
import io.eigr.spawn.api.exceptions.SpawnException;
1112
import io.eigr.spawn.java.test.domain.Actor;
1213
import io.eigr.spawn.test.actors.JoeActor;
1314
import org.junit.Before;
@@ -20,7 +21,7 @@ public class WorkflowTest {
2021
private ActorRef joeActorRef;
2122
private Spawn spawnSystem;
2223
@Before
23-
public void before() throws Exception {
24+
public void before() throws SpawnException {
2425
spawnSystem = new Spawn.SpawnSystem()
2526
.create("spawn-system")
2627
.withActor(JoeActor.class)

0 commit comments

Comments
 (0)