reformat
[jSite2.git] / src / net / pterodactylus / jsite / core / NodeManager.java
index b9404c7..56910ae 100644 (file)
@@ -40,6 +40,7 @@ import java.util.logging.Logger;
 
 import net.pterodactylus.fcp.highlevel.HighLevelClient;
 import net.pterodactylus.fcp.highlevel.HighLevelClientListener;
+import net.pterodactylus.fcp.highlevel.HighLevelException;
 import net.pterodactylus.fcp.highlevel.KeyGenerationResult;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
@@ -48,7 +49,6 @@ import net.pterodactylus.util.logging.Logging;
  * TODO
  * 
  * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
  */
 public class NodeManager implements Iterable<Node>, PropertyChangeListener, HighLevelClientListener {
 
@@ -120,7 +120,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         *            The node that was added.
         */
        private void fireNodeAdded(Node node) {
-               for (NodeListener nodeListener: nodeListeners) {
+               for (NodeListener nodeListener : nodeListeners) {
                        nodeListener.nodeAdded(node);
                }
        }
@@ -132,7 +132,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         *            The node that was removed
         */
        private void fireNodeRemoved(Node node) {
-               for (NodeListener nodeListener: nodeListeners) {
+               for (NodeListener nodeListener : nodeListeners) {
                        nodeListener.nodeRemoved(node);
                }
        }
@@ -144,7 +144,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         *            The node that is now connected
         */
        private void fireNodeConnected(Node node) {
-               for (NodeListener nodeListener: nodeListeners) {
+               for (NodeListener nodeListener : nodeListeners) {
                        nodeListener.nodeConnected(node);
                }
        }
@@ -158,7 +158,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         *            The cause of the failure
         */
        private void fireNodeConnectionFailed(Node node, Throwable cause) {
-               for (NodeListener nodeListener: nodeListeners) {
+               for (NodeListener nodeListener : nodeListeners) {
                        nodeListener.nodeConnectionFailed(node, cause);
                }
        }
@@ -173,7 +173,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         *            if there was no exception
         */
        private void fireNodeDisconnected(Node node, Throwable throwable) {
-               for (NodeListener nodeListener: nodeListeners) {
+               for (NodeListener nodeListener : nodeListeners) {
                        nodeListener.nodeDisconnected(node, throwable);
                }
        }
@@ -270,7 +270,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                logger.fine("loaded " + loadedNodes.size() + " nodes from config");
                synchronized (syncObject) {
                        nodes.clear();
-                       for (Node node: loadedNodes) {
+                       for (Node node : loadedNodes) {
                                addNode(node);
                        }
                }
@@ -291,7 +291,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                }
                Properties nodeProperties = new Properties();
                int nodeIndex = -1;
-               for (Node node: nodes) {
+               for (Node node : nodes) {
                        String nodePrefix = "nodes." + ++nodeIndex;
                        nodeProperties.setProperty(nodePrefix + ".name", node.getName());
                        nodeProperties.setProperty(nodePrefix + ".hostname", node.getHostname());
@@ -346,6 +346,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                        if (nodeClients.containsKey(node)) {
                                disconnect(node);
                        }
+                       nodes.remove(node);
                        node.removePropertyChangeListener(this);
                        fireNodeRemoved(node);
                }
@@ -429,10 +430,10 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         *         public key at index <code>1</code>
         * @throws IOException
         *             if an I/O error occurs communicating with the node
-        * @throws NoNodeException
-        *             if no node is configured
+        * @throws JSiteException
+        *             if there is a problem with the node
         */
-       public String[] generateKeyPair() throws IOException, NoNodeException {
+       public String[] generateKeyPair() throws IOException, JSiteException {
                if (nodes.isEmpty()) {
                        throw new NoNodeException("no node configured");
                }
@@ -441,6 +442,8 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                try {
                        KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
                        return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
+               } catch (HighLevelException hle1) {
+                       throw new BackendException(hle1);
                } catch (InterruptedException e) {
                        /* ignore. */
                }