diff options
Diffstat (limited to 'same')
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; |