List of usage examples for javax.management ObjectName ObjectName
public ObjectName(String name) throws MalformedObjectNameException
From source file:net.sf.ehcache.management.ManagementServiceTest.java
private void traverseMBeanAttributes(MBeanServerConnection connection, String type) throws JMException, IOException { Set objectNames = connection.queryNames(new ObjectName("net.sf.ehcache:type=" + type + ",*"), null); for (Iterator iterator = objectNames.iterator(); iterator.hasNext();) { ObjectName objectName = (ObjectName) iterator.next(); MBeanInfo mBeanInfo = connection.getMBeanInfo(objectName); MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes(); for (int i = 0; i < attributes.length; i++) { MBeanAttributeInfo attribute = attributes[i]; LOG.info(attribute.getName() + " " + connection.getAttribute(objectName, attribute.getName())); }// ww w.jav a2 s . c o m } }
From source file:com.spotify.reaper.cassandra.JmxProxy.java
/** * @return true if any repairs are running on the node. *//*from w w w. j a va 2 s .c o m*/ public boolean isRepairRunningPre22() { // Check if AntiEntropySession is actually running on the node try { ObjectName name = new ObjectName(AES_OBJECT_NAME); int activeCount = (Integer) mbeanServer.getAttribute(name, "ActiveCount"); long pendingCount = (Long) mbeanServer.getAttribute(name, "PendingTasks"); return activeCount + pendingCount != 0; } catch (IOException ignored) { LOG.warn(FAILED_TO_CONNECT_TO_USING_JMX, host, ignored); } catch (MalformedObjectNameException ignored) { LOG.error("Internal error, malformed name", ignored); } catch (InstanceNotFoundException e) { // This happens if no repair has yet been run on the node // The AntiEntropySessions object is created on the first repair LOG.debug("No repair has run yet on the node. Ignoring exception.", e); return false; } catch (Exception e) { LOG.error(ERROR_GETTING_ATTR_JMX, e); } // If uncertain, assume it's running return true; }
From source file:net.sf.ehcache.management.ManagementServiceTest.java
private void traverseMBeanAttributesUsingMBeanServer(String type) throws JMException { Set objectNames = mBeanServer.queryNames(new ObjectName("net.sf.ehcache:type=" + type + ",*"), null); for (Iterator iterator = objectNames.iterator(); iterator.hasNext();) { ObjectName objectName = (ObjectName) iterator.next(); MBeanInfo mBeanInfo = mBeanServer.getMBeanInfo(objectName); MBeanAttributeInfo[] attributes = mBeanInfo.getAttributes(); for (int i = 0; i < attributes.length; i++) { MBeanAttributeInfo attribute = attributes[i]; LOG.info(attribute.getName() + " " + mBeanServer.getAttribute(objectName, attribute.getName())); }//from w w w . jav a 2s .co m } }
From source file:dk.netarkivet.common.utils.JMXUtils.java
/** Get a bean name from a string version. * * @param beanName String representation of bean name * @return Object representing that bean name. *//*from w w w .j av a2 s . c om*/ public static ObjectName getBeanName(String beanName) { ArgumentNotValid.checkNotNullOrEmpty(beanName, "String beanName"); try { return new ObjectName(beanName); } catch (MalformedObjectNameException e) { throw new ArgumentNotValid("Name " + beanName + " is not a valid " + "object name", e); } }
From source file:catalina.mbeans.MBeanFactory.java
/** * Create a new FileLogger./* w ww . j a v a 2 s. c om*/ * * @param parent MBean Name of the associated parent component * * @exception Exception if an MBean cannot be created or registered */ public String createFileLogger(String parent) throws Exception { // Create a new FileLogger instance FileLogger fileLogger = new FileLogger(); // Add the new instance to its parent component ObjectName pname = new ObjectName(parent); String type = pname.getKeyProperty("type"); Server server = ServerFactory.getServer(); Service service = server.findService(pname.getKeyProperty("service")); Engine engine = (Engine) service.getContainer(); if (type.equals("Context")) { Host host = (Host) engine.findChild(pname.getKeyProperty("host")); String pathStr = getPathStr(pname.getKeyProperty("path")); Context context = (Context) host.findChild(pathStr); context.setLogger(fileLogger); } else if (type.equals("Engine")) { engine.setLogger(fileLogger); } else if (type.equals("Host")) { Host host = (Host) engine.findChild(pname.getKeyProperty("host")); host.setLogger(fileLogger); } // Return the corresponding MBean name ManagedBean managed = registry.findManagedBean("FileLogger"); ObjectName oname = MBeanUtils.createObjectName(managed.getDomain(), fileLogger); return (oname.toString()); }
From source file:org.jolokia.client.request.J4pReadIntegrationTest.java
private void checkNames(String pMethod, List<String>... pNames) throws MalformedObjectNameException, J4pException { for (int i = 0; i < pNames.length; i++) { for (String name : pNames[i]) { System.out.println(name); ObjectName oName = new ObjectName(name); J4pReadRequest req = new J4pReadRequest(oName, "Ok"); req.setPreferredHttpMethod(pMethod); J4pReadResponse resp = j4pClient.execute(req); Collection names = resp.getObjectNames(); assertEquals(1, names.size()); assertEquals(oName, names.iterator().next()); assertEquals("OK", resp.getValue()); Collection<String> attrs = resp.getAttributes(); assertEquals(1, attrs.size()); assertNotNull(resp.getValue("Ok")); try { resp.getValue("Koepke"); fail();/*ww w .ja v a 2 s . c om*/ } catch (IllegalArgumentException exp) { assertTrue(exp.getMessage().contains("Koepke")); } } } }
From source file:com.googlecode.psiprobe.Utils.java
public static boolean isThreadingEnabled() { try {/*from w w w . j a v a2 s. c o m*/ MBeanServer mBeanServer = new Registry().getMBeanServer(); ObjectName threadingOName = new ObjectName("java.lang:type=Threading"); Set s = mBeanServer.queryMBeans(threadingOName, null); return s != null && s.size() > 0; } catch (MalformedObjectNameException e) { return false; } }
From source file:com.norconex.collector.core.crawler.AbstractCrawler.java
private void registerMonitoringMbean(ICrawlDataStore crawlDataStore) { try {/*from w w w. jav a 2 s . c om*/ MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName name = new ObjectName( "com.norconex.collector.http.crawler:type=" + getCrawlerConfig().getId()); Monitoring mbean = new Monitoring(crawlDataStore); mbs.registerMBean(mbean, name); } catch (MalformedObjectNameException | InstanceAlreadyExistsException | MBeanRegistrationException | NotCompliantMBeanException e) { throw new CollectorException(e); } }