From f09a940c1098882fb137ad0b96e8bc9835170d3f Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Sat, 15 Nov 2008 02:48:41 +0100 Subject: [PATCH] Manage currently connected nodes. --- src/net/pterodactylus/jsite/core/NodeManager.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index 9cdc60d..957e1bc 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -31,10 +31,12 @@ import java.net.UnknownHostException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -147,6 +149,18 @@ public class NodeManager implements Iterable, PropertyChangeListener, High } /** + * Returns whether the given node is currently connected. + * + * @param node + * The node to check + * @return true if the node is currently connected, + * false otherwise + */ + public boolean isNodeConnected(Node node) { + return connectedNodes.contains(node); + } + + /** * {@inheritDoc} */ public Iterator iterator() { @@ -438,6 +452,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High logger.log(Level.WARNING, "got event for unknown client"); return; } + connectedNodes.add(node); nodeListenerSupport.fireNodeConnected(node); } @@ -452,6 +467,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High logger.log(Level.WARNING, "got event for unknown client"); return; } + connectedNodes.remove(node); nodeListenerSupport.fireNodeDisconnected(node, throwable); } } -- 2.7.4