summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/same/TjwsApp.java12
-rw-r--r--same/src/main/java/com/orbekk/same/http/JettyServerContainer.java2
-rw-r--r--same/src/main/java/com/orbekk/same/http/ServerContainer.java8
-rw-r--r--same/src/main/java/com/orbekk/same/http/TjwsServerBuilder.java2
-rw-r--r--same/src/main/java/com/orbekk/same/http/TjwsServerContainer.java18
5 files changed, 35 insertions, 7 deletions
diff --git a/same/src/main/java/com/orbekk/same/TjwsApp.java b/same/src/main/java/com/orbekk/same/TjwsApp.java
index b06322b..c3f1a78 100644
--- a/same/src/main/java/com/orbekk/same/TjwsApp.java
+++ b/same/src/main/java/com/orbekk/same/TjwsApp.java
@@ -1,15 +1,19 @@
package com.orbekk.same;
import com.orbekk.same.http.HelloServlet;
+import com.orbekk.same.http.ServerContainer;
import com.orbekk.same.http.TjwsServerBuilder;
-import com.orbekk.same.http.TjwsServerContainer;
public class TjwsApp {
public static void main(String[] args) {
- TjwsServerContainer server = new TjwsServerBuilder(8080)
+ ServerContainer server = new TjwsServerBuilder(8080)
.withServlet(new HelloServlet(), "/hello")
.build();
- server.start();
- server.join();
+ try {
+ server.start();
+ server.join();
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/same/src/main/java/com/orbekk/same/http/JettyServerContainer.java b/same/src/main/java/com/orbekk/same/http/JettyServerContainer.java
index 34db226..c15d94d 100644
--- a/same/src/main/java/com/orbekk/same/http/JettyServerContainer.java
+++ b/same/src/main/java/com/orbekk/same/http/JettyServerContainer.java
@@ -7,7 +7,7 @@ import org.eclipse.jetty.servlet.ServletContextHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-public class JettyServerContainer {
+public class JettyServerContainer implements ServerContainer {
Logger logger = LoggerFactory.getLogger(getClass());
Server server;
int port;
diff --git a/same/src/main/java/com/orbekk/same/http/ServerContainer.java b/same/src/main/java/com/orbekk/same/http/ServerContainer.java
new file mode 100644
index 0000000..6f87910
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/http/ServerContainer.java
@@ -0,0 +1,8 @@
+package com.orbekk.same.http;
+
+public interface ServerContainer {
+ public abstract int getPort();
+ public abstract void start() throws Exception;
+ public abstract void stop() throws Exception;
+ public abstract void join() throws Exception;
+} \ No newline at end of file
diff --git a/same/src/main/java/com/orbekk/same/http/TjwsServerBuilder.java b/same/src/main/java/com/orbekk/same/http/TjwsServerBuilder.java
index c0aed5a..7a07dbd 100644
--- a/same/src/main/java/com/orbekk/same/http/TjwsServerBuilder.java
+++ b/same/src/main/java/com/orbekk/same/http/TjwsServerBuilder.java
@@ -29,7 +29,7 @@ public class TjwsServerBuilder {
return withServlet(new RpcServlet(server), pathSpec);
}
- public TjwsServerContainer build() {
+ public ServerContainer build() {
TjwsServerContainer server = TjwsServerContainer.create(port);
for (int i = 0; i < servletPaths.size(); i++) {
String path = servletPaths.get(i);
diff --git a/same/src/main/java/com/orbekk/same/http/TjwsServerContainer.java b/same/src/main/java/com/orbekk/same/http/TjwsServerContainer.java
index a38cfac..ec2f2a2 100644
--- a/same/src/main/java/com/orbekk/same/http/TjwsServerContainer.java
+++ b/same/src/main/java/com/orbekk/same/http/TjwsServerContainer.java
@@ -7,7 +7,7 @@ import org.slf4j.LoggerFactory;
import Acme.Serve.Serve;
-public class TjwsServerContainer {
+public class TjwsServerContainer implements ServerContainer {
private static class MyServer extends Serve {
public void join() {
try {
@@ -31,18 +31,34 @@ public class TjwsServerContainer {
this.server = server;
}
+ /* (non-Javadoc)
+ * @see com.orbekk.same.http.ServerContainer#getPort()
+ */
+ @Override
public int getPort() {
return (Integer)this.server.getAttribute(Serve.ARG_PORT);
}
+ /* (non-Javadoc)
+ * @see com.orbekk.same.http.ServerContainer#start()
+ */
+ @Override
public void start() {
server.runInBackground();
}
+ /* (non-Javadoc)
+ * @see com.orbekk.same.http.ServerContainer#stop()
+ */
+ @Override
public void stop() {
server.stopBackground();
}
+ /* (non-Javadoc)
+ * @see com.orbekk.same.http.ServerContainer#join()
+ */
+ @Override
public void join() {
server.join();
}