From: David ‘Bombe’ Roden Date: Fri, 22 May 2009 04:41:08 +0000 (+0200) Subject: Remove old high-level FCP client. X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=57ceb171afaa8bf304fa5c1da0360f285702e1b3;p=jSite2.git Remove old high-level FCP client. --- diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index 957e1bc..8745cba 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -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 <bombe@freenetproject.org> */ -public class NodeManager implements Iterable, PropertyChangeListener, HighLevelClientListener { +public class NodeManager implements Iterable, PropertyChangeListener { /** Logger. */ private static final Logger logger = Logging.getLogger(NodeManager.class.getName()); @@ -77,12 +72,6 @@ public class NodeManager implements Iterable, PropertyChangeListener, High /** Map from node ID to node. */ private final Map idNodes = Collections.synchronizedMap(new HashMap()); - /** All FCP connections. */ - private final Map nodeClients = Collections.synchronizedMap(new HashMap()); - - /** Maps nodes to high-level clients. */ - private final Map clientNodes = Collections.synchronizedMap(new HashMap()); - /** Collection of currently connected nodes. */ private final Set connectedNodes = Collections.synchronizedSet(new HashSet()); @@ -288,12 +277,8 @@ public class NodeManager implements Iterable, 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, 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, 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, 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, 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 null 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 null 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, 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, 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, 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. */ } } }