Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Remove dead code

  • Loading branch information...
commit fce149c8d9594e7d43a49c52b207cf079b768743 1 parent 8a2c9ce
@aslakhellesoy authored
View
16 src/main/java/dnode/DNode.java
@@ -4,13 +4,10 @@
import java.io.IOException;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
public class DNode {
private final DNodeObject instance;
- private Map<String, Callback> callbacks = new HashMap<String, Callback>();
private List<Connection> connections = new ArrayList<Connection>();
public DNode(Object instance) {
@@ -21,13 +18,6 @@ public void listen(Server server) throws IOException {
server.listen(this);
}
- public void emit(String event, Object... args) {
- Callback callback = callbacks.get(event);
- if (callback != null) { // TODO: Loop over a list
- callback.call(args);
- }
- }
-
private JsonElement methods() {
JsonArray arguments = new JsonArray();
arguments.add(instance.getSignature());
@@ -51,10 +41,6 @@ private JsonElement response(JsonElement method, JsonArray arguments, JsonElemen
return response;
}
- public void on(String event, Callback callback) {
- callbacks.put(event, callback);
- }
-
public void onOpen(Connection connection) {
connections.add(connection);
connection.write(methods());
@@ -71,7 +57,7 @@ public void onMessage(Connection connection, String msg) {
}
private void handleMethods(JsonObject methods) {
-
+// System.out.println("methods = " + methods);
}
public void closeAllConnections() {
View
6 src/main/java/dnode/netty/NettyServer.java
@@ -26,14 +26,8 @@ public void listen(DNode dnode) throws IOException {
Executors.newCachedThreadPool());
ServerBootstrap bootstrap = new ServerBootstrap(factory);
-
bootstrap.setPipelineFactory(new DNodePipelineFactory(dnode));
-
-// bootstrap.setOption("child.tcpNoDelay", true);
-// bootstrap.setOption("child.keepAlive", true);
-
channel = bootstrap.bind(new InetSocketAddress(port));
- dnode.emit("ready");
}
@Override
View
5 src/main/java/dnode/webbit/WebbitServer.java
@@ -15,12 +15,11 @@ public WebbitServer(WebServer server) {
}
public void listen(DNode dnode) throws IOException {
- this.server.add("/socket.io/websocket", new SocketIOWebSocketHandler(new DNodeWebSocketHandler(dnode)));
- dnode.emit("ready");
+ server.add("/socket.io/websocket", new SocketIOWebSocketHandler(new DNodeWebSocketHandler(dnode)));
}
public void shutdown() throws IOException {
- this.server.stop();
+ server.stop();
}
}
View
68 src/test/java/dnode/DNodeTest.java
@@ -3,10 +3,7 @@
import dnode.netty.NettyServer;
import junit.framework.AssertionFailedError;
import org.junit.After;
-import org.junit.Ignore;
import org.junit.Test;
-import webbit.WebServer;
-import webbit.WebServers;
import java.io.IOException;
import java.io.InputStreamReader;
@@ -44,19 +41,17 @@ public void shutdownServer() throws IOException {
server.shutdown();
}
- private final Object signals = new Object();
-
@Test
public void shouldTalk() throws IOException, InterruptedException {
createDnode(100);
- runServer(dNode);
+ dNode.listen(server);
assertEquals("100\n", runClient("moo"));
}
@Test
public void shouldUseDataInInstance() throws IOException, InterruptedException {
createDnode(200);
- runServer(dNode);
+ dNode.listen(server);
assertEquals("200\n", runClient("moo"));
}
@@ -69,67 +64,10 @@ private void createDnode(int moo) {
@Test
public void shouldCallRightMethod() throws IOException, InterruptedException {
createDnode(300);
- runServer(dNode);
+ dNode.listen(server);
assertEquals("3000\n", runClient("boo"));
}
- @Test
- @Ignore
- public void shouldTalkUsingWebbit() throws IOException, InterruptedException {
- createDnode(100);
- runWebbitServer(dNode);
-// assertEquals("100\n", runClient("moo"));
- // TODO: Run HTMLUnit here.
- }
-
- private void runServer(final DNode dNode) throws InterruptedException {
- Thread thread = new Thread(new Runnable() {
- public void run() {
- try {
- dNode.on("ready", new Callback() {
- public void call(Object... args) {
- synchronized (signals) {
- signals.notifyAll();
- }
- }
- });
- dNode.listen(server);
- } catch (IOException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- });
- synchronized (signals) {
- thread.start();
- signals.wait();
- }
- }
-
- private void runWebbitServer(final DNode dNode) throws InterruptedException {
- WebServer webServer = WebServers.createWebServer(6060);
-// server = new WebbitServer(webServer, "/websocket");
- Thread thread = new Thread(new Runnable() {
- public void run() {
- try {
- dNode.on("ready", new Callback() {
- public void call(Object... args) {
- synchronized (signals) {
- signals.notifyAll();
- }
- }
- });
- dNode.listen(server);
- } catch (IOException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- });
- synchronized (signals) {
- thread.start();
- signals.wait();
- }
- }
-
private String runClient(String method) throws IOException, InterruptedException {
String node = System.getProperty("node", "/usr/local/bin/node");
String clientScript = System.getProperty("client", "client.js");
Please sign in to comment.
Something went wrong with that request. Please try again.