summaryrefslogtreecommitdiff
path: root/same/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'same/src/main/java')
-rw-r--r--same/src/main/java/com/orbekk/same/ClientService.java3
-rw-r--r--same/src/main/java/com/orbekk/same/ClientServiceImpl.java27
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java2
3 files changed, 32 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
index 9382bfa..3992e4c 100644
--- a/same/src/main/java/com/orbekk/same/ClientService.java
+++ b/same/src/main/java/com/orbekk/same/ClientService.java
@@ -4,4 +4,7 @@ public interface ClientService {
void notifyNetwork(String networkName, String masterUrl) throws Exception;
void setState(String component, String data, long revision) throws Exception;
+
+ // Manual discovery request by client.
+ void discoveryRequest(String remoteUrl) 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 92482d5..f19d272 100644
--- a/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
+++ b/same/src/main/java/com/orbekk/same/ClientServiceImpl.java
@@ -2,10 +2,15 @@ package com.orbekk.same;
import static com.orbekk.same.StackTraceUtil.throwableToString;
+import java.util.ArrayList;
+import java.util.List;
+
import org.codehaus.jackson.type.TypeReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import com.orbekk.util.WorkQueue;
+
public class ClientServiceImpl implements ClientService, UrlReceiver,
DiscoveryListener {
private Logger logger = LoggerFactory.getLogger(getClass());
@@ -15,11 +20,28 @@ public class ClientServiceImpl implements ClientService, UrlReceiver,
private StateChangedListener stateListener;
private NetworkNotificationListener networkListener;
+ private WorkQueue<String> discoveryThread = new WorkQueue<String>() {
+ @Override protected void onChange() {
+ List<String> pending = getAndClear();
+ for (String url : pending) {
+ discover(url);
+ }
+ }
+ };
+
public ClientServiceImpl(State state, ConnectionManager connections) {
this.state = state;
this.connections = connections;
}
+ public void start() {
+ discoveryThread.start();
+ }
+
+ public void interrupt() {
+ discoveryThread.interrupt();
+ }
+
@Override
public void notifyNetwork(String networkName, String masterUrl) {
logger.info("NotifyNetwork(networkName={}, masterUrl={})",
@@ -122,4 +144,9 @@ public class ClientServiceImpl implements ClientService, UrlReceiver,
}
}
}
+
+ @Override
+ public void discoveryRequest(String remoteUrl) {
+ discoveryThread.add(remoteUrl);
+ }
}
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 38c4149..9b8abde 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -65,10 +65,12 @@ public class SameController implements UrlReceiver {
public void start() throws Exception {
server.start();
master.start();
+ client.start();
}
public void stop() {
try {
+ client.interrupt();
master.interrupt();
server.stop();
} catch (Exception e) {