Skip to content
Permalink
Browse files

Refactor JMX remote RMI registry creation

  • Loading branch information
rmaucher committed Nov 14, 2019
1 parent 2b2ed21 commit a91d7db4047d372b2f12999d3cf2bc3254c20d00
Showing with 52 additions and 16 deletions.
  1. +49 −16 java/org/apache/catalina/mbeans/JmxRemoteLifecycleListener.java
  2. +3 −0 webapps/docs/changelog.xml
@@ -25,10 +25,11 @@
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.security.NoSuchAlgorithmException;
@@ -300,18 +301,6 @@ private JMXConnectorServer createServer(String serverName,
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";
}
@@ -332,11 +321,20 @@ private JMXConnectorServer createServer(String serverName,
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);
@@ -492,4 +490,39 @@ public boolean equals(Object obj) {
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 };
}
}

}
@@ -85,6 +85,9 @@
the final release. Note that this preview API has deprecated for over a
year and may be removed as soon as the next 8.5.x release. (markt)
</fix>
<fix>
Refactor JMX remote RMI registry creation. (remm)
</fix>
</changelog>
</subsection>
<subsection name="Coyote">

0 comments on commit a91d7db

Please sign in to comment.
You can’t perform that action at this time.