summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-02 14:15:10 +0100
committerKjetil Ørbekk <kjetil.orbekk@gmail.com>2012-03-02 14:15:10 +0100
commit8bbb0f4ce2d80821893b2c32b36bdedf914ccee2 (patch)
tree1981b871233e010e5e53392fb872b73bfa592e7d
parent4a4dc574fcb44f5d92b488de1efeba40d1e6469f (diff)
Implement discovery service.
No main class yet.
-rw-r--r--discovery/pom.xml5
-rw-r--r--discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java13
-rw-r--r--discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java38
3 files changed, 55 insertions, 1 deletions
diff --git a/discovery/pom.xml b/discovery/pom.xml
index d3e9cd7..92cbc94 100644
--- a/discovery/pom.xml
+++ b/discovery/pom.xml
@@ -81,6 +81,11 @@
<artifactId>httpclient</artifactId>
<version>4.1.2</version>
</dependency>
+ <dependency>
+ <groupId>com.orbekk</groupId>
+ <artifactId>same</artifactId>
+ <version>0.0-SNAPSHOT</version>
+ </dependency>
</dependencies>
<build>
<plugins>
diff --git a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java
new file mode 100644
index 0000000..dbad697
--- /dev/null
+++ b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java
@@ -0,0 +1,13 @@
+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/DiscoveryServiceImpl.java b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java
index f568213..fe97228 100644
--- a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java
+++ b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java
@@ -1,5 +1,41 @@
package com.orbekk.same.discovery;
-public class DiscoveryServiceImpl {
+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);
+ }
}