private void configureMBeanServer(BrokerService brokerService, int port) throws IOException {
// shared fs master/slave
brokerService.getPersistenceAdapter().setDirectory(
new File(brokerService.getDataDirectoryFile(), "shared"));
ManagementContext managementContext = brokerService.getManagementContext();
// have mbean servers remain alive - like in karaf container
MBeanServer mbeanServer = MBeanServerFactory.createMBeanServer(managementContext.getJmxDomainName());
Registry registry = LocateRegistry.createRegistry(port + 1);
JMXConnectorServer connectorServer =
JMXConnectorServerFactory.newJMXConnectorServer(
new JMXServiceURL(
"service:jmx:rmi://localhost:" + port + "/jndi/rmi://localhost:" + (port + 1) + "/jmxrmi"),
null, mbeanServer);
connectorServer.start();
serverList.addFirst(connectorServer);
managementContext.setMBeanServer(mbeanServer);
managementContext.setCreateConnector(false);
}