This is an automated email from the ASF dual-hosted git repository. remm pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push: new 1fc9f58 Refactor JMX remote RMI registry creation 1fc9f58 is described below commit 1fc9f589dbdd8295cf313b2667ab041c425f99c3 Author: remm <r...@apache.org> AuthorDate: Thu Nov 14 13:39:31 2019 +0100 Refactor JMX remote RMI registry creation --- .../mbeans/JmxRemoteLifecycleListener.java | 65 ++++++++++++++++------ webapps/docs/changelog.xml | 7 +++ 2 files changed, 56 insertions(+), 16 deletions(-) diff --git a/java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java b/java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java index 3e472d0..77a785d 100644 --- a/java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java +++ b/java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java @@ -25,10 +25,11 @@ import java.net.MalformedURLException; import java.net.ServerSocket; import java.net.Socket; import java.net.UnknownHostException; +import java.rmi.AccessException; import java.rmi.AlreadyBoundException; +import java.rmi.NotBoundException; +import java.rmi.Remote; import java.rmi.RemoteException; -import java.rmi.registry.LocateRegistry; -import java.rmi.registry.Registry; import java.rmi.server.RMIClientSocketFactory; import java.rmi.server.RMIServerSocketFactory; import java.util.HashMap; @@ -417,18 +418,6 @@ public class JmxRemoteLifecycleListener extends SSLHostConfig implements Lifecyc RMIClientSocketFactory registryCsf, RMIServerSocketFactory registrySsf, RMIClientSocketFactory serverCsf, RMIServerSocketFactory serverSsf) { - // Create the RMI registry - Registry registry; - try { - registry = LocateRegistry.createRegistry( - theRmiRegistryPort, registryCsf, registrySsf); - } catch (RemoteException e) { - log.error(sm.getString( - "jmxRemoteLifecycleListener.createRegistryFailed", - serverName, Integer.toString(theRmiRegistryPort)), e); - return null; - } - if (bindAddress == null) { bindAddress = "localhost"; } @@ -449,11 +438,20 @@ public class JmxRemoteLifecycleListener extends SSLHostConfig implements Lifecyc cs = new RMIConnectorServer(serviceUrl, theEnv, server, ManagementFactory.getPlatformMBeanServer()); cs.start(); - registry.bind("jmxrmi", server.toStub()); + Remote jmxServer = server.toStub(); + // Create the RMI registry + try { + new JmxRegistry(theRmiRegistryPort, registryCsf, registrySsf, "jmxrmi", jmxServer); + } catch (RemoteException e) { + log.error(sm.getString( + "jmxRemoteLifecycleListener.createRegistryFailed", + serverName, Integer.toString(theRmiRegistryPort)), e); + return null; + } log.info(sm.getString("jmxRemoteLifecycleListener.start", Integer.toString(theRmiRegistryPort), Integer.toString(theRmiServerPort), serverName)); - } catch (IOException | AlreadyBoundException e) { + } catch (IOException e) { log.error(sm.getString( "jmxRemoteLifecycleListener.createServerFailed", serverName), e); @@ -589,4 +587,39 @@ public class JmxRemoteLifecycleListener extends SSLHostConfig implements Lifecyc return true; } } + + + private static class JmxRegistry extends sun.rmi.registry.RegistryImpl { + private static final long serialVersionUID = -3772054804656428217L; + private final String jmxName; + private final Remote jmxServer; + public JmxRegistry(int port, RMIClientSocketFactory csf, + RMIServerSocketFactory ssf, String jmxName, Remote jmxServer) throws RemoteException { + super(port, csf, ssf); + this.jmxName = jmxName; + this.jmxServer = jmxServer; + } + @Override + public Remote lookup(String name) + throws RemoteException, NotBoundException { + return (jmxName.equals(name)) ? jmxServer : null; + } + @Override + public void bind(String name, Remote obj) + throws RemoteException, AlreadyBoundException, AccessException { + } + @Override + public void unbind(String name) + throws RemoteException, NotBoundException, AccessException { + } + @Override + public void rebind(String name, Remote obj) + throws RemoteException, AccessException { + } + @Override + public String[] list() throws RemoteException { + return new String[] { jmxName }; + } + } + } diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index efc0ab6..9bbff4c 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -45,6 +45,13 @@ issues do not "pop up" wrt. others). --> <section name="Tomcat 9.0.29 (markt)" rtext="in development"> + <subsection name="Catalina"> + <changelog> + <fix> + Refactor JMX remote RMI registry creation. (remm) + </fix> + </changelog> + </subsection> </section> <section name="Tomcat 9.0.28 (markt)" rtext="release in progress"> <subsection name="Catalina"> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org