summaryrefslogtreecommitdiff
path: root/same/src/main/java/com
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-02 14:30:38 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-02 14:30:38 +0100
commit5fb1fa01e75b2d47aad321f00fb28ea2c4478a8f (patch)
treec0df13b786145db637882c1f0a9564bb6ffca5e0 /same/src/main/java/com
parent8bbb0f4ce2d80821893b2c32b36bdedf914ccee2 (diff)
Move discovery code to a separate package.
Diffstat (limited to 'same/src/main/java/com')
-rw-r--r--same/src/main/java/com/orbekk/same/Client.java1
-rw-r--r--same/src/main/java/com/orbekk/same/DiscoveryListener.java5
-rw-r--r--same/src/main/java/com/orbekk/same/DiscoveryService.java52
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java1
4 files changed, 2 insertions, 57 deletions
diff --git a/same/src/main/java/com/orbekk/same/Client.java b/same/src/main/java/com/orbekk/same/Client.java
index d035881..c6c3c1d 100644
--- a/same/src/main/java/com/orbekk/same/Client.java
+++ b/same/src/main/java/com/orbekk/same/Client.java
@@ -10,6 +10,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.orbekk.same.State.Component;
+import com.orbekk.same.discovery.DiscoveryListener;
import com.orbekk.util.DelayedOperation;
import com.orbekk.util.WorkQueue;
diff --git a/same/src/main/java/com/orbekk/same/DiscoveryListener.java b/same/src/main/java/com/orbekk/same/DiscoveryListener.java
deleted file mode 100644
index ba31034..0000000
--- a/same/src/main/java/com/orbekk/same/DiscoveryListener.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.orbekk.same;
-
-public interface DiscoveryListener {
- void discover(String url);
-}
diff --git a/same/src/main/java/com/orbekk/same/DiscoveryService.java b/same/src/main/java/com/orbekk/same/DiscoveryService.java
deleted file mode 100644
index 1987c69..0000000
--- a/same/src/main/java/com/orbekk/same/DiscoveryService.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.orbekk.same;
-
-import java.net.DatagramPacket;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.orbekk.net.BroadcastListener;
-
-public class DiscoveryService extends Thread {
- private Logger logger = LoggerFactory.getLogger(getClass());
- BroadcastListener broadcastListener;
- DiscoveryListener listener;
-
- public DiscoveryService(DiscoveryListener listener,
- BroadcastListener broadcastListener) {
- this.listener = listener;
- this.broadcastListener = broadcastListener;
- }
-
- @Override
- public void run() {
- logger.info("DiscoveryService starting.");
- while (!Thread.interrupted()) {
- DatagramPacket packet = broadcastListener.listen();
- if (packet == null) {
- // An error or interrupt occurred.
- continue;
- }
- String content = new String(packet.getData(), 0, packet.getLength());
- String[] words = content.split(" ");
-
- if (!content.startsWith("Discover") || words.length < 2) {
- logger.warn("Invalid discovery message: {}", content);
- continue;
- }
-
- String url = words[1];
- logger.info("Received discovery from {}", url);
- if (listener != null) {
- listener.discover(url);
- }
- }
- logger.info("DiscoveryService stopped.");
- }
-
- @Override public void interrupt() {
- logger.info("Interrupt()");
- super.interrupt();
- broadcastListener.interrupt();
- }
-}
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index 03044cf..6f32bf6 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -10,6 +10,7 @@ import com.orbekk.net.DefaultBroadcasterFactory;
import com.orbekk.paxos.PaxosService;
import com.orbekk.paxos.PaxosServiceImpl;
import com.orbekk.same.config.Configuration;
+import com.orbekk.same.discovery.DiscoveryService;
import com.orbekk.same.http.ServerContainer;
import com.orbekk.same.http.StateServlet;
import com.orbekk.same.http.JettyServerBuilder;