Skip to content

Commit 25a75ff

Browse files
committed
Initial project commit
1 parent dbf48b0 commit 25a75ff

File tree

8 files changed

+206
-0
lines changed

8 files changed

+206
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
target/
2+
.idea/
23
pom.xml.tag
34
pom.xml.releaseBackup
45
pom.xml.versionsBackup

pom.xml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>io.eigr.spawn</groupId>
5+
<artifactId>spawn-java-std-sdk</artifactId>
6+
<packaging>jar</packaging>
7+
<version>0.5.0</version>
8+
<name>spawn-java-std-sdk</name>
9+
<url>http://maven.apache.org</url>
10+
11+
<dependencies>
12+
<dependency>
13+
<groupId>junit</groupId>
14+
<artifactId>junit</artifactId>
15+
<version>3.8.1</version>
16+
<scope>test</scope>
17+
</dependency>
18+
</dependencies>
19+
</project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package io.eigr.spawn;
2+
3+
public interface Actor {
4+
5+
ActorConfig getConfig();
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package io.eigr.spawn;
2+
3+
public class ActorConfig {
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package io.eigr.spawn;
2+
3+
public final class ActorConfigBuilder {
4+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
package io.eigr.spawn;
2+
3+
import com.sun.net.httpserver.HttpServer;
4+
import io.eigr.spawn.internal.handlers.ActorServiceHandler;
5+
6+
import java.io.IOException;
7+
import java.net.InetSocketAddress;
8+
import java.util.ArrayList;
9+
import java.util.Collection;
10+
import java.util.List;
11+
import java.util.concurrent.Executors;
12+
13+
/**
14+
* Spawn SDK Entrypoint
15+
*/
16+
public final class Spawn {
17+
18+
private String host;
19+
private int port;
20+
private String proxyHost;
21+
private int proxyPort;
22+
23+
private String system;
24+
25+
private List<Actor> actors;
26+
27+
public int getPort() {
28+
return port;
29+
}
30+
31+
public String getProxyHost() {
32+
return proxyHost;
33+
}
34+
35+
public int getProxyPort() {
36+
return proxyPort;
37+
}
38+
public String getSystem() {
39+
return system;
40+
}
41+
42+
public List<Actor> getActors() {
43+
return actors;
44+
}
45+
46+
public void start() throws IOException {
47+
startServer();
48+
registerActorSystem();
49+
}
50+
private void startServer() throws IOException {
51+
HttpServer httpServer = HttpServer.create(new InetSocketAddress(this.port), 0);
52+
httpServer.createContext("/api/v1/actors", new ActorServiceHandler(this.system, this.actors));
53+
httpServer.setExecutor(Executors.newVirtualThreadPerTaskExecutor());
54+
55+
httpServer.start();
56+
}
57+
58+
private void registerActorSystem(){
59+
// TODO register actors on proxy
60+
}
61+
62+
private Spawn(SpawnSystem builder) {
63+
this.port = builder.port;
64+
this.proxyHost = builder.proxyHost;
65+
this.proxyPort = builder.proxyPort;
66+
this.system = builder.system;
67+
this.actors = builder.actors;
68+
}
69+
70+
private static final class SpawnSystem {
71+
private int port = 8091;
72+
private String proxyHost = "127.0.0.1";
73+
private int proxyPort = 9001;
74+
75+
private String system = "spawn-system";
76+
private List<Actor> actors = new ArrayList<>();
77+
78+
public SpawnSystem port(int port) {
79+
this.port = port;
80+
return this;
81+
}
82+
83+
public SpawnSystem proxyHost(String host) {
84+
this.proxyHost = host;
85+
return this;
86+
}
87+
88+
public SpawnSystem proxyPort(int port) {
89+
this.proxyPort = port;
90+
return this;
91+
}
92+
93+
public SpawnSystem of(String system) {
94+
this.system = system;
95+
return this;
96+
}
97+
98+
public SpawnSystem registerActor(Actor actor) {
99+
this.actors.add(actor);
100+
return this;
101+
}
102+
103+
public SpawnSystem registerAllActors(Collection<Actor> actors) {
104+
this.actors.addAll(actors);
105+
return this;
106+
}
107+
108+
public Spawn build() {
109+
return new Spawn(this);
110+
}
111+
112+
}
113+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package io.eigr.spawn.internal.handlers;
2+
3+
import com.sun.net.httpserver.HttpExchange;
4+
import com.sun.net.httpserver.HttpHandler;
5+
import io.eigr.spawn.Actor;
6+
7+
import java.io.IOException;
8+
import java.util.List;
9+
10+
public final class ActorServiceHandler implements HttpHandler {
11+
12+
private String system;
13+
14+
private List<Actor> actors;
15+
16+
public ActorServiceHandler(String system, List<Actor> actors) {
17+
this.system = system;
18+
this.actors = actors;
19+
}
20+
21+
@Override
22+
public void handle(HttpExchange exchange) throws IOException {
23+
24+
}
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package io.eigr.spawn;
2+
3+
import junit.framework.Test;
4+
import junit.framework.TestCase;
5+
import junit.framework.TestSuite;
6+
7+
/**
8+
* Unit test for simple App.
9+
*/
10+
public class SpawnTest
11+
extends TestCase {
12+
/**
13+
* Create the test case
14+
*
15+
* @param testName name of the test case
16+
*/
17+
public SpawnTest(String testName) {
18+
super(testName);
19+
}
20+
21+
/**
22+
* @return the suite of tests being tested
23+
*/
24+
public static Test suite() {
25+
return new TestSuite(SpawnTest.class);
26+
}
27+
28+
/**
29+
* Rigourous Test :-)
30+
*/
31+
public void testApp() {
32+
assertTrue(true);
33+
}
34+
}

0 commit comments

Comments
 (0)