Example usage for javax.management ObjectName getKeyPropertyList

List of usage examples for javax.management ObjectName getKeyPropertyList

Introduction

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

Prototype


public Hashtable<String, String> getKeyPropertyList() 

Source Link

Document

Returns the key properties as a Hashtable.

Usage

From source file:com.heliosapm.tsdblite.metric.MetricCache.java

/**
 * Registers a new meta-source ObjectName
 * @param meta The meta ObjectName/*  w  w  w . j a v a 2s .  com*/
 * @param name The meta key
 * @param value The meta value
 */
public void submit(final ObjectName meta, final String name, final String value) {
    if (meta != null) {
        final long hashCode = hashCode(meta.getDomain(), meta.getKeyPropertyList());
        MetricMeta m = metas.putIfAbsent(hashCode, MetricMeta.PLACEHOLDER);
        if (m == null) {
            m = new MetricMeta(hashCode, name, value);
            JMXHelper.registerMBean(metricMBeanServer, meta, m);
            metas.replace(hashCode, m);
        } else {
            m.addPair(name, value);
        }
    }
}

From source file:org.apache.solr.cloud.api.collections.CollectionsAPIDistributedZkTest.java

private void checkNoTwoShardsUseTheSameIndexDir() throws Exception {
    Map<String, Set<String>> indexDirToShardNamesMap = new HashMap<>();

    List<MBeanServer> servers = new LinkedList<>();
    servers.add(ManagementFactory.getPlatformMBeanServer());
    servers.addAll(MBeanServerFactory.findMBeanServer(null));
    for (final MBeanServer server : servers) {
        Set<ObjectName> mbeans = new HashSet<>();
        mbeans.addAll(server.queryNames(null, null));
        for (final ObjectName mbean : mbeans) {

            try {
                Map<String, String> props = mbean.getKeyPropertyList();
                String category = props.get("category");
                String name = props.get("name");
                if ((category != null && category.toString().equals(Category.CORE.toString()))
                        && (name != null && name.equals("indexDir"))) {
                    String indexDir = server.getAttribute(mbean, "Value").toString();
                    String key = props.get("dom2") + "." + props.get("dom3") + "." + props.get("dom4");
                    if (!indexDirToShardNamesMap.containsKey(indexDir)) {
                        indexDirToShardNamesMap.put(indexDir.toString(), new HashSet<>());
                    }/*from   ww  w  . j  a  va 2s. c o m*/
                    indexDirToShardNamesMap.get(indexDir.toString()).add(key);
                }
            } catch (Exception e) {
                // ignore, just continue - probably a "Value" attribute
                // not found
            }
        }
    }

    assertTrue(
            "Something is broken in the assert for no shards using the same indexDir - probably something was changed in the attributes published in the MBean of "
                    + SolrCore.class.getSimpleName() + " : " + indexDirToShardNamesMap,
            indexDirToShardNamesMap.size() > 0);
    for (Entry<String, Set<String>> entry : indexDirToShardNamesMap.entrySet()) {
        if (entry.getValue().size() > 1) {
            fail("We have shards using the same indexDir. E.g. shards " + entry.getValue().toString()
                    + " all use indexDir " + entry.getKey());
        }
    }

}

From source file:architecture.ee.web.spring.controller.SecureMoSKitoController.java

private List<URL> getClassPathUrlsForTomcat(final String context, final String contextPropertyName) {
    List<MBeanServer> servers = MBeanServerFactory.findMBeanServer(null);
    for (MBeanServer s : servers) {
        Set<ObjectInstance> instances = s.queryMBeans(null, new QueryExp() {

            public boolean apply(ObjectName name) throws BadStringOperationException,
                    BadBinaryOpValueExpException, BadAttributeValueExpException, InvalidApplicationException {
                String type = name.getKeyProperty("type");
                log.debug(name.getDomain() + " : " + name.getKeyPropertyList());
                if (!type.equals("WebappClassLoader"))
                    return false;
                if (!name.getDomain().equals("Catalina"))
                    return false;
                if (!name.getKeyProperty(contextPropertyName).equals(context))
                    return false;
                return true;
            }/*from   w  w  w . ja v a2 s . c  o m*/

            public void setMBeanServer(MBeanServer s) {
            }
        });
        if (instances.size() > 0) {
            try {
                URL[] urls = (URL[]) s.getAttribute(instances.iterator().next().getObjectName(), "URLs");
                return Arrays.asList(urls);
            } catch (Exception e) {
            }

        }
    }
    return null;
}

From source file:io.fabric8.mq.autoscaler.MQAutoScaler.java

