List of usage examples for javax.management MBeanServerFactory findMBeanServer
public synchronized static ArrayList<MBeanServer> findMBeanServer(String agentId)
Return a list of registered MBeanServer objects.
From source file:com.atolcd.alfresco.audit.cmr.AbstractJMXInfoGet.java
protected MBeanServer getMBeanServerWithQuery(ObjectName query) { if (knownMBeanServersWithQuery.containsKey(query)) { return knownMBeanServersWithQuery.get(query); }//from w w w .j a va2s. c o m // no cached instances, search high and low... MBeanServer mbeanServer = null; final List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null); for (int i = 0; mbeanServer == null && i < servers.size(); i++) { if (servers.get(i).queryNames(query, null) != null) { mbeanServer = servers.get(i); } } if (mbeanServer == null) { // oh well, most likely it is here then... mbeanServer = getPlatformMBeanServer(); } knownMBeanServersWithQuery.put(query, mbeanServer); return mbeanServer; }
From source file:com.amazonaws.client.metrics.jmx.MBeans.java
/** * Returns the first registered MBean server, or the platform MBean server * if there is none./*from w w w .ja v a 2s . co m*/ */ public static MBeanServer getMBeanServer() { List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null); MBeanServer server = servers.size() > 0 ? servers.get(0) : ManagementFactory.getPlatformMBeanServer(); return server; }
From source file:com.googlecode.arit.mbeans.MBeanScanner.java
public void clean(ClassLoader classLoader) { ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null); for (MBeanServer mbs : mbeanServers) { MBeanAccessor mbeanAccessor = mbsInspector.inspect(mbs); if (mbeanAccessor == null) { String errorMsg = "Unable to inspect MBeanServer of type " + mbs.getClass().getName(); LOG.error(errorMsg);//from w w w.j a va 2s .c o m if (messages != null) { messages.addMessage(errorMsg); } } else { Set<ObjectName> mbeans; try { mbeans = mbs.queryNames(new ObjectName("*:*"), null); } catch (MalformedObjectNameException ex) { // We should never get here throw new Error(ex); } for (ObjectName name : mbeans) { Object mbean = mbeanAccessor.retrieve(name); if (mbean.getClass().getClassLoader().equals(classLoader)) { try { mbs.unregisterMBean(name); } catch (JMException ex) { String errorMsg = "Error during cleanup of mbean - unregistration of mbean " + name.toString() + " failed"; LOG.error(errorMsg, ex); if (messages != null) { messages.addMessage(errorMsg); } } } } } } }
From source file:chronos.web.listener.ChronosServletListener.java
/** * {@inheritDoc}//from w ww .j av a2 s . c o m * * @see javax.servlet.ServletContextListener#contextDestroyed(javax.servlet.ServletContextEvent) */ public void contextDestroyed(final ServletContextEvent event) { logger.debug("Chronos is shutting down..."); final ArrayList<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null); logger.debug("Got " + servers.size() + " MBean servers"); if (servers.size() != 0) { final MBeanServer mbeanServer = servers.get(0); try { final ObjectName objectName = new ObjectName(CHRONOS, "type", QUARTZ_SCHEDULER_ADAPTER); logger.debug("Invoking shutdown() on QuartzSchedulerAdapter..."); mbeanServer.invoke(objectName, "shutdown", null, null); logger.debug("Unregistering QuartzSchedulerAdapter Mbean"); mbeanServer.unregisterMBean(objectName); } catch (final JMException e) { logger.error("Shutting down QuartzSchedulerAdapter failed: " + e.getMessage(), e); } catch (final NullPointerException e) { logger.error("Shutting down QuartzSchedulerAdapter failed: " + e.getMessage(), e); } } else { logger.warn("Unable to find MBeanServer!"); } logger.info("Chronos shutdown"); }
From source file:net.zcarioca.jmx.services.impl.MBeanObjectServiceImpl.java
private MBeanServer getPlatformMBeanServer() { synchronized (mbeanServer) { if (mbeanServer == null) { // find the JBoss mbean server, if it exists Collection<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null); if (mbeanServers != null) { if (mbeanServers.size() == 1) { return mbeanServers.iterator().next(); } else if (mbeanServers.size() > 1) { for (MBeanServer mbeanServer : mbeanServers) { String domain = mbeanServer.getDefaultDomain(); if (StringUtils.contains(domain, "jboss")) { return mbeanServer; }//w w w .j a va 2 s. co m } } } mbeanServer = ManagementFactory.getPlatformMBeanServer(); } return mbeanServer; } }
From source file:org.mule.management.agents.JmxAgent.java
public void initialise() throws InitialisationException { if (initialized) { return;//from w ww . j a v a 2s .c om } if (!locateServer && !createServer) { throw new InitialisationException(new Message(Messages.JMX_CREATE_OR_LOCATE_SHOULD_BE_SET), this); } if (mBeanServer == null && locateServer) { List l = MBeanServerFactory.findMBeanServer(null); if (l != null && l.size() > 0) { mBeanServer = (MBeanServer) l.get(0); } } if (mBeanServer == null && createServer) { mBeanServer = MBeanServerFactory.createMBeanServer(); serverCreated = true; } if (mBeanServer == null) { throw new InitialisationException(new Message(Messages.JMX_CANT_LOCATE_CREATE_SERVER), this); } if (connectorServerUrl != null) { try { JMXServiceURL url = new JMXServiceURL(connectorServerUrl); if (!credentials.isEmpty()) { JMXAuthenticator jmxAuthenticator = new SimplePasswordJmxAuthenticator(); ((SimplePasswordJmxAuthenticator) jmxAuthenticator).setCredentials(credentials); connectorServerProperties.put(JMXConnectorServer.AUTHENTICATOR, jmxAuthenticator); } connectorServer = JMXConnectorServerFactory.newJMXConnectorServer(url, connectorServerProperties, mBeanServer); } catch (Exception e) { throw new InitialisationException(new Message(Messages.FAILED_TO_CREATE_X, "Jmx Connector"), e, this); } } // We need to register all the services once the server has initialised MuleManager.getInstance().registerListener(new ModelEventListener() { public void onEvent(UMOServerEvent event) { if (event.getAction() == ModelEvent.MODEL_STARTED) { try { registerStatisticsService(); registerMuleService(); registerConfigurationService(); registerModelService(); registerComponentServices(); registerEndpointServices(); registerConnectorServices(); } catch (Exception e) { throw new MuleRuntimeException(new Message(Messages.X_FAILED_TO_INITIALISE, "MBeans"), e); } } } }); initialized = true; }
From source file:org.ow2.proactive.resourcemanager.core.jmx.RMJMXHelper.java
/** * Return a list of registered MBeanServers. * * @param agentId the agentId of the MBeanServer to find. *//* w ww . j a v a 2 s . com*/ public static ArrayList<MBeanServer> findMBeanServer(String agentId) { return MBeanServerFactory.findMBeanServer(agentId); }
From source file:org.nuxeo.runtime.management.ServerLocatorService.java
@SuppressWarnings("cast") protected MBeanServer doFindServer(String domainName) { for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) { String domain = server.getDefaultDomain(); if (domain == null || !domain.equals(domainName)) { continue; }/* w ww . ja v a 2 s .co m*/ return server; } return defaultServer; }
From source file:org.jpos.q2.Q2.java
public void run() { started = true;//from www.ja v a 2 s . c o m Thread.currentThread().setName("Q2-" + getInstanceId().toString()); try { /* * The following code determines whether a MBeanServer exists * already. If so then the first one in the list is used. * I have not yet find a way to interrogate the server for * information other than MBeans so to pick a specific one * would be difficult. */ ArrayList mbeanServerList = MBeanServerFactory.findMBeanServer(null); if (mbeanServerList.isEmpty()) { server = MBeanServerFactory.createMBeanServer(JMX_NAME); } else { server = (MBeanServer) mbeanServerList.get(0); } final ObjectName loaderName = new ObjectName(Q2_CLASS_LOADER); try { loader = (QClassLoader) java.security.AccessController .doPrivileged(new java.security.PrivilegedAction() { public Object run() { return new QClassLoader(server, libDir, loaderName, mainClassLoader); } }); server.registerMBean(loader, loaderName); loader = loader.scan(false); } catch (Throwable t) { if (log != null) log.error("initial-scan", t); else t.printStackTrace(); } factory = new QFactory(loaderName, this); initSystemLogger(); if (bundleContext == null) addShutdownHook(); q2Thread = Thread.currentThread(); q2Thread.setContextClassLoader(loader); if (cli != null) cli.start(); initConfigDecorator(); if (startOSGI) startOSGIFramework(); for (int i = 1; !shutdown; i++) { try { boolean forceNewClassLoader = scan(); QClassLoader oldClassLoader = loader; loader = loader.scan(forceNewClassLoader); if (loader != oldClassLoader) { oldClassLoader = null; // We want this to be null so it gets GCed. System.gc(); // force a GC log.info("new classloader [" + Integer.toString(loader.hashCode(), 16) + "] has been created"); } deploy(); checkModified(); relax(SCAN_INTERVAL); if (i % (3600000 / SCAN_INTERVAL) == 0) logVersion(); } catch (Throwable t) { log.error("start", t); relax(); } } undeploy(); try { server.unregisterMBean(loaderName); } catch (InstanceNotFoundException e) { log.error(e); } if (decorator != null) { decorator.uninitialize(); } if (exit && !shuttingDown) System.exit(0); } catch (Exception e) { if (log != null) log.error(e); else e.printStackTrace(); System.exit(1); } }
From source file:org.nuxeo.runtime.management.ServerLocatorService.java
@Override @SuppressWarnings("cast") public MBeanServer lookupServer(ObjectName qualifiedName) { if (defaultServer.isRegistered(qualifiedName)) { return defaultServer; }/*from w w w . j a v a2 s . co m*/ for (MBeanServer server : MBeanServerFactory.findMBeanServer(null)) { if (server.isRegistered(qualifiedName)) { return server; } } throw new ManagementRuntimeException(qualifiedName + " is not registered"); }