summaryrefslogtreecommitdiff
path: root/discovery/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'discovery/src/main')
-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.java5
-rw-r--r--discovery/src/main/java/com/orbekk/same/discovery/NetworkEntry.java30
3 files changed, 57 insertions, 0 deletions
diff --git a/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryService.java b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryService.java
new file mode 100644
index 0000000..04fdab0
--- /dev/null
+++ b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryService.java
@@ -0,0 +1,22 @@
+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
new file mode 100644
index 0000000..f568213
--- /dev/null
+++ b/discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java
@@ -0,0 +1,5 @@
+package com.orbekk.same.discovery;
+
+public class DiscoveryServiceImpl {
+
+}
diff --git a/discovery/src/main/java/com/orbekk/same/discovery/NetworkEntry.java b/discovery/src/main/java/com/orbekk/same/discovery/NetworkEntry.java
new file mode 100644
index 0000000..11c7f90
--- /dev/null
+++ b/discovery/src/main/java/com/orbekk/same/discovery/NetworkEntry.java
@@ -0,0 +1,30 @@
+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;
+ }
+}