private void bounceBroker(BrokerVitalSigns broker) throws Exception {
    if (broker.getTotalConnections() > 0) {
        ObjectName root = broker.getRoot();
        Hashtable<String, String> props = root.getKeyPropertyList();
        props.put("connector", "clientConnectors");
        props.put("connectorName", "*");
        String objectName = root.getDomain() + ":" + getOrderedProperties(props);

        /**/*from   ww  w .  ja  v  a 2 s.c  o  m*/
         * not interested in StatisticsEnabled, just need a real attribute so we can get the root which we
         * can execute against
         */

        List<String> roots = new ArrayList<>();
        J4pResponse<J4pReadRequest> response = broker.getClient()
                .execute(new J4pReadRequest(objectName, "StatisticsEnabled"));
        JSONObject value = response.getValue();
        for (Object key : value.keySet()) {
            roots.add(key.toString());
        }

        for (String key : roots) {
            broker.getClient().execute(new J4pExecRequest(key, "stop"));
            LOG.info("Stopping all clients " + " on broker " + broker.getBrokerIdentifier() + ": connector = "
                    + key);
        }
        Thread.sleep(1000);
        for (String key : roots) {
            broker.getClient().execute(new J4pExecRequest(key, "start"));
        }
    }
}

From source file:io.fabric8.mq.autoscaler.MQAutoScaler.java

private void bounceConnections(BrokerVitalSigns broker, int number) throws Exception {
    if (number > 0) {
        ObjectName root = broker.getRoot();
        Hashtable<String, String> props = root.getKeyPropertyList();
        props.put("connector", "clientConnectors");
        props.put("connectorName", "*");
        String objectName = root.getDomain() + ":" + getOrderedProperties(props);

        /**//w  w w .j a  v a2  s.c om
         * not interested in StatisticsEnabled, just need a real attribute so we can get the root which we
         * can execute against
         */

        List<String> connectors = new ArrayList<>();
        J4pResponse<J4pReadRequest> response = broker.getClient()
                .execute(new J4pReadRequest(objectName, "StatisticsEnabled"));
        JSONObject value = response.getValue();
        for (Object key : value.keySet()) {
            connectors.add(key.toString());
        }

        List<String> targets = new ArrayList<>();
        for (String key : connectors) {
            ObjectName on = new ObjectName(key);
            Hashtable<String, String> p = on.getKeyPropertyList();
            p.put("connectionName", "*");
            p.put("connectionViewType", "clientId");
            String clientObjectName = root.getDomain() + ":" + getOrderedProperties(p);
            ObjectName on1 = new ObjectName(clientObjectName);
            J4pResponse<J4pReadRequest> response1 = broker.getClient().execute(new J4pReadRequest(on1, "Slow"));
            JSONObject value1 = response1.getValue();
            for (Object k : value1.keySet()) {
                targets.add(k.toString());
            }
        }

        int count = 0;
        for (String key : targets) {
            broker.getClient().execute(new J4pExecRequest(key, "stop"));
            LOG.info("Stopping Client " + key + " on broker " + broker.getBrokerIdentifier());
            if (++count >= number) {
                break;
            }
        }
    }

}

From source file:io.fabric8.mq.autoscaler.MQAutoScaler.java

private BrokerVitalSigns populateDestinations(DestinationVitalSigns.Type type,
        BrokerVitalSigns brokerVitalSigns) {

    try {// w  ww .  j  a v a2  s . com
        ObjectName root = brokerVitalSigns.getRoot();
        Hashtable<String, String> props = root.getKeyPropertyList();
        props.put("destinationType", type == DestinationVitalSigns.Type.QUEUE ? "Queue" : "Topic");
        props.put("destinationName", "*");
        String objectName = root.getDomain() + ":" + getOrderedProperties(props);

        J4pResponse<J4pReadRequest> response = brokerVitalSigns.getClient()
                .execute(new J4pReadRequest(objectName, "Name", "QueueSize", "ConsumerCount", "ProducerCount"));
        JSONObject value = response.getValue();
        for (Object key : value.keySet()) {
            //get the destinations
            JSONObject jsonObject = (JSONObject) value.get(key);
            String name = jsonObject.get("Name").toString();
            String producerCount = jsonObject.get("ProducerCount").toString().trim();
            String consumerCount = jsonObject.get("ConsumerCount").toString().trim();
            String queueSize = jsonObject.get("QueueSize").toString().trim();

            if (!name.contains("Advisory")
                    && !name.contains(ActiveMQDestination.TEMP_DESTINATION_NAME_PREFIX)) {
                ActiveMQDestination destination = type == DestinationVitalSigns.Type.QUEUE
                        ? new ActiveMQQueue(name)
                        : new ActiveMQTopic(name);
                DestinationVitalSigns destinationVitalSigns = new DestinationVitalSigns(destination);
                destinationVitalSigns.setNumberOfConsumers(Integer.parseInt(consumerCount));
                destinationVitalSigns.setNumberOfProducers(Integer.parseInt(producerCount));
                destinationVitalSigns.setQueueDepth(Integer.parseInt(queueSize));
                brokerVitalSigns.addDestinationVitalSigns(destinationVitalSigns);
            }
        }
    } catch (Exception ex) {
        // Destinations don't exist yet on the broker
        LOG.debug("populateDestinations failed", ex);
    }
    return brokerVitalSigns;
}

