public static ManagementRuntimeException wrap(Exception cause) { return new ManagementRuntimeException(cause); }
public static ManagementRuntimeException wrap(String message, Exception cause) { return new ManagementRuntimeException(message, cause); }
protected JMXServiceURL doFormatServerURL(ServerLocatorDescriptor descriptor) { try { return new JMXServiceURL("service:jmx:rmi:///jndi/rmi://localhost:" + descriptor.rmiPort + "/" + descriptor.domainName + "/jmxrmi"); } catch (MalformedURLException e) { throw new ManagementRuntimeException("Cannot format url for " + descriptor.domainName); } }
@Override @SuppressWarnings("cast") public MBeanServer lookupServer(ObjectName qualifiedName) { if (defaultServer.isRegistered(qualifiedName)) { return defaultServer; } for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) { if (server.isRegistered(qualifiedName)) { return server; } } throw new ManagementRuntimeException(qualifiedName + " is not registered"); }
protected <T> T doResolveService(Class<T> resourceClass, ServiceDescriptor descriptor) { T service = Framework.getService(resourceClass); if (service == null) { throw new ManagementRuntimeException("Cannot locate resource using " + resourceClass); } return service; }
protected void doRegisterFactory(ResourceFactoryDescriptor descriptor) { ResourceFactory factory; Class<? extends ResourceFactory> factoryClass = descriptor.getFactoryClass(); try { factory = factoryClass.newInstance(); } catch (ReflectiveOperationException e) { throw new ManagementRuntimeException("Cannot create factory " + factoryClass, e); } factory.configure(ResourcePublisherService.this, descriptor); registry.put(factoryClass, factory); }
protected MBeanServer doCreateServer(final ServerLocatorDescriptor descriptor) { MBeanServer server = MBeanServerFactory.createMBeanServer(); JMXServiceURL url = doFormatServerURL(descriptor); if (!descriptor.remote) { return server; } final RMIConnectorServer connector; try { connector = new RMIConnectorServer(url, null, server); } catch (IOException e) { throw new ManagementRuntimeException("Cannot start connector for " + descriptor.domainName, e); } try { connector.start(); } catch (IOException e) { try { LocateRegistry.createRegistry(descriptor.rmiPort); } catch (RemoteException e2) { throw new ManagementRuntimeException("Cannot start RMI connector for " + descriptor.domainName, e); } try { connector.start(); } catch (IOException e2) { throw new ManagementRuntimeException("Cannot start RMI connector for " + descriptor.domainName, e2); } } assert connector.isActive(); log.info("Started a mbean server : " + url); return server; }