summaryrefslogtreecommitdiff
path: root/same/src/main
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-27 10:07:39 +0200
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-27 10:09:25 +0200
commite340a4b120eaf0d490b183c1227bce0eb5b32495 (patch)
tree38e30d89a875cee468a38caba131dc5181f16518 /same/src/main
parent810c7c1587b5c44c150eb4ba893874555802fc6b (diff)
Remove unused UDP broadcast code.
Diffstat (limited to 'same/src/main')
-rw-r--r--same/src/main/java/com/orbekk/net/Broadcaster.java78
-rw-r--r--same/src/main/java/com/orbekk/net/BroadcasterFactory.java5
-rw-r--r--same/src/main/java/com/orbekk/net/BroadcasterInterface.java5
-rw-r--r--same/src/main/java/com/orbekk/net/DefaultBroadcasterFactory.java8
-rw-r--r--same/src/main/java/com/orbekk/same/App.java1
-rw-r--r--same/src/main/java/com/orbekk/same/SameController.java25
6 files changed, 3 insertions, 119 deletions
diff --git a/same/src/main/java/com/orbekk/net/Broadcaster.java b/same/src/main/java/com/orbekk/net/Broadcaster.java
deleted file mode 100644
index cfec0ae..0000000
--- a/same/src/main/java/com/orbekk/net/Broadcaster.java
+++ /dev/null
@@ -1,78 +0,0 @@
-package com.orbekk.net;
-
-import java.io.IOException;
-import java.net.DatagramPacket;
-import java.net.DatagramSocket;
-import java.net.InetAddress;
-import java.net.InterfaceAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.util.Enumeration;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-
-public class Broadcaster implements BroadcasterInterface {
- private Logger logger = LoggerFactory.getLogger(getClass());
-
- public List<InetAddress> getBroadcastAddresses() {
- List<InetAddress> broadcastAddresses = new LinkedList<InetAddress>();
-
- Enumeration<NetworkInterface> interfaces;
- try {
- interfaces = NetworkInterface.getNetworkInterfaces();
- } catch (SocketException e) {
- logger.warn("Network problem?", e.fillInStackTrace());
- return broadcastAddresses;
- }
- while (interfaces.hasMoreElements()) {
- NetworkInterface iface = interfaces.nextElement();
- try {
- if (iface.isLoopback()) {
- logger.debug("Ignoring looback device " + iface.getName());
- continue;
- }
- for (InterfaceAddress address : iface.getInterfaceAddresses()) {
- InetAddress broadcast = address.getBroadcast();
- if (broadcast != null) {
- broadcastAddresses.add(broadcast);
- }
- }
- } catch (SocketException e) {
- logger.info("Ignoring interface " + iface.getName(), e.fillInStackTrace());
- }
- }
- return broadcastAddresses;
- }
-
- @Override
- public boolean sendBroadcast(int port, byte[] data) {
- boolean successful = false;
- for (InetAddress broadcastAddress : getBroadcastAddresses()) {
- try {
- DatagramSocket socket = new DatagramSocket();
- socket.setBroadcast(true);
- DatagramPacket packet = new DatagramPacket(data, data.length, broadcastAddress, port);
- socket.send(packet);
- successful = true;
- } catch (SocketException e) {
- logger.warn("Failed to send broadcast to " + broadcastAddress +
- ". ", e.fillInStackTrace());
- } catch (IOException e) {
- logger.warn("Error when sending broadcast to " +
- broadcastAddress + ".", e.fillInStackTrace());
- }
- }
- return successful;
- }
-
- public static void main(String[] args) {
- int port = Integer.parseInt(args[0]);
- Broadcaster broadcaster = new Broadcaster();
- String message = "Broadcast from Java broadcaster.";
- broadcaster.sendBroadcast(port, message.getBytes());
- }
-}
diff --git a/same/src/main/java/com/orbekk/net/BroadcasterFactory.java b/same/src/main/java/com/orbekk/net/BroadcasterFactory.java
deleted file mode 100644
index 30dd0ae..0000000
--- a/same/src/main/java/com/orbekk/net/BroadcasterFactory.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.orbekk.net;
-
-public interface BroadcasterFactory {
- BroadcasterInterface create();
-}
diff --git a/same/src/main/java/com/orbekk/net/BroadcasterInterface.java b/same/src/main/java/com/orbekk/net/BroadcasterInterface.java
deleted file mode 100644
index 08a7e80..0000000
--- a/same/src/main/java/com/orbekk/net/BroadcasterInterface.java
+++ /dev/null
@@ -1,5 +0,0 @@
-package com.orbekk.net;
-
-public interface BroadcasterInterface {
- boolean sendBroadcast(int port, byte[] data);
-}
diff --git a/same/src/main/java/com/orbekk/net/DefaultBroadcasterFactory.java b/same/src/main/java/com/orbekk/net/DefaultBroadcasterFactory.java
deleted file mode 100644
index 018d334..0000000
--- a/same/src/main/java/com/orbekk/net/DefaultBroadcasterFactory.java
+++ /dev/null
@@ -1,8 +0,0 @@
-package com.orbekk.net;
-
-public class DefaultBroadcasterFactory implements BroadcasterFactory {
- @Override
- public BroadcasterInterface create() {
- return new Broadcaster();
- }
-}
diff --git a/same/src/main/java/com/orbekk/same/App.java b/same/src/main/java/com/orbekk/same/App.java
index 464668d..ca12fa2 100644
--- a/same/src/main/java/com/orbekk/same/App.java
+++ b/same/src/main/java/com/orbekk/same/App.java
@@ -13,7 +13,6 @@ public class App {
SameController controller = SameController.create(configuration);
try {
controller.start();
- controller.searchNetworks();
if ("true".equals(configuration.get("isMaster"))) {
controller.createNetwork(configuration.get("networkName"));
} else {
diff --git a/same/src/main/java/com/orbekk/same/SameController.java b/same/src/main/java/com/orbekk/same/SameController.java
index c1c7901..95b8c29 100644
--- a/same/src/main/java/com/orbekk/same/SameController.java
+++ b/same/src/main/java/com/orbekk/same/SameController.java
@@ -3,10 +3,6 @@ package com.orbekk.same;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.orbekk.net.BroadcastListener;
-import com.orbekk.net.BroadcasterFactory;
-import com.orbekk.net.BroadcasterInterface;
-import com.orbekk.net.DefaultBroadcasterFactory;
import com.orbekk.paxos.PaxosService;
import com.orbekk.paxos.PaxosServiceImpl;
import com.orbekk.same.config.Configuration;
@@ -23,7 +19,6 @@ public class SameController {
private Master master;
private Client client;
private PaxosServiceImpl paxos;
- private BroadcasterFactory broadcasterFactory;
private Configuration configuration;
private ConnectionManager connections;
private Broadcaster serviceBroadcaster;
@@ -57,8 +52,7 @@ public class SameController {
}
};
- public static SameController create(BroadcasterFactory broadcasterFactory,
- Configuration configuration) {
+ public static SameController create(Configuration configuration) {
int port = configuration.getInt("port");
ConnectionManagerImpl connections = new ConnectionManagerImpl(
timeout, timeout);
@@ -91,14 +85,10 @@ public class SameController {
SameController controller = new SameController(
configuration, connections, server, master, client,
- paxos, broadcaster, broadcasterFactory);
+ paxos, broadcaster);
return controller;
}
- public static SameController create(Configuration configuration) {
- return create(new DefaultBroadcasterFactory(), configuration);
- }
-
public SameController(
Configuration configuration,
ConnectionManager connections,
@@ -106,8 +96,7 @@ public class SameController {
MasterServiceProxy master,
Client client,
PaxosServiceImpl paxos,
- Broadcaster serviceBroadcaster,
- BroadcasterFactory broadcasterFactory) {
+ Broadcaster serviceBroadcaster) {
this.configuration = configuration;
this.connections = connections;
this.server = server;
@@ -115,7 +104,6 @@ public class SameController {
this.client = client;
this.paxos = paxos;
this.serviceBroadcaster = serviceBroadcaster;
- this.broadcasterFactory = broadcasterFactory;
}
public void start() throws Exception {
@@ -151,13 +139,6 @@ public class SameController {
"MasterService.json";
joinNetwork(masterUrl);
}
-
- public void searchNetworks() {
- BroadcasterInterface broadcaster = broadcasterFactory.create();
- String message = "Discover " + client.getUrl();
- broadcaster.sendBroadcast(configuration.getInt("discoveryPort"),
- message.getBytes());
- }
public void joinNetwork(String url) {
client.joinNetwork(url);