List of usage examples for javax.management MBeanServer queryNames
public Set<ObjectName> queryNames(ObjectName name, QueryExp query);
From source file:psiprobe.beans.ResourceResolverBean.java
@Override public List<ApplicationResource> getApplicationResources() throws NamingException { logger.info("Reading GLOBAL resources"); List<ApplicationResource> resources = new ArrayList<>(); MBeanServer server = getMBeanServer(); if (server != null) { try {/*w w w . j ava 2s . c o m*/ Set<ObjectName> dsNames = server .queryNames(new ObjectName("Catalina:type=Resource,resourcetype=Global,*"), null); for (ObjectName objectName : dsNames) { ApplicationResource resource = new ApplicationResource(); logger.info("reading resource: {}", objectName); resource.setName(getStringAttribute(server, objectName, "name")); resource.setType(getStringAttribute(server, objectName, "type")); resource.setScope(getStringAttribute(server, objectName, "scope")); resource.setAuth(getStringAttribute(server, objectName, "auth")); resource.setDescription(getStringAttribute(server, objectName, "description")); lookupResource(resource, true, true); resources.add(resource); } } catch (Exception e) { logger.error("There was an error querying JMX server:", e); } } return resources; }
From source file:com.avanza.ymer.YmerMirrorIntegrationTest.java
@Test public void mbeanInvoke() throws Exception { MBeanServer server = ManagementFactory.getPlatformMBeanServer(); ObjectName nameTemplate = ObjectName.getInstance( "se.avanzabank.space.mirror:type=DocumentWriteExceptionHandler,name=documentWriteExceptionHandler"); Set<ObjectName> names = server.queryNames(nameTemplate, null); assertThat(names.size(), is(greaterThan(0))); server.invoke(names.toArray(new ObjectName[1])[0], "useCatchesAllHandler", null, null); }
From source file:org.wso2.carbon.business.messaging.core.internal.BrokerServiceComponent.java
/** * Check if the broker is up and running * * @return true if the broker is running or false otherwise *//*from w w w . jav a 2 s. co m*/ private boolean isBrokerRunning() { boolean response = false; try { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> set = mBeanServer.queryNames(new ObjectName(BrokerConstants.VIRTUAL_HOST_MBEAN), null); if (set.size() > 0) { // Virtual hosts created, hence broker running. response = true; } } catch (MalformedObjectNameException e) { //We do not propagate the exception further since the framework would re attempt to activate the bundle String error = "Error checking if broker is running."; log.error(error, e); } return response; }
From source file:org.apache.geode.management.internal.cli.commands.CreateAlterDestroyRegionCommandsDUnitTest.java
private Callable<Boolean> newRegionMBeanIsCreated(final String regionPath) { return () -> { try {/* w ww . j a v a 2 s . c o m*/ MBeanServer mbeanServer = MBeanJMXAdapter.mbeanServer; String queryExp = MessageFormat.format(ManagementConstants.OBJECTNAME__REGION_MXBEAN, regionPath, "*"); ObjectName queryExpON = new ObjectName(queryExp); return mbeanServer.queryNames(null, queryExpON).size() == 1; } catch (MalformedObjectNameException mone) { getLogWriter().error(mone); fail(mone.getMessage()); return false; } }; }
From source file:org.apache.axis2.transport.base.AbstractTransportSender.java
private void registerMBean(MBeanServer mbs, Object mbeanInstance, String objectName) { try {/* w w w . ja va 2 s .c o m*/ ObjectName name = new ObjectName(objectName); Set set = mbs.queryNames(name, null); if (set != null && set.isEmpty()) { mbs.registerMBean(mbeanInstance, name); } else { mbs.unregisterMBean(name); mbs.registerMBean(mbeanInstance, name); } } catch (Exception e) { log.warn("Error registering a MBean with objectname ' " + objectName + " ' for JMX management", e); } }
From source file:org.wso2.carbon.andes.internal.QpidServiceComponent.java
/** * Check if the broker is up and running * * @return true if the broker is running or false otherwise *///from w w w .j a v a 2 s . c om private boolean isBrokerRunning() { boolean response = false; try { MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> set = mBeanServer .queryNames(new ObjectName("org.wso2.andes:type=VirtualHost.VirtualHostManager,*"), null); if (set.size() > 0) { // Virtual hosts created, hence broker running. response = true; } } catch (MalformedObjectNameException e) { log.error("Error checking if broker is running.", e); } return response; }
From source file:com.googlecode.arit.mbeans.MBeanScanner.java
public void scanForResources(ResourceListener resourceEventListener) { 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 ww . j ava 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); SimpleResource<Object> mbeanResource = new SimpleResource<Object>(resourceType, mbean, "MBean: " + name); mbeanResource.addClassloaderReference(mbean.getClass().getClassLoader(), "Implementation class: " + mbean.getClass().getName()); resourceEventListener.onResourceFound(mbeanResource); } } } }
From source file:org.mc4j.ems.impl.jmx.connection.DConnection.java
@SuppressWarnings({ "unchecked" }) public synchronized void loadSynchronous(boolean deep) { if (!connectionProvider.isConnected()) connectionProvider.connect();// w w w .ja v a 2s. c om log.info("Querying MBeanServer for all MBeans..."); MBeanServer mBeanServer = connectionProvider.getMBeanServer(); Set<ObjectName> objectNames = null; try { objectNames = (Set<ObjectName>) mBeanServer.queryNames(new ObjectName("*:*"), null); } catch (MalformedObjectNameException e) { /* Should never happen */ } SortedMap<ObjectName, DMBean> retrievedBeansMap = new TreeMap<ObjectName, DMBean>( new ObjectNameComparator()); if (!loaded) { log.info("Found " + objectNames.size() + " MBeans - starting load..."); } Set<DObjectName> currentKeys = new HashSet<DObjectName>(this.beanMap.keySet()); for (ObjectName objectName : objectNames) { // TODO: We're loading the beans on every run here i think... only load it if its not in the beanMap DMBean bean = mapBean(objectName, deep); retrievedBeansMap.put(objectName, bean); } Set<EmsBean> newBeans = new HashSet<EmsBean>(); Set<EmsBean> removedBeans = new HashSet<EmsBean>(); for (Map.Entry<ObjectName, DMBean> entry : retrievedBeansMap.entrySet()) { if (!currentKeys.contains(entry.getKey())) { newBeans.add(entry.getValue()); } } for (DObjectName name : currentKeys) { if (!retrievedBeansMap.containsKey(name.getObjectName())) { removedBeans.add(beanMap.remove(name)); } } if (loaded && log.isDebugEnabled()) { log.debug("Added " + newBeans.size() + " and removed " + removedBeans.size() + " since previous load."); } loaded = true; fireRegistrationEvent(newBeans, removedBeans); }
From source file:org.apache.geode.management.internal.ManagementAgent.java
private void registerAccessControlMBean() { try {// w ww .j a v a 2 s . com AccessControlMBean acc = new AccessControlMBean(this.securityService); ObjectName accessControlMBeanON = new ObjectName(ResourceConstants.OBJECT_NAME_ACCESSCONTROL); MBeanServer platformMBeanServer = ManagementFactory.getPlatformMBeanServer(); Set<ObjectName> names = platformMBeanServer.queryNames(accessControlMBeanON, null); if (names.isEmpty()) { try { platformMBeanServer.registerMBean(acc, accessControlMBeanON); logger.info("Registered AccessControlMBean on " + accessControlMBeanON); } catch (InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) { throw new GemFireConfigException("Error while configuring access control for jmx resource", e); } } } catch (MalformedObjectNameException e) { throw new GemFireConfigException("Error while configuring access control for jmx resource", e); } }
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);/* ww w . j a va2 s .co 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); } } } } } } }