summaryrefslogtreecommitdiff
path: root/discovery/src
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-02 14:32:01 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-02 14:35:52 +0100
commit0ac19e55b447e9bc966282e1ba9cae9f23ae4f91 (patch)
tree4aaab6159bb0ace904af76f3d797aec6b273cd6f /discovery/src
parent5fb1fa01e75b2d47aad321f00fb28ea2c4478a8f (diff)
Rename Discovery* => Directory*.
Diffstat (limited to 'discovery/src')
-rw-r--r--discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java13
-rw-r--r--discovery/src/main/java/com/orbekk/same/discovery/DiscoveryService.java22
-rw-r--r--discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java41
-rw-r--r--discovery/src/main/java/com/orbekk/same/discovery/NetworkEntry.java30
-rw-r--r--discovery/src/test/java/com/orbekk/same/discovery/NetworkEntryTest.java25
5 files changed, 0 insertions, 131 deletions
diff --git a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java
deleted file mode 100644
index dbad697..0000000
--- a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java
+++ /dev/null
@@ -1,13 +0,0 @@
-package com.orbekk.same.discovery;
-
-import com.orbekk.same.http.ServerContainer;
-
-public class DiscoveryApp {
- public static final int DISCOVERY_PORT = 15072;
-
- public static void main(String[] args) {
- /**
- * TODO: Need to move DiscoveryService to same project.
- */
- }
-}
diff --git a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryService.java b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryService.java
deleted file mode 100644
index 04fdab0..0000000
--- a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryService.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.orbekk.same.discovery;
-
-import java.util.List;
-
-/**
- * Maintains a registry of available networks.
- *
- * The discovery service is only meant to be used for debugging.
- */
-public interface DiscoveryService {
- /**
- * Returns a list of network names and master urls interleaved, i.e.,
- *
- * [NetworkName1, MasterUrl1, ...]
- */
- List<String> getNetworks() throws Exception;
-
- /**
- * Register a network.
- */
- void registerNetwork(String networkName, String masterUrl) throws Exception;
-}
diff --git a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java
deleted file mode 100644
index fe97228..0000000
--- a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java
+++ /dev/null
@@ -1,41 +0,0 @@
-package com.orbekk.same.discovery;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-public class DiscoveryServiceImpl implements DiscoveryService {
- public final static long EXPIRE_TIME = 15 * 60l * 1000; // 15 minutes
- List<NetworkEntry> networkList = new ArrayList<NetworkEntry>();
-
- synchronized void cleanNetworkList() {
- long expiredTime = System.currentTimeMillis() - EXPIRE_TIME;
- for (Iterator<NetworkEntry> it = networkList.iterator(); it.hasNext();) {
- NetworkEntry e = it.next();
- if (e.hasExpired(expiredTime)) {
- it.remove();
- }
- }
- }
-
- @Override
- public List<String> getNetworks() throws Exception {
- cleanNetworkList();
- List<String> networks = new ArrayList<String>();
- for (NetworkEntry e : networkList) {
- networks.add(e.networkName);
- networks.add(e.masterUrl);
- }
- return networks;
- }
-
- @Override
- public void registerNetwork(String networkName, String masterUrl)
- throws Exception {
- cleanNetworkList();
- NetworkEntry entry = new NetworkEntry(networkName, masterUrl);
- entry.register(System.currentTimeMillis());
- networkList.remove(entry);
- networkList.add(entry);
- }
-}
diff --git a/discovery/src/main/java/com/orbekk/same/discovery/NetworkEntry.java b/discovery/src/main/java/com/orbekk/same/discovery/NetworkEntry.java
deleted file mode 100644
index 11c7f90..0000000
--- a/discovery/src/main/java/com/orbekk/same/discovery/NetworkEntry.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package com.orbekk.same.discovery;
-
-public class NetworkEntry {
- public String networkName;
- public String masterUrl;
- private long lastRegisteredMillis = -1;
-
- public NetworkEntry(String networkName, String masterUrl) {
- this.networkName = networkName;
- this.masterUrl = masterUrl;
- }
-
- public void register(long registeredTime) {
- lastRegisteredMillis = registeredTime;
- }
-
- public boolean hasExpired(long latestValidTimeMillis) {
- return lastRegisteredMillis < latestValidTimeMillis;
- }
-
- @Override
- public boolean equals(Object other) {
- if (other instanceof NetworkEntry) {
- NetworkEntry otherEntry = (NetworkEntry)other;
- return networkName.equals(otherEntry.networkName) &&
- masterUrl.equals(otherEntry.masterUrl);
- }
- return false;
- }
-}
diff --git a/discovery/src/test/java/com/orbekk/same/discovery/NetworkEntryTest.java b/discovery/src/test/java/com/orbekk/same/discovery/NetworkEntryTest.java
deleted file mode 100644
index dacaf9c..0000000
--- a/discovery/src/test/java/com/orbekk/same/discovery/NetworkEntryTest.java
+++ /dev/null
@@ -1,25 +0,0 @@
-package com.orbekk.same.discovery;
-
-import static org.junit.Assert.*;
-
-import org.junit.Test;
-
-public class NetworkEntryTest {
- @Test
- public void testExpiry() {
- NetworkEntry entry = new NetworkEntry("NetworkA", "UrlA");
- entry.register(100);
- assertFalse(entry.hasExpired(50));
- assertTrue(entry.hasExpired(101));
- }
-
- @Test
- public void testRegister() {
- NetworkEntry entry = new NetworkEntry("NetworkB", "UrlB");
- long time = 1000000000000l;
- entry.register(time);
- assertTrue(entry.hasExpired(time+1));
- entry.register(time + 1000);
- assertFalse(entry.hasExpired(time + 500));
- }
-}