List of usage examples for javax.management MBeanServer getObjectInstance
public ObjectInstance getObjectInstance(ObjectName name) throws InstanceNotFoundException;
From source file:net.sbbi.upnp.jmx.upnp.UPNPConnectorServer.java
public void handleNotification(Notification notification, Object handBack) { if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) { MBeanServerNotification regNot = (MBeanServerNotification) notification; MBeanServer srv = getMBeanServer(); ObjectName name = regNot.getMBeanName(); try {//from ww w . j a v a 2 s.c o m ObjectInstance objIn = srv.getObjectInstance(name); String className = objIn.getClassName(); // do not expose as UPN, UPNP devices exposed as MBeans ( class UPNPServiceMBean purpose ) if (className.equals(UPNPServiceMBean.class.getName())) return; if (builder.select(name, className)) { MBeanInfo info = srv.getMBeanInfo(name); UPNPMBeanDevice dv = builder.buildUPNPMBean(getMBeanServer(), objIn, info); if (dv != null) { dv.setBindAddress(sktAddress); dv.start(); registeredMBeans.put(name.toString(), dv); } } } catch (Exception ex) { log.error("Error during UPNP Mbean device " + name.toString() + " creation", ex); } } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) { MBeanServerNotification regNot = (MBeanServerNotification) notification; String beanName = regNot.getMBeanName().toString(); synchronized (STOP_PROCESS) { UPNPMBeanDevice dv = (UPNPMBeanDevice) registeredMBeans.get(beanName); if (dv != null) { try { dv.stop(); } catch (Exception ex) { log.error("Error during UPNPMBean device stop", ex); } registeredMBeans.remove(beanName); } } } }
From source file:com.googlecode.psiprobe.beans.ContainerListenerBean.java
/** * Load ObjectNames for the relevant MBeans so they can be queried at a later stage without searching MBean server * over and over again.// www .j a v a 2s. c om * * @throws Exception - this method does not handle any of the exceptions that may be thrown when querying MBean server. */ private synchronized void initialize() throws Exception { MBeanServer server = getContainerWrapper().getResourceResolver().getMBeanServer(); String serverName = getContainerWrapper().getTomcatContainer().getName(); Set threadPools = server.queryMBeans(new ObjectName(serverName + ":type=ThreadPool,*"), null); poolNames = new ArrayList(threadPools.size()); for (Iterator it = threadPools.iterator(); it.hasNext();) { ThreadPoolObjectName threadPoolObjectName = new ThreadPoolObjectName(); ObjectName threadPoolName = ((ObjectInstance) it.next()).getObjectName(); String name = threadPoolName.getKeyProperty("name"); threadPoolObjectName.setThreadPoolName(threadPoolName); ObjectName grpName = server .getObjectInstance(new ObjectName( threadPoolName.getDomain() + ":type=GlobalRequestProcessor,name=" + name)) .getObjectName(); threadPoolObjectName.setGlobalRequestProcessorName(grpName); // // unfortunately exact workers could not be found at the time of testing // so we filter out the relevant workers within the loop // Set workers = server .queryMBeans(new ObjectName(threadPoolName.getDomain() + ":type=RequestProcessor,*"), null); for (Iterator wrkIt = workers.iterator(); wrkIt.hasNext();) { ObjectName wrkName = ((ObjectInstance) wrkIt.next()).getObjectName(); if (name.equals(wrkName.getKeyProperty("worker"))) { threadPoolObjectName.getRequestProcessorNames().add(wrkName); } } poolNames.add(threadPoolObjectName); } Set executors = server.queryMBeans(new ObjectName(serverName + ":type=Executor,*"), null); executorNames = new ArrayList(executors.size()); for (Iterator it = executors.iterator(); it.hasNext();) { ObjectName executorName = ((ObjectInstance) it.next()).getObjectName(); executorNames.add(executorName); } // Register with MBean server server.addNotificationListener(new ObjectName("JMImplementation:type=MBeanServerDelegate"), this, null, null); }
From source file:org.opennms.netmgt.eventd.adaptors.EventHandlerMBeanProxy.java
private void findServer() throws InstanceNotFoundException { for (final MBeanServer sx : findMBeanServers()) { try {/*from w w w . ja va 2 s . c o m*/ if (sx.getObjectInstance(m_listener) != null) { m_mbserver = sx; break; } } catch (final InstanceNotFoundException e) { // do nothing } } if (m_mbserver == null) { throw new InstanceNotFoundException("could not locate mbean server instance"); } }