From source file:org.cloudfoundry.identity.uaa.varz.VarzEndpoint.java

private Map<String, ?> getMBeans(String domain, String pattern) throws Exception {
    Set<ObjectName> names = server.queryNames(ObjectName.getInstance(domain + ":" + pattern), null);

    Map<String, Object> result = new LinkedHashMap<String, Object>();

    for (ObjectName name : names) {

        Map<String, Object> map = new MBeanMap(server, name);

        Map<String, Object> objects = getMap((Map<String, Object>) result, domain);

        String type = name.getKeyProperty("type");
        if (type != null) {
            type = MBeanMap.prettify(type);
            objects = getMap(objects, type);
        }//from www.j a va  2s.  c  om

        String key = name.getKeyProperty("name");
        if (key != null) {
            key = MBeanMap.prettify(key);
            objects = getMap(objects, key);
        }

        for (String property : name.getKeyPropertyList().keySet()) {
            if (property.equals("type") || property.equals("name")) {
                continue;
            }
            key = MBeanMap.prettify(property);
            objects = getMap(objects, key);
            String value = name.getKeyProperty(property);
            objects = getMap(objects, value);
        }

        if (key == null) {
            key = type;
        }
        if (key == null) {
            key = domain;
        }
        objects.putAll(map);
    }

    return result;

}

From source file:com.riotgames.mondev.JMXDiscovery.java

protected String discoverMBeans(String key) throws Exception {
    try {//from w w  w  .j av a 2  s  . com
        HashMap<String, String[]> env = null;
        if (null != username && null != password) {
            env = new HashMap<String, String[]>();
            env.put(JMXConnector.CREDENTIALS, new String[] { username, password });
        }

        jmxc = JMXConnectorFactory.connect(jmxServerUrl, env);
        mbsc = jmxc.getMBeanServerConnection();

        ObjectName filter = new ObjectName(key);
        JSONArray beanList = new JSONArray();
        JSONObject mapping = new JSONObject();

        Set beans = mbsc.queryMBeans(filter, null);
        for (Object obj : beans) {
            JSONObject bean = new JSONObject();
            ObjectName beanName;

            // Return the ObjectName instance correctly for both Objects and Instances
            if (obj instanceof ObjectName)
                beanName = (ObjectName) obj;
            else if (obj instanceof ObjectInstance)
                beanName = ((ObjectInstance) obj).getObjectName();
            else
                throw new RuntimeException("Unexpected object type: " + obj);

            // Build the standing info, description and object path
            MBeanInfo mbi = mbsc.getMBeanInfo(beanName);
            bean.put("{#JMXDESC}", mbi.getDescription());
            bean.put("{#JMXOBJ}", beanName.getCanonicalName());

            // Build a list of all the MBean properties as {#PROP<NAME>}
            Hashtable<String, String> pt = beanName.getKeyPropertyList();
            for (Map.Entry<String, String> prop : pt.entrySet())
                bean.put(String.format("{#PROP%s}", prop.getKey().toUpperCase()), prop.getValue());

            beanList.put(bean);
        }

        mapping.put("data", beanList);
        return mapping.toString();
    } catch (Exception e) {
        JSONArray data = new JSONArray();
        JSONObject out = new JSONObject();
        out.put("data", data);

        return out.toString();
    } finally {
        try {
            if (null != jmxc)
                jmxc.close();
        } catch (java.io.IOException exception) {
        }

        jmxc = null;
        mbsc = null;
    }
}

From source file:org.cloudfoundry.identity.varz.VarzEndpoint.java

private Map<String, ?> getMBeans(String domain, String pattern) throws Exception {
    Set<ObjectName> names = server.queryNames(ObjectName.getInstance(domain + ":" + pattern), null);

    Map<String, Object> result = new LinkedHashMap<String, Object>();

    for (ObjectName name : names) {

        Map<String, Object> map = new MBeanMap(server, name);

        Map<String, Object> objects = getMap((Map<String, Object>) result, domain);

        String type = name.getKeyProperty("type");
        if (type != null) {
            type = VarzStringUtils.camelToUnderscore(type);
            objects = getMap(objects, type);
        }//ww  w  .  j  a va 2 s  .c o  m

        String key = name.getKeyProperty("name");
        if (key != null) {
            key = VarzStringUtils.camelToUnderscore(key);
            objects = getMap(objects, key);
        }

        for (String property : name.getKeyPropertyList().keySet()) {
            if (property.equals("type") || property.equals("name")) {
                continue;
            }
            key = VarzStringUtils.camelToUnderscore(property);
            objects = getMap(objects, key);
            String value = name.getKeyProperty(property);
            objects = getMap(objects, value);
        }

        if (key == null) {
            key = type;
        }
        if (key == null) {
            key = domain;
        }
        objects.putAll(map);
    }

    return result;

}