[jboss-cvs] JBossAS SVN: r105008 - in trunk: console/src/main/java/org/jboss/console/twiddle/command and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Wed May 19 21:47:37 EDT 2010
Author: smarlow at redhat.com
Date: 2010-05-19 21:47:36 -0400 (Wed, 19 May 2010)
New Revision: 105008
Modified:
trunk/console/src/main/java/org/jboss/console/twiddle/Twiddle.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/CommandContext.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/CreateCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/GetCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/InfoCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/InvokeCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/JSR77Command.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/ListDomainsCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/MBeanServerCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/QueryMethodCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/ServerInfoCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/SetAttrsCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/SetCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/UnregisterCommand.java
trunk/console/src/main/java/org/jboss/console/twiddle/command/XMBeanCommand.java
trunk/server/src/main/java/org/jboss/Shutdown.java
trunk/system/src/main/java/org/jboss/system/server/jmx/JMXAdapter.java
Log:
JBAS-8034 The JMXConnector returned from javax.management.remote.JMXConnectorFactory.connect(JMXServiceURL, environment) needs to be closed when server connection is no longer needed.
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/Twiddle.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/Twiddle.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/Twiddle.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -85,6 +85,7 @@
private String port;
private boolean quiet;
private MBeanServerConnection server;
+ JMXConnector jmxc;
private String username;
private String password;
private boolean verbose;
@@ -182,6 +183,20 @@
return err;
}
+ public void closeServer()
+ {
+ if (jmxc != null)
+ {
+ server = null;
+ try {
+ jmxc.close();
+ } catch (IOException e) {
+ throw new org.jboss.util.NestedRuntimeException(e);
+ }
+ }
+
+ }
+
public MBeanServerConnection getServer()
{
try
@@ -275,7 +290,7 @@
out.flush();
}
- private MBeanServerConnection createMBeanServerConnection()
+ private JMXConnector createMBeanServerConnection()
throws NamingException, IOException
{
HashMap env = new HashMap();
@@ -292,7 +307,7 @@
}
JMXServiceURL url = new JMXServiceURL(this.serverURL);
JMXConnector jmxc = JMXConnectorFactory.connect(url, env);
- return jmxc.getMBeanServerConnection();
+ return jmxc;
}
private void connect()
@@ -300,7 +315,9 @@
{
if (server == null)
{
- server = createMBeanServerConnection();
+ jmxc = createMBeanServerConnection();
+ server = jmxc.getMBeanServerConnection();
+
}
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/CommandContext.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/CommandContext.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/CommandContext.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -52,4 +52,6 @@
//
MBeanServerConnection getServer();
+
+ void closeServer();
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/CreateCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/CreateCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/CreateCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -173,5 +173,6 @@
out.println(obj.getObjectName());
out.flush();
}
+ closeServer();
}
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/GetCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/GetCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/GetCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -190,5 +190,6 @@
}
out.println(attr.getValue());
}
+ closeServer();
}
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/InfoCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/InfoCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/InfoCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -171,5 +171,6 @@
}
out.println(')');
}
+ closeServer();
}
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/InvokeCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/InvokeCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/InvokeCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -265,6 +265,7 @@
out.println(resultText);
out.flush();
}
+ closeServer();
}
public void execute(String[] args) throws Exception
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/JSR77Command.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/JSR77Command.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/JSR77Command.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -136,6 +136,7 @@
printJsr77Node(server, (ObjectName)i.next(), out, 0);
}
out.flush();
+ super.closeServer();
}
/**
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/ListDomainsCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/ListDomainsCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/ListDomainsCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -116,6 +116,7 @@
}
out.flush();
+ closeServer();
}
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/MBeanServerCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/MBeanServerCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/MBeanServerCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -53,7 +53,12 @@
throw new CommandException("Invalid object name: " + name);
}
}
-
+
+ protected void closeServer()
+ {
+ context.closeServer();
+ }
+
protected MBeanServerConnection getMBeanServer()
{
return context.getServer();
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/QueryMethodCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/QueryMethodCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/QueryMethodCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -188,6 +188,7 @@
}
}
}
+ closeServer();
return hits;
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/ServerInfoCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/ServerInfoCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/ServerInfoCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -154,5 +154,6 @@
}
out.flush();
+ closeServer();
}
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/SetAttrsCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/SetAttrsCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/SetAttrsCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -188,6 +188,7 @@
System.out.println(a.getName() + "=" + a.getValue());
}
}
+ closeServer();
}
private MBeanAttributeInfo findAttribute(String attr_name,
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/SetCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/SetCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/SetCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -198,8 +198,7 @@
out.println(nat.toString());
}
}
-
-
+ closeServer();
}
/**
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/UnregisterCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/UnregisterCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/UnregisterCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -132,5 +132,6 @@
ObjectName name = (ObjectName)iter.next();
server.unregisterMBean(name);
}
+ closeServer();
}
}
Modified: trunk/console/src/main/java/org/jboss/console/twiddle/command/XMBeanCommand.java
===================================================================
--- trunk/console/src/main/java/org/jboss/console/twiddle/command/XMBeanCommand.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/console/src/main/java/org/jboss/console/twiddle/command/XMBeanCommand.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -193,6 +193,7 @@
out.println("</mbean>");
out.flush();
+ closeServer();
}
private void outputParameters(PrintWriter out, MBeanParameterInfo[] params)
Modified: trunk/server/src/main/java/org/jboss/Shutdown.java
===================================================================
--- trunk/server/src/main/java/org/jboss/Shutdown.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/server/src/main/java/org/jboss/Shutdown.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -243,6 +243,7 @@
System.out.println("Shutdown message has been posted to the server.");
System.out.println("Server shutdown may take a while - check logfiles for completion");
+ jmxc.close();
}
private static class ServerProxyHandler implements InvocationHandler
Modified: trunk/system/src/main/java/org/jboss/system/server/jmx/JMXAdapter.java
===================================================================
--- trunk/system/src/main/java/org/jboss/system/server/jmx/JMXAdapter.java 2010-05-20 00:54:20 UTC (rev 105007)
+++ trunk/system/src/main/java/org/jboss/system/server/jmx/JMXAdapter.java 2010-05-20 01:47:36 UTC (rev 105008)
@@ -21,15 +21,17 @@
*/
package org.jboss.system.server.jmx;
-import javax.management.remote.JMXConnectorFactory;
-import javax.management.remote.JMXServiceURL;
+import javax.management.remote.*;
import javax.naming.Context;
import javax.naming.Name;
import javax.naming.RefAddr;
import javax.naming.Reference;
import javax.naming.spi.ObjectFactory;
+import java.io.IOException;
import java.util.HashMap;
import java.util.Hashtable;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
/**
* RMIAdapter replacement using JMXConnector
@@ -37,6 +39,8 @@
*
*/
public class JMXAdapter implements ObjectFactory {
+ // cache the connection to the server so that we don't leak each new JMXConnector
+ private static Map<String,javax.management.remote.JMXConnector> jmxConnectorMap = new ConcurrentHashMap<String,javax.management.remote.JMXConnector>();
public JMXAdapter() {
@@ -49,9 +53,30 @@
RefAddr urlRef = ref.get("JMXServiceURL");
String url = (String)urlRef.getContent();
JMXServiceURL jmxserviceURL = new JMXServiceURL(url);
- // TODO: security...
- HashMap env = new HashMap();
- javax.management.remote.JMXConnector jmxc = JMXConnectorFactory.connect(jmxserviceURL, env);
+ javax.management.remote.JMXConnector jmxc = null;
+ jmxc = jmxConnectorMap.get(url);
+
+ if(jmxc != null) {
+ try {
+ // attempt to detect that the cached connection is broken
+ jmxc.getConnectionId();
+ }
+ catch(IOException e) {
+ try {
+ jmxc.close(); // clean up any local resources associated with the connection (e.g. background threads)
+ }
+ catch( IOException ignore)
+ {
+
+ }
+ jmxc = null; // ignore the broken connection and get a new one
+ }
+ }
+
+ if(jmxc == null) {
+ jmxc = JMXConnectorFactory.connect(jmxserviceURL, new HashMap());
+ jmxConnectorMap.put(url, jmxc);
+ }
return jmxc.getMBeanServerConnection();
}
return null;
More information about the jboss-cvs-commits
mailing list