X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FNodeManager.java;h=437dace0272357b9f1c81cccb1942aab08669b1e;hb=8d2c8293c9704a7eec0faa9ae9515e25e481f795;hp=4224cf16888194217c02e2401b48060f4e719200;hpb=464bd5d54b6b55a84dd7245f48164ec0a72cd49c;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index 4224cf1..437dace 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -72,6 +72,9 @@ public class NodeManager implements Iterable, PropertyChangeListener, High /** All nodes. */ private List nodes = Collections.synchronizedList(new ArrayList()); + /** Map from node ID to node. */ + private Map idNodes = Collections.synchronizedMap(new HashMap()); + /** All FCP connections. */ private Map nodeClients = Collections.synchronizedMap(new HashMap()); @@ -122,6 +125,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node that was added. */ private void fireNodeAdded(Node node) { + logger.finest("firing nodeAdded event with [node=" + node + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeAdded(node); } @@ -134,6 +138,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node that was removed */ private void fireNodeRemoved(Node node) { + logger.finest("firing nodeRemoved event with [node=" + node + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeRemoved(node); } @@ -146,6 +151,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node that is now connected */ private void fireNodeConnected(Node node) { + logger.finest("firing nodeConnected event with [node=" + node + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeConnected(node); } @@ -160,6 +166,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The cause of the failure */ private void fireNodeConnectionFailed(Node node, Throwable cause) { + logger.finest("firing nodeConnectionFailed event with [node=" + node + ",cause=" + cause + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeConnectionFailed(node, cause); } @@ -175,6 +182,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if there was no exception */ private void fireNodeDisconnected(Node node, Throwable throwable) { + logger.finest("firing nodeDisconnected event with [node=" + node + ",throwable=" + throwable + "]"); for (NodeListener nodeListener : nodeListeners) { nodeListener.nodeDisconnected(node, throwable); } @@ -223,6 +231,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if an I/O error occurs loading the nodes */ public void load() throws IOException { + logger.finest("load()"); File directoryFile = new File(directory); File nodeFile = new File(directoryFile, "nodes.properties"); if (!nodeFile.exists() || !nodeFile.isFile() || !nodeFile.canRead()) { @@ -290,6 +299,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if an I/O error occurs saving the nodes */ public void save() throws IOException { + logger.finest("save()"); File directoryFile = new File(directory); if (!directoryFile.exists()) { if (!directoryFile.mkdirs()) { @@ -325,6 +335,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if the node was not added because it was already known */ public boolean addNode(Node node) { + logger.finest("addNode(node=" + node + ")"); if (nodes.contains(node)) { logger.warning("was told to add already known node: " + node); return false; @@ -332,6 +343,7 @@ public class NodeManager implements Iterable, 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); @@ -347,6 +359,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node to remove */ public void removeNode(Node node) { + logger.finest("removeNode(node=" + node + ")"); synchronized (syncObject) { if (!nodes.contains(node)) { return; @@ -355,6 +368,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High disconnect(node); } nodes.remove(node); + idNodes.remove(node.getId()); node.removePropertyChangeListener(this); fireNodeRemoved(node); } @@ -367,6 +381,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node to connect to */ public void connect(Node node) { + logger.finest("connect(node=" + node + ")"); HighLevelClient highLevelClient; highLevelClient = nodeClients.get(node); if (highLevelClient == null) { @@ -389,6 +404,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * The node to disconnect */ public void disconnect(Node node) { + logger.finest("disconnect(node=" + node + ")"); synchronized (syncObject) { if (!nodes.contains(node)) { return; @@ -432,6 +448,18 @@ public class NodeManager implements Iterable, 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 null 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 0 and the @@ -442,6 +470,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * if there is a problem with the node */ public String[] generateKeyPair() throws IOException, JSiteException { + logger.finest("generateKeyPair()"); if (nodes.isEmpty()) { throw new NoNodeException("no node configured"); } @@ -470,7 +499,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * {@inheritDoc} */ public void clientConnected(HighLevelClient highLevelClient) { - logger.log(Level.FINER, "clientConnected(c=" + highLevelClient + ")"); + logger.finest("clientConnected(highLevelClient=" + highLevelClient + ")"); Node node = clientNodes.get(highLevelClient); if (node == null) { logger.log(Level.WARNING, "got event for unknown client"); @@ -483,7 +512,7 @@ public class NodeManager implements Iterable, PropertyChangeListener, High * {@inheritDoc} */ public void clientDisconnected(HighLevelClient highLevelClient, Throwable throwable) { - logger.log(Level.FINER, "clientDisconnected(c=" + highLevelClient + ",t=" + throwable + ")"); + logger.finest("clientDisconnected(highLevelClient=" + highLevelClient + ",throwable=" + throwable + ")"); synchronized (syncObject) { Node node = clientNodes.get(highLevelClient); if (node == null) {