summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-27 17:00:53 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-27 17:00:53 +0100
commit9501f7a2b4b2b174c1b1c413a459b8c56101c53a (patch)
tree4d8c8a2066c02318fa9f0bdd81fd36da8c74bf15
parentfe19c8b73039d27676a7f8f80ed3bb0dfa9e2278 (diff)
Improve discovery and error handling.
-rw-r--r--same/src/main/java/com/orbekk/same/ClientServiceImpl.java8
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java9
-rw-r--r--same/src/test/java/com/orbekk/same/ClientServiceImplTest.java2
3 files changed, 15 insertions, 4 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
index b46dbfb..92482d5 100644
--- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
@@ -1,5 +1,7 @@
package com.orbekk.same;
+import static com.orbekk.same.StackTraceUtil.throwableToString;
+
import org.codehaus.jackson.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -108,13 +110,15 @@ public class ClientServiceImpl implements ClientService, UrlReceiver,
@Override
public void discover(String url) {
+ String clientUrl = url + "ClientService.json";
if (!url.equals(myUrl)) {
try {
- connections.getClient(url + "/ClientService.json")
+ connections.getClient(clientUrl)
.notifyNetwork(state.getDataOf(".networkName"),
state.getDataOf(".masterUrl"));
} catch (Exception e) {
- logger.warn("Failed to contact new client {}", url, e);
+ logger.warn("Failed to contact new client {}: {}", clientUrl,
+ throwableToString(e));
}
}
}
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index d7cc747..0601547 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -69,10 +69,10 @@ public class SameController implements UrlReceiver {
public void stop() {
try {
+ master.interrupt();
server.stop();
} catch (Exception e) {
logger.error("Failed to stop webserver", e);
- master.interrupt();
}
}
@@ -122,4 +122,11 @@ public class SameController implements UrlReceiver {
}
}
+ public ClientServiceImpl getClient() {
+ return client;
+ }
+
+ public MasterServiceImpl getMaster() {
+ return master;
+ }
}
diff --git a/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java b/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
index 69e4511..4523fe1 100644
--- a/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
+++ b/same/src/test/java/com/orbekk/same/ClientServiceImplTest.java
@@ -30,7 +30,7 @@ public class ClientServiceImplTest {
ClientServiceImpl mockClient = mock(ClientServiceImpl.class);
connections.clientMap.put("mockClient/ClientService.json",
mockClient);
- client.discover("mockClient");
+ client.discover("mockClient/");
verify(mockClient).notifyNetwork("ClientNetwork", "master");
}
}