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;
private final NodeListenerSupport nodeListenerSupport = new NodeListenerSupport();
/** All nodes. */
- private List<Node> nodes = Collections.synchronizedList(new ArrayList<Node>());
+ private final List<Node> nodes = Collections.synchronizedList(new ArrayList<Node>());
/** Map from node ID to node. */
- private Map<String, Node> idNodes = Collections.synchronizedMap(new HashMap<String, Node>());
+ private final Map<String, Node> idNodes = Collections.synchronizedMap(new HashMap<String, Node>());
/** All FCP connections. */
- private Map<Node, HighLevelClient> nodeClients = Collections.synchronizedMap(new HashMap<Node, HighLevelClient>());
+ private final Map<Node, HighLevelClient> nodeClients = Collections.synchronizedMap(new HashMap<Node, HighLevelClient>());
/** Maps nodes to high-level clients. */
- private Map<HighLevelClient, Node> clientNodes = Collections.synchronizedMap(new HashMap<HighLevelClient, Node>());
+ private final Map<HighLevelClient, Node> clientNodes = Collections.synchronizedMap(new HashMap<HighLevelClient, Node>());
+
+ /** Collection of currently connected nodes. */
+ private final Set<Node> connectedNodes = Collections.synchronizedSet(new HashSet<Node>());
/**
* Creates a new FCP collector.
}
/**
+ * Returns whether the given node is currently connected.
+ *
+ * @param node
+ * The node to check
+ * @return <code>true</code> if the node is currently connected,
+ * <code>false</code> otherwise
+ */
+ public boolean isNodeConnected(Node node) {
+ return connectedNodes.contains(node);
+ }
+
+ /**
* {@inheritDoc}
*/
public Iterator<Node> iterator() {
logger.log(Level.WARNING, "got event for unknown client");
return;
}
+ connectedNodes.add(node);
nodeListenerSupport.fireNodeConnected(node);
}
logger.log(Level.WARNING, "got event for unknown client");
return;
}
+ connectedNodes.remove(node);
nodeListenerSupport.fireNodeDisconnected(node, throwable);
}
}