summaryrefslogtreecommitdiff
path: root/same/src/main/java/com/orbekk
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-17 18:25:48 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-01-17 18:25:48 +0100
commit5a21215b4ea85bfa4da8d3fbb0f87916c2f4635a (patch)
treecc838d27cb41a1ba51d4a3208539ac412180ab80 /same/src/main/java/com/orbekk
parentee986f93216e63460a6aaba1cb7d2f451401a23a (diff)
Begin error handling.
– Declare thrown exceptions in services. – Use try {} blocks when communicating with services.
Diffstat (limited to 'same/src/main/java/com/orbekk')
-rw-r--r--same/src/main/java/com/orbekk/same/ClientService.java4
-rw-r--r--same/src/main/java/com/orbekk/same/ClientServiceImpl.java6
-rw-r--r--same/src/main/java/com/orbekk/same/MasterService.java5
-rw-r--r--same/src/main/java/com/orbekk/same/MasterServiceImpl.java16
4 files changed, 22 insertions, 9 deletions
diff --git a/same/src/main/java/com/orbekk/same/ClientService.java b/same/src/main/java/com/orbekk/same/ClientService.java
index 480b813..9382bfa 100644
--- a/same/src/main/java/com/orbekk/same/ClientService.java
+++ b/same/src/main/java/com/orbekk/same/ClientService.java
@@ -1,7 +1,7 @@
package com.orbekk.same;
public interface ClientService {
- void notifyNetwork(String networkName, String masterUrl);
+ void notifyNetwork(String networkName, String masterUrl) throws Exception;
- void setState(String component, String data, long revision);
+ void setState(String component, String data, long revision) throws Exception;
}
diff --git a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
index 36918cf..3f84c2e 100644
--- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
@@ -42,7 +42,11 @@ public class ClientServiceImpl implements ClientService, UrlReceiver {
if (myUrl != null) {
MasterService master = connections.getMaster(masterUrl);
state.clear();
- master.joinNetworkRequest(myUrl);
+ try {
+ master.joinNetworkRequest(myUrl);
+ } catch (Exception e) {
+ logger.error("Unable to connect to master.", e);
+ }
} else {
logger.error("Tried to join network at {}, but my url is unknown. " +
"Run discovery service.", masterUrl);
diff --git a/same/src/main/java/com/orbekk/same/MasterService.java b/same/src/main/java/com/orbekk/same/MasterService.java
index 46e8ec1..6076ed4 100644
--- a/same/src/main/java/com/orbekk/same/MasterService.java
+++ b/same/src/main/java/com/orbekk/same/MasterService.java
@@ -1,6 +1,7 @@
package com.orbekk.same;
public interface MasterService {
- void joinNetworkRequest(String clientUrl);
- boolean updateStateRequest(String component, String newData, long revision);
+ void joinNetworkRequest(String clientUrl) throws Exception;
+ boolean updateStateRequest(String component, String newData, long revision)
+ throws Exception;
}
diff --git a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
index a8acc52..5511dbf 100644
--- a/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/MasterServiceImpl.java
@@ -45,9 +45,13 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable {
for (final String component : state.getAndClearUpdatedComponents()) {
logger.info("Broadcasting new component {}", state.show(component));
broadcaster.broadcast(participants(), new ServiceOperation() {
- @Override public void run(ClientService client) {
- client.setState(component, state.getDataOf(component),
- state.getRevision(component));
+ @Override public void run(ClientService client) {
+ try {
+ client.setState(component, state.getDataOf(component),
+ state.getRevision(component));
+ } catch (Exception e) {
+ logger.warn("Exception when connecting to client.", e);
+ }
}
});
worked = true;
@@ -62,7 +66,11 @@ public class MasterServiceImpl implements MasterService, UrlReceiver, Runnable {
broadcaster.broadcast(_fullStateReceivers, new ServiceOperation() {
@Override public void run(ClientService client) {
for (Component c : components) {
- client.setState(c.getName(), c.getData(), c.getRevision());
+ try {
+ client.setState(c.getName(), c.getData(), c.getRevision());
+ } catch (Exception e) {
+ logger.warn("Exception when connecting to client.", e);
+ }
}
}
});