summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-13 11:25:25 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-13 11:25:25 +0100
commit2413c4cf76f82983dc1bde5fb3dc2ce3e1afdf15 (patch)
tree2a9a1bac84c36750af7c18eb2c15be40af11e060
parenta3389e3e7782f56650760b07bb2f452e78406459 (diff)
Add new Client and Master interfaces.
Begin implementing Master interface.
-rw-r--r--same/src/main/java/com/orbekk/same/ClientService.java7
-rw-r--r--same/src/main/java/com/orbekk/same/MasterService.java6
-rw-r--r--same/src/main/java/com/orbekk/same/MasterServiceImpl.java32
-rw-r--r--same/src/test/java/com/orbekk/same/MasterServiceImplTest.java17
4 files changed, 62 insertions, 0 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientService.java b/same/src/main/java/com/orbekk/same/ClientService.java
new file mode 100644
index 0000000..f5e668f
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/ClientService.java
@@ -0,0 +1,7 @@
+package com.orbekk.same;
+
+public interface ClientService {
+ void notifyNetwork(String networkName, String masterUrl);
+
+ void setState(String component, long revision, String data);
+}
diff --git a/same/src/main/java/com/orbekk/same/MasterService.java b/same/src/main/java/com/orbekk/same/MasterService.java
new file mode 100644
index 0000000..f1ef24a
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/MasterService.java
@@ -0,0 +1,6 @@
+package com.orbekk.same;
+
+public interface MasterService {
+ void joinNetworkRequest(String networkName, String clientUrl);
+ boolean updateStateRequest(String component, String newData, long revision);
+}
diff --git a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
new file mode 100644
index 0000000..64cde2f
--- /dev/null
+++ b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
@@ -0,0 +1,32 @@
+package com.orbekk.same;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MasterServiceImpl implements MasterService, UrlReceiver {
+ private Logger logger = LoggerFactory.getLogger(getClass());
+ private State state;
+
+ public MasterServiceImpl(State initialState) {
+ state = initialState;
+ }
+
+ @Override
+ public void joinNetworkRequest(String networkName, String clientUrl) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public boolean updateStateRequest(String component, String newData, long revision) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void setUrl(String url) {
+ String myUrl = url + "MasterService.json";
+ logger.info("Master URL is " + myUrl);
+ state.update(".masterUrl", myUrl, 0);
+ }
+}
diff --git a/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
new file mode 100644
index 0000000..826471e
--- /dev/null
+++ b/same/src/test/java/com/orbekk/same/MasterServiceImplTest.java
@@ -0,0 +1,17 @@
+package com.orbekk.same;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+
+public class MasterServiceImplTest {
+ private State state = new State();
+ private MasterServiceImpl master = new MasterServiceImpl(state);
+
+ @Test
+ public void setsMasterUrl() {
+ master.setUrl("http://10.0.0.54:10050/");
+ assertEquals("http://10.0.0.54:10050/MasterService.json",
+ state.getDataOf(".masterUrl"));
+ }
+}