use of org.apache.karaf.management.internal.MBeanInvocationHandler in project karaf by apache.
the class ConnectorServerFactory method init.
public void init() throws Exception {
if (this.server == null) {
throw new IllegalArgumentException("server must be set");
}
JMXServiceURL url = new JMXServiceURL(this.serviceUrl);
setupKarafRMIServerSocketFactory();
if (isClientAuth()) {
this.secured = true;
}
if (this.secured) {
this.setupSsl();
}
if (!AuthenticatorType.PASSWORD.equals(this.authenticatorType)) {
this.environment.remove("jmx.remote.authenticator");
}
MBeanInvocationHandler handler = new MBeanInvocationHandler(server, guard);
MBeanServer guardedServer = (MBeanServer) Proxy.newProxyInstance(server.getClass().getClassLoader(), new Class[] { MBeanServer.class }, handler);
this.connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, this.environment, guardedServer);
if (this.objectName != null) {
this.server.registerMBean(this.connectorServer, this.objectName);
}
try {
if (this.threaded) {
Thread connectorThread = new Thread(() -> {
try {
Thread.currentThread().setContextClassLoader(ConnectorServerFactory.class.getClassLoader());
connectorServer.start();
} catch (IOException ex) {
if (ex.getCause() instanceof BindException) {
// we want just the port message
int endIndex = ex.getMessage().indexOf("nested exception is");
// check to make sure we do not get an index out of range
if (endIndex > ex.getMessage().length() || endIndex < 0) {
endIndex = ex.getMessage().length();
}
throw new RuntimeException("\n" + ex.getMessage().substring(0, endIndex) + "\nYou may have started two containers. If you need to start a second container or the default ports are already in use " + "update the config file etc/org.apache.karaf.management.cfg and change the Registry Port and Server Port to unused ports");
}
throw new RuntimeException("Could not start JMX connector server", ex);
}
});
connectorThread.setName("JMX Connector Thread [" + this.serviceUrl + "]");
connectorThread.setDaemon(this.daemon);
connectorThread.start();
} else {
this.connectorServer.start();
}
} catch (Exception ex) {
doUnregister(this.objectName);
throw ex;
}
}
Aggregations