summaryrefslogtreecommitdiff
path: root/jsonrpc/src/main/java/com
diff options
context:
space:
mode:
Diffstat (limited to 'jsonrpc/src/main/java/com')
-rw-r--r--jsonrpc/src/main/java/com/orbekk/rpc/App.java19
-rw-r--r--jsonrpc/src/main/java/com/orbekk/rpc/Client.java16
-rw-r--r--jsonrpc/src/main/java/com/orbekk/rpc/PingService.java5
-rw-r--r--jsonrpc/src/main/java/com/orbekk/rpc/PingServiceImpl.java8
-rw-r--r--jsonrpc/src/main/java/com/orbekk/same/SameService.java6
-rw-r--r--jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java31
6 files changed, 62 insertions, 23 deletions
diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/App.java b/jsonrpc/src/main/java/com/orbekk/rpc/App.java
index e112008..ffd316d 100644
--- a/jsonrpc/src/main/java/com/orbekk/rpc/App.java
+++ b/jsonrpc/src/main/java/com/orbekk/rpc/App.java
@@ -1,15 +1,24 @@
package com.orbekk.rpc;
-import org.eclipse.jetty.server.Server;
-
import com.googlecode.jsonrpc4j.JsonRpcServer;
+import com.orbekk.same.SameService;
+import com.orbekk.same.SameServiceImpl;
+import org.eclipse.jetty.server.Server;
public class App {
public static void main(String[] args) {
- PingService service = new PingServiceImpl();
- JsonRpcServer jsonServer = new JsonRpcServer(service, PingService.class);
+ if (args.length < 2) {
+ System.err.println("Arguments: port networkName");
+ System.exit(1);
+ }
+ int port = Integer.parseInt(args[0]);
+ String networkName = args[1];
+
+ SameService service = new SameServiceImpl(networkName);
+ JsonRpcServer jsonServer = new JsonRpcServer(service,
+ SameService.class);
- Server server = new Server(10080);
+ Server server = new Server(port);
RpcHandler rpcHandler = new RpcHandler(jsonServer);
server.setHandler(rpcHandler);
diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/Client.java b/jsonrpc/src/main/java/com/orbekk/rpc/Client.java
index bfb6c52..ba77df6 100644
--- a/jsonrpc/src/main/java/com/orbekk/rpc/Client.java
+++ b/jsonrpc/src/main/java/com/orbekk/rpc/Client.java
@@ -3,23 +3,29 @@ package com.orbekk.rpc;
import java.net.MalformedURLException;
import java.net.URL;
+import com.orbekk.same.SameService;
import com.googlecode.jsonrpc4j.JsonRpcHttpClient;
import com.googlecode.jsonrpc4j.ProxyUtil;
public class Client {
public static void main(String[] args) {
+ if (args.length < 1) {
+ System.err.println("Arguments: networkAddress");
+ System.exit(1);
+ }
+ String networkAddress = args[0];
JsonRpcHttpClient client = null;
try {
- client = new JsonRpcHttpClient(
- new URL("http://10.0.0.96:10080/PingService.json"));
+ client = new JsonRpcHttpClient(new URL(networkAddress));
} catch (MalformedURLException e) {
e.printStackTrace();
}
- PingService service = ProxyUtil.createProxy(
+ SameService service = ProxyUtil.createProxy(
client.getClass().getClassLoader(),
- PingService.class,
+ SameService.class,
client);
- System.out.println(service.ping());
+ service.notifyNetwork("NoNetwork");
+ System.out.println(service.participateNetwork("FirstNetwork"));
}
}
diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/PingService.java b/jsonrpc/src/main/java/com/orbekk/rpc/PingService.java
deleted file mode 100644
index 353f7c5..0000000
--- a/jsonrpc/src/main/java/com/orbekk/rpc/PingService.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.orbekk.rpc;
-
-public interface PingService {
- String ping();
-}
diff --git a/jsonrpc/src/main/java/com/orbekk/rpc/PingServiceImpl.java b/jsonrpc/src/main/java/com/orbekk/rpc/PingServiceImpl.java
deleted file mode 100644
index 9472846..0000000
--- a/jsonrpc/src/main/java/com/orbekk/rpc/PingServiceImpl.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.orbekk.rpc;
-
-public class PingServiceImpl implements PingService {
- @Override
- public String ping() {
- return "Pong";
- }
-}
diff --git a/jsonrpc/src/main/java/com/orbekk/same/SameService.java b/jsonrpc/src/main/java/com/orbekk/same/SameService.java
new file mode 100644
index 0000000..dccc1e9
--- /dev/null
+++ b/jsonrpc/src/main/java/com/orbekk/same/SameService.java
@@ -0,0 +1,6 @@
+package com.orbekk.same;
+
+public interface SameService {
+ void notifyNetwork(String networkName);
+ String participateNetwork(String networkName);
+}
diff --git a/jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java b/jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java
new file mode 100644
index 0000000..56a0fa1
--- /dev/null
+++ b/jsonrpc/src/main/java/com/orbekk/same/SameServiceImpl.java
@@ -0,0 +1,31 @@
+package com.orbekk.same;
+
+import java.util.List;
+import java.util.LinkedList;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class SameServiceImpl implements SameService {
+ private Logger logger = LoggerFactory.getLogger(getClass());
+ private List<String> participants = new LinkedList<String>();
+ private String networkName;
+
+ public SameServiceImpl(String networkName) {
+ this.networkName = networkName;
+ }
+
+ @Override
+ public void notifyNetwork(String networkName) {
+ logger.info("Notification from network " + networkName);
+ }
+
+ @Override
+ public String participateNetwork(String networkName) {
+ logger.info("Got participation request.");
+ if (networkName != this.networkName) {
+ logger.info("Network name mismatch.");
+ }
+ return "<Not implemented>";
+ }
+}