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:flens.query.JMXQuery.java
private void get(Query q, String[] rest) throws MalformedObjectNameException, NullPointerException, IOException, InstanceNotFoundException, IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException { String name = rest[0];//from ww w . j a va 2s.c om String att = rest[1]; 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(), connection.getAttribute(objectName, att)); } q.respond(out); }
From source file:org.jolokia.client.request.J4pReadResponse.java
private JSONObject getAttributesForObjectNameWithPatternRequest(ObjectName pObjectName) { ObjectName pMBeanFromRequest = getRequest().getObjectName(); ObjectName objectName = pObjectName == null ? pMBeanFromRequest : pObjectName; JSONObject values = getValue();/*from w w w .j a va2 s. c o m*/ JSONObject attributes = (JSONObject) values.get(objectName.getCanonicalName()); if (attributes == null) { throw new IllegalArgumentException("No ObjectName " + objectName + " found in the set of returned " + " ObjectNames for requested pattern " + pMBeanFromRequest); } return attributes; }
From source file:org.elasticsearch.river.jolokia.strategy.simple.SimpleRiverSource.java
private String getObjectName(ObjectName o) { return o.getDomain() + ":" + o.getCanonicalName(); }
From source file:VerboseGC.java
/** * Constructs a PrintGCStat object to monitor a remote JVM. *///from w w w.j ava 2s.com public PrintGCStat(MBeanServerConnection server) throws IOException { // Create the platform mxbean proxies this.rmbean = newPlatformMXBeanProxy(server, RUNTIME_MXBEAN_NAME, RuntimeMXBean.class); this.mmbean = newPlatformMXBeanProxy(server, MEMORY_MXBEAN_NAME, MemoryMXBean.class); ObjectName poolName = null; ObjectName gcName = null; try { poolName = new ObjectName(MEMORY_POOL_MXBEAN_DOMAIN_TYPE + ",*"); gcName = new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*"); } catch (MalformedObjectNameException e) { // should not reach here assert (false); } Set mbeans = server.queryNames(poolName, null); if (mbeans != null) { pools = new ArrayList<MemoryPoolMXBean>(); Iterator iterator = mbeans.iterator(); while (iterator.hasNext()) { ObjectName objName = (ObjectName) iterator.next(); MemoryPoolMXBean p = newPlatformMXBeanProxy(server, objName.getCanonicalName(), MemoryPoolMXBean.class); pools.add(p); } } mbeans = server.queryNames(gcName, null); if (mbeans != null) { gcmbeans = new ArrayList<GarbageCollectorMXBean>(); Iterator iterator = mbeans.iterator(); while (iterator.hasNext()) { ObjectName objName = (ObjectName) iterator.next(); GarbageCollectorMXBean gc = newPlatformMXBeanProxy(server, objName.getCanonicalName(), GarbageCollectorMXBean.class); gcmbeans.add(gc); } } }
From source file:com.quinsoft.zeidon.jconsole.JConsoleEnvironment.java
void searchForObjectEngineBeans() { try {/*ww w . ja v a2 s .com*/ proxies = new ArrayList<>(); Set<ObjectName> objects = server.queryNames(null, null); for (ObjectName object : objects) { ObjectInstance oi = server.getObjectInstance(object); if (oi.getClassName().equals("com.quinsoft.zeidon.jmx.JmxObjectEngineMonitor")) { String name = object.getCanonicalName(); JmxObjectEngineMonitorMBean proxy = JMX.newMBeanProxy(server, object, JmxObjectEngineMonitorMBean.class, true); proxies.add(new OeProxy(name, proxy)); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get all attributes obtained. This method can be only used, if the requested MBean * was not a pattern (i.e. the request was for a single MBean). * * @return a list of attributes for this request. If the request was performed for * only a single attribute, the attribute name of the request is returend as * a single valued list. For more than one attribute, the attribute names * a returned from the returned list. *///from ww w . j a v a 2 s . c om public Collection<String> getAttributes() { J4pReadRequest request = getRequest(); ObjectName requestBean = request.getObjectName(); if (requestBean.isPattern()) { throw new IllegalArgumentException("Attributes can be fetched only for non-pattern request (current: " + requestBean.getCanonicalName() + ")"); } // The attribute names are the same as from the request if (request.hasSingleAttribute()) { // Contains only a single attribute: return request.getAttributes(); } else { JSONObject attributes = getValue(); return attributes.keySet(); } }
From source file:org.openadaptor.core.jmx.MBeanServer.java
private void startHtmlServerAdaptor(HtmlAdaptorServer html) { try {//from w ww .j a v a 2s . c o m ObjectName name = new ObjectName(OBJECT_NAME_STRING); log.info("Registering MBean for htmlAdaptorServer with name " + name.getCanonicalName()); mServer.registerMBean(html, name); log.info("starting jmx http adaptor on port " + html.getPort()); html.start(); } catch (Exception e) { log.error("failed to start HtmlAdaptorServer", e); } }
From source file:org.rhq.plugins.jbossas.JBossASServerComponent.java
private static String getCanonicalName(String objectName) { ObjectName on; try {/*from w ww . j a v a 2s .co m*/ on = new ObjectName(objectName); } catch (MalformedObjectNameException e) { throw new IllegalStateException( "Malformed JMX object name: " + objectName + " - " + e.getLocalizedMessage()); } return on.getCanonicalName(); }
From source file:org.rhq.plugins.jbosscache.JBossCacheComponent.java
/** * Load the configuration from the actual resource *//*from ww w .ja va 2s .c om*/ public Configuration loadResourceConfiguration() throws Exception { File file = DeploymentUtility.getDescriptorFile(parentServer.getEmsConnection(), context.getResourceKey()); if (file == null) { log.warn("Can not find the deployment descriptor for this cache "); return null; } try { SAXBuilder builder = new SAXBuilder(); Document doc = builder.build(file); // Get the root element Element root = doc.getRootElement(); // First look for the right mbean of *our* cache - the file may contain more than one Configuration config = new Configuration(); for (Object mbeanObj : root.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); } if (nameAttrib.equals(context.getResourceKey())) { // found ours, let the fun begin ConfigurationDefinition configDef = context.getResourceType() .getResourceConfigurationDefinition(); fillAttributesInConfig(mbean, config, configDef); Attribute code = mbean.getAttribute("code"); PropertySimple flavour = new PropertySimple(); flavour.setName("Flavour"); if (code.getValue().contains("Tree")) { flavour.setStringValue("treecache"); } else { flavour.setStringValue("cache"); } config.put(flavour); } } } return config; } 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); } return null; }
From source file:org.jolokia.client.request.J4pReadResponse.java
/** * Get the value for a single attribute. This method is appropriate if the request was done for a single * MBean (no pattern), but multiple attributes. If it is called for a request with non-pattern MBean * and a single attribute, the given attribute must match the attribute of the request. If this method is * called with a <code>null</code> argument, then it will return the value if the request was for * a single attribute, otherwise it will raise an {@link IllegalArgumentException} * * @param pAttribute attribute for which to get the value * @param <V> value type//from www. j a va2 s . c o m * @return value * @throws IllegalArgumentException if the attribute could not be found in the return value or if this method * is called with a <code>null</code> argument, but the request leads to multiple attribute return values. */ public <V> V getValue(String pAttribute) { J4pReadRequest request = getRequest(); ObjectName requestBean = request.getObjectName(); if (requestBean.isPattern()) { throw new IllegalArgumentException( "Attributes without ObjectName can be fetched only for non-pattern request (current: " + requestBean.getCanonicalName() + ")"); } // The attribute names are the same as from the request if (request.hasSingleAttribute()) { // Contains only a single attribute: if (pAttribute != null && !pAttribute.equals(request.getAttribute())) { throw new IllegalArgumentException( "Given attribute " + pAttribute + " doesnt match single attribute " + "given " + request.getAttribute() + " in the request"); } return (V) getValue(); } else { JSONObject attributes = getValue(); if (pAttribute == null) { throw new IllegalArgumentException( "Cannot use null-attribute name to fetch a value from a multi-attribute request"); } if (!attributes.containsKey(pAttribute)) { throw new IllegalArgumentException( "No such key " + pAttribute + " in the set of returned attribute values"); } return (V) attributes.get(pAttribute); } }