store nodes by id
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 3 Jun 2008 06:50:51 +0000 (08:50 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Tue, 3 Jun 2008 06:50:51 +0000 (08:50 +0200)
add method to get node by id

src/net/pterodactylus/jsite/core/NodeManager.java

index 4224cf1..c251232 100644 (file)
@@ -72,6 +72,9 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
        /** All nodes. */
        private 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>());
+
        /** All FCP connections. */
        private Map<Node, HighLevelClient> nodeClients = Collections.synchronizedMap(new HashMap<Node, HighLevelClient>());
 
@@ -332,6 +335,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                node.addPropertyChangeListener(this);
                HighLevelClient highLevelClient = new HighLevelClient(clientName);
                nodes.add(node);
+               idNodes.put(node.getId(), node);
                clientNodes.put(highLevelClient, node);
                nodeClients.put(node, highLevelClient);
                highLevelClient.addHighLevelClientListener(this);
@@ -355,6 +359,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                                disconnect(node);
                        }
                        nodes.remove(node);
+                       idNodes.remove(node.getId());
                        node.removePropertyChangeListener(this);
                        fireNodeRemoved(node);
                }
@@ -432,6 +437,18 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
        }
 
        /**
+        * Returns the node identified by the given ID.
+        * 
+        * @param id
+        *            The ID of the node
+        * @return The node with the given ID, or <code>null</code> if no such
+        *         node was found
+        */
+       Node getNode(String id) {
+               return idNodes.get(id);
+       }
+
+       /**
         * Generates a new SSK key pair.
         * 
         * @return An array with the private key at index <code>0</code> and the