Remove old high-level FCP client.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 22 May 2009 04:41:08 +0000 (06:41 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 22 May 2009 04:41:08 +0000 (06:41 +0200)
src/net/pterodactylus/jsite/core/NodeManager.java

index 957e1bc..8745cba 100644 (file)
@@ -27,7 +27,6 @@ import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
-import java.net.UnknownHostException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
@@ -40,10 +39,6 @@ import java.util.Set;
 import java.util.logging.Level;
 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.jsite.util.IdGenerator;
 import net.pterodactylus.util.io.Closer;
 import net.pterodactylus.util.logging.Logging;
@@ -54,7 +49,7 @@ import net.pterodactylus.util.number.Hex;
  *
  * @author David ‘Bombe’ Roden &lt;bombe@freenetproject.org&gt;
  */
-public class NodeManager implements Iterable<Node>, PropertyChangeListener, HighLevelClientListener {
+public class NodeManager implements Iterable<Node>, PropertyChangeListener {
 
        /** Logger. */
        private static final Logger logger = Logging.getLogger(NodeManager.class.getName());
@@ -77,12 +72,6 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
        /** Map from node ID to node. */
        private final Map<String, Node> idNodes = Collections.synchronizedMap(new HashMap<String, Node>());
 
-       /** All FCP connections. */
-       private final Map<Node, HighLevelClient> nodeClients = Collections.synchronizedMap(new HashMap<Node, HighLevelClient>());
-
-       /** Maps nodes to high-level clients. */
-       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>());
 
@@ -288,12 +277,8 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                        return false;
                }
                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);
                nodeListenerSupport.fireNodeAdded(node);
                return true;
        }
@@ -311,9 +296,6 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                        if (!nodes.contains(node)) {
                                return;
                        }
-                       if (nodeClients.containsKey(node)) {
-                               disconnect(node);
-                       }
                        nodes.remove(node);
                        idNodes.remove(node.getId());
                        node.removePropertyChangeListener(this);
@@ -329,19 +311,6 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         */
        public void connect(Node node) {
                logger.log(Level.FINEST, "connect(node=" + node + ")");
-               HighLevelClient highLevelClient;
-               highLevelClient = nodeClients.get(node);
-               if (highLevelClient == null) {
-                       logger.log(Level.WARNING, "was told to connect to unknown node: " + node);
-                       return;
-               }
-               try {
-                       highLevelClient.connect(node.getHostname(), node.getPort());
-               } catch (UnknownHostException uhe1) {
-                       nodeListenerSupport.fireNodeConnectionFailed(node, uhe1);
-               } catch (IOException ioe1) {
-                       nodeListenerSupport.fireNodeConnectionFailed(node, ioe1);
-               }
        }
 
        /**
@@ -352,13 +321,6 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
         */
        public void disconnect(Node node) {
                logger.log(Level.FINEST, "disconnect(node=" + node + ")");
-               synchronized (syncObject) {
-                       if (!nodes.contains(node)) {
-                               return;
-                       }
-                       HighLevelClient highLevelClient = nodeClients.get(node);
-                       highLevelClient.disconnect();
-               }
        }
 
        /**
@@ -371,30 +333,6 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
        }
 
        /**
-        * Returns the high-level client for a given node.
-        *
-        * @param node
-        *            The node to get a high-level client for
-        * @return The high-level client for a node, or <code>null</code> if the
-        *         node was disconnected or removed
-        */
-       public HighLevelClient getHighLevelClient(Node node) {
-               return nodeClients.get(node);
-       }
-
-       /**
-        * Returns the node for a high-level client.
-        *
-        * @param highLevelClient
-        *            The high-level client to get the node for
-        * @return The node for the high-level client, or <code>null</code> if the
-        *         high-level client is not known
-        */
-       public Node getNode(HighLevelClient highLevelClient) {
-               return clientNodes.get(highLevelClient);
-       }
-
-       /**
         * Returns the node identified by the given ID.
         *
         * @param id
@@ -421,16 +359,6 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                if (nodes.isEmpty()) {
                        throw new NoNodeException("no node configured");
                }
-               Node node = nodes.get(0);
-               HighLevelClient highLevelClient = nodeClients.get(node);
-               try {
-                       KeyGenerationResult keyGenerationResult = highLevelClient.generateKey().getResult();
-                       return new String[] { keyGenerationResult.getInsertURI(), keyGenerationResult.getRequestURI() };
-               } catch (HighLevelException hle1) {
-                       throw new BackendException(hle1);
-               } catch (InterruptedException e) {
-                       /* ignore. */
-               }
                return null;
        }
 
@@ -439,40 +367,6 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
        //
 
        //
-       // INTERFACE HighLevelClientListener
-       //
-
-       /**
-        * {@inheritDoc}
-        */
-       public void clientConnected(HighLevelClient highLevelClient) {
-               logger.log(Level.FINEST, "clientConnected(highLevelClient=" + highLevelClient + ")");
-               Node node = clientNodes.get(highLevelClient);
-               if (node == null) {
-                       logger.log(Level.WARNING, "got event for unknown client");
-                       return;
-               }
-               connectedNodes.add(node);
-               nodeListenerSupport.fireNodeConnected(node);
-       }
-
-       /**
-        * {@inheritDoc}
-        */
-       public void clientDisconnected(HighLevelClient highLevelClient, Throwable throwable) {
-               logger.log(Level.FINEST, "clientDisconnected(highLevelClient=" + highLevelClient + ",throwable=" + throwable + ")");
-               synchronized (syncObject) {
-                       Node node = clientNodes.get(highLevelClient);
-                       if (node == null) {
-                               logger.log(Level.WARNING, "got event for unknown client");
-                               return;
-                       }
-                       connectedNodes.remove(node);
-                       nodeListenerSupport.fireNodeDisconnected(node, throwable);
-               }
-       }
-
-       //
        // INTERFACE PropertyChangeListener
        //
 
@@ -484,22 +378,7 @@ public class NodeManager implements Iterable<Node>, PropertyChangeListener, High
                if (eventSource instanceof Node) {
                        String propertyName = propertyChangeEvent.getPropertyName();
                        if ("hostname".equals(propertyName) || "port".equals(propertyName)) {
-                               Node node = (Node) eventSource;
-                               HighLevelClient highLevelClient = nodeClients.get(node);
-                               if (highLevelClient == null) {
-                                       logger.log(Level.WARNING, "got property change event for unknown node: " + node);
-                                       return;
-                               }
-                               if (highLevelClient.isConnected()) {
-                                       highLevelClient.disconnect();
-                                       try {
-                                               highLevelClient.connect(node.getHostname(), node.getPort());
-                                       } catch (UnknownHostException uhe1) {
-                                               nodeListenerSupport.fireNodeConnectionFailed(node, uhe1);
-                                       } catch (IOException ioe1) {
-                                               nodeListenerSupport.fireNodeConnectionFailed(node, ioe1);
-                                       }
-                               }
+                               /* TODO - reconnect. */
                        }
                }
        }