Example usage for javax.management ObjectName getCanonicalKeyPropertyListString

List of usage examples for javax.management ObjectName getCanonicalKeyPropertyListString

Introduction

In this page you can find the example usage for javax.management ObjectName getCanonicalKeyPropertyListString.

Prototype

public String getCanonicalKeyPropertyListString() 

Source Link

Document

Returns a string representation of the list of key properties, in which the key properties are sorted in lexical order.

Usage

From source file:org.jolokia.client.request.J4pListRequest.java

/**
 * Constructor for fetching the meta data of a specific MBean
 *
 * @param pConfig proxy target configuration or <code>null</code> if no proxy should be used
 * @param pObjectName name of MBean for which to fetch the meta data
 *///from w  ww  . j a v  a2  s  .  c  o m
public J4pListRequest(J4pTargetConfig pConfig, ObjectName pObjectName) {
    super(J4pType.LIST, pConfig);
    pathElements = new ArrayList<String>();
    pathElements.add(pObjectName.getDomain());
    pathElements.add(pObjectName.getCanonicalKeyPropertyListString());
}

From source file:org.apache.hadoop.hdfs.tools.JMXGet.java

/**
 * print all attributes' values/*from   w  w w. j  a v a 2s .c  o m*/
 */
public void printAllValues() throws Exception {
    err("List of all the available keys:");

    Object val = null;

    for (ObjectName oname : hadoopObjectNames) {
        err(">>>>>>>>jmx name: " + oname.getCanonicalKeyPropertyListString());
        MBeanInfo mbinfo = mbsc.getMBeanInfo(oname);
        MBeanAttributeInfo[] mbinfos = mbinfo.getAttributes();

        for (MBeanAttributeInfo mb : mbinfos) {
            val = mbsc.getAttribute(oname, mb.getName());
            System.out.format(format, mb.getName(), (val == null) ? "" : val.toString());
        }
    }
}

From source file:org.jolokia.handler.list.MBeanInfoData.java

private String getKeyPropertyString(ObjectName pName) {
    return useCanonicalName ? pName.getCanonicalKeyPropertyListString() : pName.getKeyPropertyListString();
}

From source file:org.apache.camel.web.util.JMXRouteStatistics.java

@SuppressWarnings("unchecked")
public Object getRouteStatistic(CamelContext camelContext, String routeID, String attribute) {
    // only possible if JMX is enabled
    if (!(camelContext.getManagementStrategy() instanceof ManagedManagementStrategy)) {
        return null;
    }//w  w  w . j av  a2 s  .c  o m

    try {
        MBeanServer server = camelContext.getManagementStrategy().getManagementAgent().getMBeanServer();
        String domain = camelContext.getManagementStrategy().getManagementAgent().getMBeanObjectDomainName();

        ObjectName objName = new ObjectName(domain + ":type=routes,*");
        List<ObjectName> cacheList = new LinkedList(server.queryNames(objName, null));
        for (Iterator<ObjectName> iter = cacheList.iterator(); iter.hasNext();) {
            objName = iter.next();
            String keyProps = objName.getCanonicalKeyPropertyListString();
            ObjectName objectInfoName = new ObjectName(domain + ":" + keyProps);
            String currentRouteID = (String) server.getAttribute(objectInfoName, "RouteId");
            if (currentRouteID.equals(routeID)) {
                Object value = server.getAttribute(objectInfoName, attribute);
                if (value instanceof Date) {
                    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT);
                    return df.format(value);
                } else {
                    return value;
                }
            }
        }
    } catch (Exception e) {
        LOG.warn("Error getting route statistic from JMX. This exception will be ignored.", e);
    }

    return null;
}

From source file:org.mule.module.management.agent.AbstractJmxAgent.java

/**
 * @param containerMode when true, MuleContext will still be exposed to enable the 'start' operation
 *//*from ww w . j  a v  a 2s .c o m*/
protected void unregisterMBeansIfNecessary(boolean containerMode) {
    if (mBeanServer == null) {
        return;
    }

    try {
        // note that we don't try to resolve a domain name clash here.
        // e.g. when stopping an app via jmx, we want to obtain current domain only,
        // but the execution thread is different, and doesn't have the resolved domain info
        final String domain = jmxSupport.getDomainName(muleContext, false);
        ObjectName query = jmxSupport.getObjectName(domain + ":*");
        Set<ObjectName> mbeans = mBeanServer.queryNames(query, null);
        while (!mbeans.isEmpty()) {
            ObjectName name = mbeans.iterator().next();
            try {
                if (!(containerMode && MuleServiceMBean.DEFAULT_JMX_NAME
                        .equals(name.getCanonicalKeyPropertyListString()))) {
                    mBeanServer.unregisterMBean(name);
                }
            } catch (Exception e) {
                logger.warn(
                        String.format("Failed to unregister MBean: %s. Error is: %s", name, e.getMessage()));
            }

            // query mbeans again, as some mbeans have cascaded unregister operations,
            // this prevents duplicate unregister attempts
            mbeans = mBeanServer.queryNames(query, null);

            if (containerMode) {
                // filter out MuleContext MBean to avoid an endless loop
                mbeans.remove(jmxSupport
                        .getObjectName(String.format("%s:%s", domain, MuleServiceMBean.DEFAULT_JMX_NAME)));
            }
        }
    } catch (MalformedObjectNameException e) {
        logger.warn("Failed to create ObjectName query", e);
    }
}

From source file:com.tesora.dve.tools.DVEConfigCLI.java

public void cmd_jmx_list_mbeans() throws PEException {
    checkJMXConnected();//  ww  w.ja va 2  s .  c  o m
    checkJMXDomain();

    final Set<ObjectName> beans = jmxConnector.getBeanNames(jmxDomain);

    printlnDots("Available MBean(s) in domain '" + jmxDomain + "' are:");

    for (final ObjectName bean : beans) {
        println(bean.getCanonicalKeyPropertyListString());
    }
}