diff options
Diffstat (limited to 'discovery/src')
-rw-r--r-- | discovery/src/main/java/com/orbekk/same/discovery/DiscoveryApp.java | 13 | ||||
-rw-r--r-- | discovery/src/main/java/com/orbekk/same/discovery/DiscoveryServiceImpl.java | 38 |
2 files changed, 50 insertions, 1 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 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); + } } |