From: markt Date: Wed, 1 Oct 2008 10:47:41 +0000 (+0000) Subject: Move JmxRemote to extras. Fix Tomcat hang on shutdown. Improve logging. Update the... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=4ea247dea22ef778e71761f5845571402829bd69;p=tomcat7.0 Move JmxRemote to extras. Fix Tomcat hang on shutdown. Improve logging. Update the docs. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@700734 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/build.xml b/build.xml index 80481e124..4eeb857d3 100644 --- a/build.xml +++ b/build.xml @@ -259,6 +259,7 @@ + diff --git a/extras.xml b/extras.xml index adf30e0bf..9483269ba 100644 --- a/extras.xml +++ b/extras.xml @@ -82,6 +82,7 @@ + @@ -330,7 +331,20 @@ To run the sample application, copy the following applications into your CATALIN - + + + + + + + + + + + + + diff --git a/java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java b/java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java index 7a84ca627..eca0f35cf 100644 --- a/java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java +++ b/java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java @@ -75,6 +75,9 @@ public class JmxRemoteLifecycleListener implements LifecycleListener { protected String accessFile = null; protected boolean useLocalPorts = false; + protected JMXConnectorServer csPlatform = null; + protected JMXConnectorServer csCatalina = null; + /** * Get the port on which the Platform RMI server is exported. This is the * port that is normally chosen by the RMI stack. @@ -247,16 +250,22 @@ public class JmxRemoteLifecycleListener implements LifecycleListener { // Create the Platform server - createServer(rmiRegistryPortPlatform, rmiServerPortPlatform, env, + csPlatform = createServer("Platform", rmiRegistryPortPlatform, + rmiServerPortPlatform, env, ManagementFactory.getPlatformMBeanServer()); // Create the catalina server - createServer(rmiRegistryPortCatalina, rmiServerPortCatalina, env, + csCatalina = createServer("Catalina", rmiRegistryPortCatalina, + rmiServerPortCatalina, env, MBeanUtils.createServer()); + } else if (Lifecycle.STOP_EVENT == event.getType()) { + destroyServer("Platform", csPlatform); + destroyServer("Catalina", csCatalina); } } - private void createServer(int theRmiRegistryPort, int theRmiServerPort, + private JMXConnectorServer createServer(String serverName, + int theRmiRegistryPort, int theRmiServerPort, HashMap theEnv, MBeanServer theMBeanServer) { // Create the RMI registry @@ -265,8 +274,8 @@ public class JmxRemoteLifecycleListener implements LifecycleListener { } catch (RemoteException e) { log.error(sm.getString( "jmxRemoteLifecycleListener.createRegistryFailed", - Integer.toString(theRmiRegistryPort)), e); - return; + serverName, Integer.toString(theRmiRegistryPort)), e); + return null; } // Build the connection string with fixed ports @@ -282,21 +291,37 @@ public class JmxRemoteLifecycleListener implements LifecycleListener { } catch (MalformedURLException e) { log.error(sm.getString( "jmxRemoteLifecycleListener.invalidURL", - url.toString()), e); - return; + serverName, url.toString()), e); + return null; } // Start the JMX server with the connection string - JMXConnectorServer cs; + JMXConnectorServer cs = null; try { cs = JMXConnectorServerFactory.newJMXConnectorServer( serviceUrl, theEnv, theMBeanServer); cs.start(); log.info(sm.getString("jmxRemoteLifecycleListener.start", Integer.valueOf(theRmiRegistryPort), - Integer.valueOf(theRmiServerPort))); + Integer.valueOf(theRmiServerPort), serverName)); } catch (IOException e) { - log.error(sm.getString(""), e); + log.error(sm.getString( + "jmxRemoteLifecycleListener.createServerFailed", + serverName), e); + } + return cs; + } + + private void destroyServer(String serverName, + JMXConnectorServer theConnectorServer) { + if (theConnectorServer != null) { + try { + theConnectorServer.stop(); + } catch (IOException e) { + log.error(sm.getString( + "jmxRemoteLifecycleListener.destroyServerFailed", + serverName),e); + } } } diff --git a/java/org/apache/catalina/mbeans/LocalStrings.properties b/java/org/apache/catalina/mbeans/LocalStrings.properties index 8c5c7b52d..26ed927bf 100644 --- a/java/org/apache/catalina/mbeans/LocalStrings.properties +++ b/java/org/apache/catalina/mbeans/LocalStrings.properties @@ -13,7 +13,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -jmxRemoteLifecycleListener.createRegistryFailed=Unable to create the RMI registry using port "{0}" -jmxRemoteLifecycleListener.invalidURL=The JMX Service URL requested, "{0}", was invalid -jmxRemoteLifecycleListener.serverFailed=The JMX connector server could not be created or failed to start -jmxRemoteLifecycleListener.start=The JMX Remote Listener has configured the registry on port {0} and the server on port {1} \ No newline at end of file +jmxRemoteLifecycleListener.createRegistryFailed=Unable to create the RMI registry for the {0} server using port {1} +jmxRemoteLifecycleListener.createServerFailed=The JMX connector server could not be created or failed to start for the {0} server +jmxRemoteLifecycleListener.destroyServerFailed=The JMX connector server could not be stopped for the {0} server +jmxRemoteLifecycleListener.invalidURL=The JMX Service URL requested for the {0} server, "{1}", was invalid +jmxRemoteLifecycleListener.start=The JMX Remote Listener has configured the registry on port {0} and the server on port {1} for the {2} server diff --git a/webapps/docs/config/listeners.xml b/webapps/docs/config/listeners.xml index 616fd664f..7fe1b778f 100644 --- a/webapps/docs/config/listeners.xml +++ b/webapps/docs/config/listeners.xml @@ -138,6 +138,10 @@

JMX Remote Lifecycle Listener (org.apache.catalina.mbeans.JmxRemoteLifecycleListener)

+

This listener requires catalina-jmx-remote.jar to be placed + in $CATALINA_HOME/lib. This jar may be found in the extras + directory of the binary download area.

+

The JMX Remote Lifecycle Listener fixes the port used by the JMX/RMI Server making things much simpler if you need to connect jconsole or a similar tool to a remote Tomcat instance that is running @@ -151,7 +155,8 @@

If this listener was configured in server.xml as: <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" - rmiRegistryPort="10001" rmiServerPort="10002" /> + rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002" + rmiRegistryPortCatalina="10003" rmiServerPortCatalina="10004" /> with the following system properties set (eg in setenv.sh):