From f7bfc2672693384db5c7a9ee252f6a548e513489 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Mon, 12 May 2008 16:24:14 +0000 Subject: [PATCH] fix waiting when finding unused connection remove client from used connections when disconnecting git-svn-id: http://trooper/svn/projects/jSite/trunk@803 c3eda9e8-030b-0410-8277-bc7414b0a119 --- src/net/pterodactylus/jsite/core/NodeManager.java | 40 +++++++++++++---------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/net/pterodactylus/jsite/core/NodeManager.java b/src/net/pterodactylus/jsite/core/NodeManager.java index 5ed51a7..fe52fd7 100644 --- a/src/net/pterodactylus/jsite/core/NodeManager.java +++ b/src/net/pterodactylus/jsite/core/NodeManager.java @@ -43,7 +43,7 @@ import net.pterodactylus.util.logging.Logging; /** * TODO - * + * * @author David ‘Bombe’ Roden <bombe@freenetproject.org> * @version $Id$ */ @@ -78,7 +78,7 @@ public class NodeManager implements HighLevelClientListener { /** * Creates a new FCP collector. - * + * * @param clientName * The name of the FCP client * @param directory @@ -95,7 +95,7 @@ public class NodeManager implements HighLevelClientListener { /** * Adds the given listener to the list of listeners. - * + * * @param nodeListener * The listener to add */ @@ -105,7 +105,7 @@ public class NodeManager implements HighLevelClientListener { /** * Removes the given listener from the list of listeners. - * + * * @param nodeListener * The listener to remove */ @@ -115,7 +115,7 @@ public class NodeManager implements HighLevelClientListener { /** * Notifies all listeners that the given node was connected. - * + * * @param node * The node that is now connected */ @@ -127,7 +127,7 @@ public class NodeManager implements HighLevelClientListener { /** * Notifies all listeners that the given node was disconnected. - * + * * @param node * The node that is now disconnected * @param throwable @@ -146,7 +146,7 @@ public class NodeManager implements HighLevelClientListener { /** * Returns the directory in which the nodes are stored. - * + * * @return The directory the nodes are stored in */ public String getDirectory() { @@ -155,7 +155,7 @@ public class NodeManager implements HighLevelClientListener { /** * Checks whether the given node is already connected. - * + * * @param node * The node to check * @return true if the node is already connected, @@ -171,7 +171,7 @@ public class NodeManager implements HighLevelClientListener { /** * Loads nodes. - * + * * @throws IOException * if an I/O error occurs loading the nodes */ @@ -230,7 +230,7 @@ public class NodeManager implements HighLevelClientListener { /** * Saves all configured nodes. - * + * * @throws IOException * if an I/O error occurs saving the nodes */ @@ -261,7 +261,7 @@ public class NodeManager implements HighLevelClientListener { /** * Adds the given node to this manager. - * + * * @see #connect(Node) * @param node * The node to connect to @@ -277,7 +277,7 @@ public class NodeManager implements HighLevelClientListener { /** * Removes the given node from the node manager, disconnecting it if it is * currently connected. - * + * * @param node * The node to remove */ @@ -294,7 +294,7 @@ public class NodeManager implements HighLevelClientListener { /** * Tries to establish a connection with the given node. - * + * * @param node * The node to connect to */ @@ -314,7 +314,7 @@ public class NodeManager implements HighLevelClientListener { /** * Disconnects the given node without removing it. - * + * * @param node * The node to disconnect */ @@ -330,7 +330,7 @@ public class NodeManager implements HighLevelClientListener { /** * Returns a list of all nodes. - * + * * @return A list of all nodes */ public List getNodes() { @@ -344,7 +344,7 @@ public class NodeManager implements HighLevelClientListener { /** * Finds a currently unused high-level client, optionally waiting until a * client is free and marking it used. - * + * * @param wait * true to wait for a free connection, * false to return null @@ -374,6 +374,11 @@ public class NodeManager implements HighLevelClientListener { if (!wait) { return null; } + try { + syncObject.wait(); + } catch (InterruptedException e) { + /* ignore, just re-check. */ + } } /* we never get here, but the compiler doesn't realize. */ return null; @@ -401,7 +406,7 @@ public class NodeManager implements HighLevelClientListener { * {@inheritDoc} */ public void clientDisconnected(HighLevelClient highLevelClient, Throwable throwable) { - logger.log(Level.FINER, "clientDisconnected(c=" + highLevelClient + ",t=" + throwable +")"); + logger.log(Level.FINER, "clientDisconnected(c=" + highLevelClient + ",t=" + throwable + ")"); synchronized (syncObject) { Node node = clientNodes.remove(highLevelClient); if (node == null) { @@ -409,6 +414,7 @@ public class NodeManager implements HighLevelClientListener { return; } nodeClients.remove(node); + usedConnections.remove(highLevelClient); fireNodeDisconnected(node, throwable); } } -- 2.7.4