use of java.rmi.server.RMIServerSocketFactory in project hbase by apache.
the class JMXListener method startConnectorServer.
public void startConnectorServer(int rmiRegistryPort, int rmiConnectorPort) throws IOException {
boolean rmiSSL = false;
boolean authenticate = true;
String passwordFile = null;
String accessFile = null;
System.setProperty("java.rmi.server.randomIDs", "true");
String rmiSSLValue = System.getProperty("com.sun.management.jmxremote.ssl", "false");
rmiSSL = Boolean.parseBoolean(rmiSSLValue);
String authenticateValue = System.getProperty("com.sun.management.jmxremote.authenticate", "false");
authenticate = Boolean.parseBoolean(authenticateValue);
passwordFile = System.getProperty("com.sun.management.jmxremote.password.file");
accessFile = System.getProperty("com.sun.management.jmxremote.access.file");
LOG.info("rmiSSL:" + rmiSSLValue + ",authenticate:" + authenticateValue + ",passwordFile:" + passwordFile + ",accessFile:" + accessFile);
// Environment map
HashMap<String, Object> jmxEnv = new HashMap<>();
RMIClientSocketFactory csf = null;
RMIServerSocketFactory ssf = null;
if (rmiSSL) {
if (rmiRegistryPort == rmiConnectorPort) {
throw new IOException("SSL is enabled. " + "rmiConnectorPort cannot share with the rmiRegistryPort!");
}
csf = new SslRMIClientSocketFactorySecure();
ssf = new SslRMIServerSocketFactorySecure();
}
if (csf != null) {
jmxEnv.put(RMIConnectorServer.RMI_CLIENT_SOCKET_FACTORY_ATTRIBUTE, csf);
}
if (ssf != null) {
jmxEnv.put(RMIConnectorServer.RMI_SERVER_SOCKET_FACTORY_ATTRIBUTE, ssf);
}
// Configure authentication
if (authenticate) {
jmxEnv.put("jmx.remote.x.password.file", passwordFile);
jmxEnv.put("jmx.remote.x.access.file", accessFile);
}
// Create the RMI registry
rmiRegistry = LocateRegistry.createRegistry(rmiRegistryPort);
// Retrieve the PlatformMBeanServer.
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// Build jmxURL
JMXServiceURL serviceUrl = buildJMXServiceURL(rmiRegistryPort, rmiConnectorPort);
try {
// Start the JMXListener with the connection string
synchronized (JMXListener.class) {
if (JMX_CS != null) {
throw new RuntimeException("Started by another thread?");
}
JMX_CS = JMXConnectorServerFactory.newJMXConnectorServer(serviceUrl, jmxEnv, mbs);
JMX_CS.start();
}
LOG.info("JMXConnectorServer started!");
} catch (IOException e) {
LOG.error("Failed start of JMXConnectorServer!", e);
// deregister the RMI registry
if (rmiRegistry != null) {
UnicastRemoteObject.unexportObject(rmiRegistry, true);
}
}
}
Aggregations