List of usage examples for javax.management ObjectName getCanonicalName
public String getCanonicalName()
Returns the canonical form of the name; that is, a string representation where the properties are sorted in lexical order.
More precisely, the canonical form of the name is a String consisting of the domain part, a colon (:
), the canonical key property list, and a pattern indication.
The canonical key property list is the same string as described for #getCanonicalKeyPropertyListString() .
The pattern indication is:
,*
) for an ObjectName that is a property list pattern with at least one key. From source file:org.rhq.plugins.jbossas.AbstractMessagingComponent.java
/** * Returns the canonical version of the passed ObjectName * @param objectName a valid {@link ObjectName} * @return an {@link ObjectName} in its canonical form * @throws MalformedObjectNameException if the passed {@link ObjectName} is invalid *//*from w ww . j a v a 2s . c o m*/ public String getCanonicalName(String objectName) throws MalformedObjectNameException { ObjectName on = new ObjectName(objectName); return on.getCanonicalName(); }
From source file:org.rhq.plugins.jbosscache.JBossCacheSubsystemComponent.java
public CreateResourceReport createResource(CreateResourceReport report) { JBossASServerComponent parentResourceComponent = (JBossASServerComponent) ctx.getParentResourceComponent(); Configuration config = report.getResourceConfiguration(); String name = report.getUserSpecifiedResourceName(); // String name = config.getSimple("MBeanName").getStringValue(); // PropertySimple nameTemplateProp = report.getPluginConfiguration().getSimple("nameTemplate"); // String rName = nameTemplateProp.getStringValue(); //noinspection ConstantConditions // rName = rName.replace("{name}", name); // TODO check for duplcicate name/mbean // PropertySimple pluginNameProperty = new PropertySimple("name", rName); // ctx.getPluginConfiguration().put(pluginNameProperty); File deployDir = new File(parentResourceComponent.getConfigurationPath() + "/deploy"); File deploymentFile = new File(deployDir, FileNameUtility.formatFileName(name) + "-cache-service.xml"); String flavour = config.getSimple("Flavour").getStringValue(); boolean isTc = false; if (flavour != null && flavour.startsWith("tree")) isTc = true;/* w w w. j a v a 2s .com*/ String mbeanName = "jboss.cache:name=" + name; try { CacheConfigurationHelper helper = new CacheConfigurationHelper(); helper.writeConfig(deploymentFile, config, mbeanName, false); } catch (Exception ioe) { ioe.printStackTrace(); // TODO remove later report.setErrorMessage(ioe.getLocalizedMessage()); report.setException(ioe); report.setStatus(CreateResourceStatus.FAILURE); return report; } String objectName = mbeanName; if (isTc) objectName += ",treecache-interceptor=CacheMgmtInterceptor"; else objectName += ",cache-interceptor=CacheMgmtInterceptor"; try { ObjectName on = new ObjectName(objectName); objectName = on.getCanonicalName(); report.setResourceKey(objectName); } catch (MalformedObjectNameException e) { log.warn("Invalid key [" + objectName + "]: " + e.getMessage()); return report; } report.setResourceName(name); // TODO ok? or better objectName? // try { // parentResourceComponent.deployFile(deploymentFile); // } // catch (Exception e) { // JBossASServerComponent.setErrorOnCreateResourceReport(report, e.getLocalizedMessage(), e); // return report; // } report.setStatus(CreateResourceStatus.SUCCESS); return report; }
From source file:org.jolokia.request.JmxObjectNameRequest.java
/** * Name prepared according to requested formatting note. The key ordering can be influenced by the * processing parameter {@link ConfigKey#CANONICAL_NAMING}. If not given or set to "true", * then the canonical order is used, if set to "initial" the name is given to construction time * is used.//www. j a v a2 s .c om * * @param pName name to format * @return formatted string */ public String getOrderedObjectName(ObjectName pName) { // For patterns we always return the canonical name if (pName.isPattern()) { return pName.getCanonicalName(); } if (getParameterAsBool(ConfigKey.CANONICAL_NAMING)) { return pName.getCanonicalName(); } else { return pName.getDomain() + ":" + pName.getKeyPropertyListString(); } }
From source file:org.rhq.plugins.jbosscache.JGroupsChannelDiscovery.java
public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext context) throws InvalidPluginConfigurationException, Exception { JBossCacheComponent parent = (JBossCacheComponent) context.getParentResourceComponent(); EmsConnection emsConnection = parent.getEmsConnection(); String resKey = context.getParentResourceContext().getResourceKey(); File file = DeploymentUtility.getDescriptorFile(emsConnection, resKey); if (file == null) { log.warn("File is null for " + resKey); return null; }//from www.jav a2 s . com boolean found = false; try { SAXBuilder builder = new SAXBuilder(); SelectiveSkippingEntityResolver entityResolver = SelectiveSkippingEntityResolver .getDtdAndXsdSkippingInstance(); builder.setEntityResolver(entityResolver); Document doc = builder.build(file); // Get the root element Element root = doc.getRootElement(); // XPath xpath = XPathFactory.newInstance().newXPath(); // TODO this expression would need to work against non-normalized versions of the name attribute // XPathExpression xp = xpath // .compile("/server/mbean[@name='" + resKey + "']/attribute[@name='ClusterConfig']"); // InputSource inputSource = new InputSource(new FileInputStream(file)); // NodeList cconfig = (NodeList) xp.evaluate(inputSource, XPathConstants.NODESET); // if (cconfig != null && cconfig.getLength() > 0) // found = true; // First look for the right mbean of *our* cache - the file may contain more than one // TODO move code in helper, as we'll need it later again // TODO replace the access of 'our' ClusterConfig attribute with an XPath expression for (Object mbeanObj : root.getChildren("mbean")) { if (mbeanObj instanceof Element) { Element mbean = (Element) mbeanObj; String nameAttrib = mbean.getAttributeValue("name"); try { ObjectName on = new ObjectName(nameAttrib); nameAttrib = on.getCanonicalName(); } catch (MalformedObjectNameException e) { log.warn("Can't canonicalize " + nameAttrib); } if (nameAttrib.equals(resKey)) { // our cache instance, look for the right attribute List children = mbean.getChildren("attribute"); for (Object childObj : children) { if (childObj instanceof Element) { Element child = (Element) childObj; String name = child.getAttributeValue("name"); if (name.equals("ClusterConfig")) found = true; } } } } } } catch (IOException e) { log.error("IO error occurred while reading file: " + file, e); } catch (JDOMException e) { log.error("Parsing error occurred while reading file: " + file, e); } if (found) { DiscoveredResourceDetails detail = new DiscoveredResourceDetails(context.getResourceType(), // Resource Type resKey + "jgroupsChannel", // ResourceKey TODO good choice ? "JGroups channel", // resource name null, // Version "JGroups config for parent JBossCache", // description context.getDefaultPluginConfiguration(), // config null); // process info Set<DiscoveredResourceDetails> res = new HashSet<DiscoveredResourceDetails>(1); res.add(detail); return res; } return null; }
From source file:org.rhq.plugins.jbosscache.CacheConfigurationHelper.java
private Element findComponentElement(Element base, String mbeanName) { for (Object mbeanObj : base.getChildren("mbean")) { if (mbeanObj instanceof Element) { Element mbean = (Element) mbeanObj; // normalize the content of 'name' String nameAttrib = mbean.getAttributeValue("name"); try { ObjectName on = new ObjectName(nameAttrib); nameAttrib = on.getCanonicalName(); } catch (MalformedObjectNameException e) { log.warn("Can't canonicalize " + nameAttrib); }//from w ww .j a va 2s . c o m if (nameAttrib.equals(mbeanName)) return mbean; } } return null; }
From source file:org.camelcookbook.monitoring.managed.ManagedSpringTest.java
@Test public void testManagedResource() throws Exception { final ManagementAgent managementAgent = context.getManagementStrategy().getManagementAgent(); assertNotNull(managementAgent);//from w ww . ja v a2s . c om final MBeanServer mBeanServer = managementAgent.getMBeanServer(); assertNotNull(mBeanServer); final String mBeanServerDefaultDomain = managementAgent.getMBeanServerDefaultDomain(); assertEquals("org.apache.camel", mBeanServerDefaultDomain); final String managementName = context.getManagementName(); assertNotNull("CamelContext should have a management name if JMX is enabled", managementName); LOG.info("managementName = {}", managementName); // Get the Camel Context MBean ObjectName onContext = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/" + managementName + ",type=context,name=\"" + context.getName() + "\""); assertTrue("Should be registered", mBeanServer.isRegistered(onContext)); // Get myManagedBean ObjectName onManagedBean = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/" + managementName + ",type=processors,name=\"myManagedBean\""); LOG.info("Canonical Name = {}", onManagedBean.getCanonicalName()); assertTrue("Should be registered", mBeanServer.isRegistered(onManagedBean)); // Send a couple of messages to get some route statistics template.sendBody("direct:start", "Hello Camel"); template.sendBody("direct:start", "Camel Rocks!"); // Get MBean attribute int camelsSeenCount = (Integer) mBeanServer.getAttribute(onManagedBean, "CamelsSeenCount"); assertEquals(2, camelsSeenCount); // Stop the route via JMX mBeanServer.invoke(onManagedBean, "resetCamelsSeenCount", null, null); camelsSeenCount = (Integer) mBeanServer.getAttribute(onManagedBean, "CamelsSeenCount"); assertEquals(0, camelsSeenCount); }
From source file:flens.query.JMXQuery.java
private void listLong(Query q) throws IOException { Set<ObjectName> names = new TreeSet<ObjectName>(connection.queryNames(null, null)); List<String> out = new LinkedList<>(); for (ObjectName objectName : names) { out.add(objectName.getCanonicalName()); }/*w ww.j a v a2s. c o m*/ q.respond(out); }
From source file:org.camelcookbook.monitoring.naming.JmxNamingContextSpringTest.java
@Test public void testNamingContextSpring() throws Exception { final ManagementAgent managementAgent = context.getManagementStrategy().getManagementAgent(); assertNotNull(managementAgent);//from w ww . j a v a2 s . c om final MBeanServer mBeanServer = managementAgent.getMBeanServer(); assertNotNull(mBeanServer); final String mBeanServerDefaultDomain = managementAgent.getMBeanServerDefaultDomain(); assertEquals("org.apache.camel", mBeanServerDefaultDomain); final String managementName = context.getManagementName(); assertNotNull("CamelContext should have a management name if JMX is enabled", managementName); LOG.info("managementName = {}", managementName); // Get the Camel Context MBean ObjectName onContext = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/" + managementName + ",type=context,name=\"" + context.getName() + "\""); assertTrue("Should be registered", mBeanServer.isRegistered(onContext)); // Get the first Route MBean by id ObjectName onRoute1 = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/" + managementName + ",type=routes,name=\"first-route\""); LOG.info("Canonical Name = {}", onRoute1.getCanonicalName()); assertTrue("Should be registered", mBeanServer.isRegistered(onRoute1)); // Send a couple of messages to get some route statistics template.sendBody("direct:start", "Hello Camel"); template.sendBody("direct:start", "Camel Rocks!"); // Get an MBean attribute for the number of messages processed assertEquals(2L, mBeanServer.getAttribute(onRoute1, "ExchangesCompleted")); // Get the other Route MBean by id ObjectName onRoute2 = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/" + managementName + ",type=routes,name=\"other-route\""); assertTrue("Should be registered", mBeanServer.isRegistered(onRoute2)); // Get an MBean attribute for the number of messages processed assertEquals(0L, mBeanServer.getAttribute(onRoute2, "ExchangesCompleted")); // Send some messages to the other route template.sendBody("direct:startOther", "Hello Other Camel"); template.sendBody("direct:startOther", "Other Camel Rocks!"); // Verify that the MBean statistics updated correctly assertEquals(2L, mBeanServer.getAttribute(onRoute2, "ExchangesCompleted")); // Check this routes running state assertEquals("Started", mBeanServer.getAttribute(onRoute2, "State")); // Stop the route via JMX mBeanServer.invoke(onRoute2, "stop", null, null); // verify the route now shows its state as stopped assertEquals("Stopped", mBeanServer.getAttribute(onRoute2, "State")); }
From source file:org.camelcookbook.monitoring.naming.JmxNamingPatternSpringTest.java
@Test public void testNamingPatternSpring() throws Exception { final ManagementAgent managementAgent = context.getManagementStrategy().getManagementAgent(); assertNotNull(managementAgent);//w ww . j av a 2s . c o m final MBeanServer mBeanServer = managementAgent.getMBeanServer(); assertNotNull(mBeanServer); final String mBeanServerDefaultDomain = managementAgent.getMBeanServerDefaultDomain(); assertEquals("org.apache.camel", mBeanServerDefaultDomain); final String managementName = context.getManagementName(); assertNotNull("CamelContext should have a management name if JMX is enabled", managementName); LOG.info("managementName = {}; name = {}", managementName, context.getName()); assertTrue(managementName.startsWith("CustomName")); // Get the Camel Context MBean ObjectName onContext = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/" + managementName + ",type=context,name=\"" + context.getName() + "\""); assertTrue("Should be registered", mBeanServer.isRegistered(onContext)); // Get the first Route MBean by id ObjectName onRoute1 = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/" + managementName + ",type=routes,name=\"first-route\""); LOG.info("Canonical Name = {}", onRoute1.getCanonicalName()); assertTrue("Should be registered", mBeanServer.isRegistered(onRoute1)); // Send a couple of messages to get some route statistics template.sendBody("direct:start", "Hello Camel"); template.sendBody("direct:start", "Camel Rocks!"); // Get an MBean attribute for the number of messages processed assertEquals(2L, mBeanServer.getAttribute(onRoute1, "ExchangesCompleted")); // Get the other Route MBean by id ObjectName onRoute2 = ObjectName.getInstance(mBeanServerDefaultDomain + ":context=localhost/" + managementName + ",type=routes,name=\"other-route\""); assertTrue("Should be registered", mBeanServer.isRegistered(onRoute2)); // Get an MBean attribute for the number of messages processed assertEquals(0L, mBeanServer.getAttribute(onRoute2, "ExchangesCompleted")); // Send some messages to the other route template.sendBody("direct:startOther", "Hello Other Camel"); template.sendBody("direct:startOther", "Other Camel Rocks!"); // Verify that the MBean statistics updated correctly assertEquals(2L, mBeanServer.getAttribute(onRoute2, "ExchangesCompleted")); // Check this routes running state assertEquals("Started", mBeanServer.getAttribute(onRoute2, "State")); // Stop the route via JMX mBeanServer.invoke(onRoute2, "stop", null, null); // verify the route now shows its state as stopped assertEquals("Stopped", mBeanServer.getAttribute(onRoute2, "State")); }
From source file:flens.query.JMXQuery.java
private void details(Query q, String[] rest) throws MalformedObjectNameException, NullPointerException, IOException, InstanceNotFoundException, IntrospectionException, ReflectionException { String name = rest[0];/*from www . j a va 2s . c o m*/ Set<ObjectName> names = new TreeSet<ObjectName>(connection.queryNames(ObjectName.getInstance(name), null)); Map<String, Object> out = new HashMap<>(); for (ObjectName objectName : names) { out.put(objectName.getCanonicalName(), getDetails(objectName)); } q.respond(out); }