summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-14 11:01:02 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-02-14 11:01:02 +0100
commit93bd1063a403fedfb79e334c5dcb81565afa655d (patch)
tree5bf2f80db092ec18104f91b721ae6befa308c62a /same/src/main/java/com
parent4de25e837653bacee4a5fd6bb8e3ce49e075805a (diff)
Network creation and discovery in Android app.
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java9
-rw-r--r--same/src/main/java/com/orbekk/same/Master.java4
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java8
3 files changed, 15 insertions, 6 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index 7730f3e..b97ab91 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -173,6 +173,15 @@ public class Client implements DiscoveryListener {
@Override
public void discover(String url) {
+ String networkName = state.getDataOf(".networkName");
+ if (networkName.equals(".InvalidClientNetwork")) {
+ logger.warn("Client not joined to a network. Ignoring discovery");
+ return;
+ } else if (networkName.equals(".Private")) {
+ logger.info("Ignoring broadcast to .Private network.");
+ return;
+ }
+
if (!url.equals(myUrl)) {
try {
connections.getClient(url)
diff --git a/same/src/main/java/com/orbekk/same/Master.java b/same/src/main/java/com/orbekk/same/Master.java
index eaf0a8f..ed04b4d 100644
--- a/same/src/main/java/com/orbekk/same/Master.java
+++ b/same/src/main/java/com/orbekk/same/Master.java
@@ -18,8 +18,8 @@ public class Master implements MasterService, Runnable {
private Thread workerThread = null;
public static Master create(ConnectionManager connections,
- Broadcaster broadcaster, String myUrl) {
- State state = new State("DefaultMaster");
+ Broadcaster broadcaster, String myUrl, String networkName) {
+ State state = new State(networkName);
state.update(".masterUrl", myUrl, 1);
return new Master(state, connections, broadcaster);
}
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index d012d64..7f7a5d0 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -34,7 +34,7 @@ public class SameController {
int port = configuration.getInt("port");
ConnectionManagerImpl connections = new ConnectionManagerImpl(
timeout, timeout);
- State state = new State("Default");
+ State clientState = new State(".InvalidClientNetwork");
Broadcaster broadcaster = BroadcasterImpl.getDefaultBroadcastRunner();
String baseUrl = String.format("http://%s:%s/",
@@ -43,10 +43,10 @@ public class SameController {
String masterUrl = baseUrl + "MasterService.json";
String clientUrl = baseUrl + "ClientService.json";
- Master master = Master.create(
- connections, broadcaster, masterUrl);
+ Master master = Master.create(connections, broadcaster,
+ masterUrl, configuration.get("networkName"));
- Client client = new Client(state, connections,
+ Client client = new Client(clientState, connections,
clientUrl);
PaxosServiceImpl paxos = new PaxosServiceImpl("");