X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fnet%2Fpterodactylus%2Fjsite%2Fcore%2FNodeManager.java;h=e8fd278576478dfb4d58a320ae2a63385c8d61de;hb=e5e14c688e13425b77ac6bf9d952af099ea52de5;hp=8745cbaadd49c15e5ae0988b1d8b0f04fc4901ae;hpb=57ceb171afaa8bf304fa5c1da0360f285702e1b3;p=jSite2.git diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index 8745cba..e8fd278 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -27,6 +27,7 @@ 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; @@ -39,6 +40,8 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; +import net.pterodactylus.fcp.highlevel.FcpClient; +import net.pterodactylus.fcp.highlevel.FcpException; import net.pterodactylus.jsite.util.IdGenerator; import net.pterodactylus.util.io.Closer; import net.pterodactylus.util.logging.Logging; @@ -72,6 +75,9 @@ public class NodeManager implements Iterable, PropertyChangeListener { /** Map from node ID to node. */ private final Map idNodes = Collections.synchronizedMap(new HashMap()); + /** Map from node to client. */ + private final Map nodeClients = Collections.synchronizedMap(new HashMap()); + /** Collection of currently connected nodes. */ private final Set connectedNodes = Collections.synchronizedSet(new HashSet()); @@ -311,6 +317,22 @@ public class NodeManager implements Iterable, PropertyChangeListener { */ public void connect(Node node) { logger.log(Level.FINEST, "connect(node=" + node + ")"); + if (!nodes.contains(node)) { + logger.log(Level.WARNING, "Was told to connect to node (" + node + ") I don’t know about!"); + return; + } + try { + FcpClient fcpClient = new FcpClient(clientName, node.getHostname(), node.getPort()); + fcpClient.connect(); + nodeClients.put(node, fcpClient); + nodeListenerSupport.fireNodeConnected(node); + } catch (UnknownHostException uhe1) { + nodeListenerSupport.fireNodeConnectionFailed(node, uhe1); + } catch (IOException ioe1) { + nodeListenerSupport.fireNodeConnectionFailed(node, ioe1); + } catch (FcpException fe1) { + nodeListenerSupport.fireNodeConnectionFailed(node, fe1); + } } /** @@ -321,6 +343,10 @@ public class NodeManager implements Iterable, PropertyChangeListener { */ public void disconnect(Node node) { logger.log(Level.FINEST, "disconnect(node=" + node + ")"); + if (!nodes.contains(node)) { + logger.log(Level.WARNING, "Was told to disconnect from a node (" + node + ") I don’t know about!"); + return; + } } /**