HBASE-16723 RMI registry is not destroyed after stopping JMX Connector Server (Pankaj Kumar)

This commit is contained in:
tedyu 2016-09-29 01:57:54 -07:00
parent 09a31bd1e9
commit f3270d44c3
1 changed files with 13 additions and 4 deletions

View File

@ -27,8 +27,10 @@ import org.apache.hadoop.hbase.coprocessor.*;
import java.io.IOException; import java.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.rmi.registry.LocateRegistry; import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.RMIClientSocketFactory; import java.rmi.server.RMIClientSocketFactory;
import java.rmi.server.RMIServerSocketFactory; import java.rmi.server.RMIServerSocketFactory;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap; import java.util.HashMap;
import javax.management.MBeanServer; import javax.management.MBeanServer;
@ -36,8 +38,6 @@ import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL; import javax.management.remote.JMXServiceURL;
import javax.management.remote.rmi.RMIConnectorServer; import javax.management.remote.rmi.RMIConnectorServer;
import javax.rmi.ssl.SslRMIClientSocketFactory;
import javax.rmi.ssl.SslRMIServerSocketFactory;
/** /**
* Pluggable JMX Agent for HBase(to fix the 2 random TCP ports issue * Pluggable JMX Agent for HBase(to fix the 2 random TCP ports issue
@ -61,6 +61,7 @@ public class JMXListener implements Coprocessor {
* we only load regionserver coprocessor on master * we only load regionserver coprocessor on master
*/ */
private static JMXConnectorServer JMX_CS = null; private static JMXConnectorServer JMX_CS = null;
private Registry rmiRegistry = null;
public static JMXServiceURL buildJMXServiceURL(int rmiRegistryPort, public static JMXServiceURL buildJMXServiceURL(int rmiRegistryPort,
int rmiConnectorPort) throws IOException { int rmiConnectorPort) throws IOException {
@ -128,7 +129,7 @@ public class JMXListener implements Coprocessor {
} }
// Create the RMI registry // Create the RMI registry
LocateRegistry.createRegistry(rmiRegistryPort); rmiRegistry = LocateRegistry.createRegistry(rmiRegistryPort);
// Retrieve the PlatformMBeanServer. // Retrieve the PlatformMBeanServer.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
@ -147,6 +148,10 @@ public class JMXListener implements Coprocessor {
LOG.info("ConnectorServer started!"); LOG.info("ConnectorServer started!");
} catch (IOException e) { } catch (IOException e) {
LOG.error("fail to start connector server!", e); LOG.error("fail to start connector server!", e);
// deregister the RMI registry
if (rmiRegistry != null) {
UnicastRemoteObject.unexportObject(rmiRegistry, true);
}
} }
} }
@ -158,6 +163,10 @@ public class JMXListener implements Coprocessor {
LOG.info("ConnectorServer stopped!"); LOG.info("ConnectorServer stopped!");
JMX_CS = null; JMX_CS = null;
} }
// deregister the RMI registry
if (rmiRegistry != null) {
UnicastRemoteObject.unexportObject(rmiRegistry, true);
}
} }
} }