summaryrefslogtreecommitdiff
path: root/java/management/common/src
diff options
context:
space:
mode:
authorRobert Gemmell <robbie@apache.org>2009-12-03 23:06:36 +0000
committerRobert Gemmell <robbie@apache.org>2009-12-03 23:06:36 +0000
commit5020ec12fbf9a7f692c10ef25f332de21840e06a (patch)
tree4793cc472107ec31a76a86fd48afcaa6e9dba30d /java/management/common/src
parentc9703c328a4cc71d8d65388a66ba5419ed551dc5 (diff)
downloadqpid-python-5020ec12fbf9a7f692c10ef25f332de21840e06a.tar.gz
QPID-2152: Update the timeout process so as not to return a null, and close any orphaned connections. Increase default timeout to 15sec.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@886974 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/management/common/src')
-rw-r--r--java/management/common/src/main/java/org/apache/qpid/management/common/JMXConnnectionFactory.java79
1 files changed, 46 insertions, 33 deletions
diff --git a/java/management/common/src/main/java/org/apache/qpid/management/common/JMXConnnectionFactory.java b/java/management/common/src/main/java/org/apache/qpid/management/common/JMXConnnectionFactory.java
index f5831c9e28..c03b782987 100644
--- a/java/management/common/src/main/java/org/apache/qpid/management/common/JMXConnnectionFactory.java
+++ b/java/management/common/src/main/java/org/apache/qpid/management/common/JMXConnnectionFactory.java
@@ -199,25 +199,32 @@ public class JMXConnnectionFactory {
Thread connectorThread = new Thread(connector);
connectorThread.start();
connectorThread.join(timeout);
-
- if (connector.getConnectionException() != null)
+
+ if(connector.getJmxc() == null)
{
- throw connector.getConnectionException();
+ if (connector.getConnectionException() != null)
+ {
+ throw connector.getConnectionException();
+ }
+ else
+ {
+ throw new IOException("Timed out connecting to " + host + ":" + port);
+ }
}
+
return connector.getJmxc();
}
- public static class ConnectWaiter implements Runnable
+ private static class ConnectWaiter implements Runnable
{
- private boolean _connected;
private Exception _connectionException;
private JMXConnector _jmxc;
private JMXServiceURL _jmxUrl;
private Map<String, ?> _env;
+ private boolean _connectionRetrieved;
public ConnectWaiter(JMXServiceURL url, Map<String, ?> env)
{
- super();
_jmxUrl = url;
_env = env;
}
@@ -226,46 +233,52 @@ public class JMXConnnectionFactory {
{
try
{
- setConnected(false);
- setConnectionException(null);
- setJmxc(JMXConnectorFactory.connect(_jmxUrl, _env));
-
- setConnected(true);
+ _jmxc = null;
+ _connectionRetrieved = false;
+ _connectionException = null;
+
+ JMXConnector conn = JMXConnectorFactory.connect(_jmxUrl, _env);
+
+ synchronized (this)
+ {
+ if(_connectionRetrieved)
+ {
+ //The app thread already timed out the attempt and retrieved the
+ //null connection, so just close this orphaned connection
+ try
+ {
+ conn.close();
+ }
+ catch (IOException e)
+ {
+ //ignore
+ }
+ }
+ else
+ {
+ _jmxc = conn;
+ }
+ }
}
catch (Exception ex)
{
- setConnectionException(ex);
+ _connectionException = ex;
}
}
- public void setConnected(boolean _connected)
- {
- this._connected = _connected;
- }
-
- public boolean getConnected()
- {
- return _connected;
- }
-
- public void setConnectionException(Exception _connectionException)
- {
- this._connectionException = _connectionException;
- }
-
public Exception getConnectionException()
{
return _connectionException;
}
- public void setJmxc(JMXConnector _jmxc)
- {
- this._jmxc = _jmxc;
- }
-
public JMXConnector getJmxc()
{
- return _jmxc;
+ synchronized (this)
+ {
+ _connectionRetrieved = true;
+
+ return _jmxc;
+ }
}
}
}