Example usage for javax.management ObjectName getKeyProperty

List of usage examples for javax.management ObjectName getKeyProperty

Introduction

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

Prototype

public String getKeyProperty(String property) 

Source Link

Document

Obtains the value associated with a key in a key property.

Usage

From source file:org.apache.geronimo.tomcat.stats.ModuleStats.java

public ModuleStats(StandardContext context) {
    assert context != null;
    // Retrieve the MBean server
    mBeanServer = Registry.getRegistry(null, null).getMBeanServer();

    try {/*from  w  ww  .  ja  v  a 2  s.co  m*/
        // org.apache.commons.modeler.BaseModelMBean@Geronimo:type=Manager,path=/,host=localhost
        mgrName = new ObjectName("*:type=Manager,*");
    } catch (Exception ex) {
        log.error("Error - " + ex.toString());
    }
    // Query Session Managers
    for (ObjectInstance oi : mBeanServer.queryMBeans(mgrName, null)) {
        ObjectName objectName = oi.getObjectName();
        if (objectName.getKeyProperty("context").indexOf(context.getPath()) > -1) {
            mgrName = objectName;
            break;

        }
    }

    //      initialize static values
    stats.setProcessingTime(context.getProcessingTime());
    stats.setStartupTime(context.getStartupTime());
    stats.setTldScanTime(context.getTldScanTime());
}

From source file:io.fabric8.mq.controller.coordination.BrokerJMXPropertiesTest.java

@Test
public void testNumberOfTopicProducers() throws Exception {
    String uriString = brokerService.getDefaultSocketURIString();
    ConnectionFactory factory = new ActiveMQConnectionFactory(uriString);
    Connection connection = factory.createConnection();
    connection.start();/*from   w  w w .j ava 2s  .co m*/
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    int numberOfProducers = 10;
    List<MessageProducer> producers = new ArrayList<>();
    Topic topic = session.createTopic("topic.test");
    for (int i = 0; i < numberOfProducers; i++) {

        MessageProducer producer = session.createProducer(topic);
        producers.add(producer);

    }
    ObjectName root = BrokerJmxUtils.getRoot(client);
    Assert.assertNotNull(root);
    List<ObjectName> list = BrokerJmxUtils.getDestinations(client, root, "Topic");
    Assert.assertNotNull(list);
    Assert.assertFalse(list.isEmpty());
    ObjectName result = null;
    for (ObjectName objectName : list) {
        if (objectName.getKeyProperty("destinationName").equals("topic.test")) {
            result = objectName;
        }
    }
    Assert.assertNotNull(result);
    Object producerCount = BrokerJmxUtils.getAttribute(client, result, "ProducerCount");
    Assert.assertNotNull(producerCount);
    int pc = Integer.parseInt(producerCount.toString());
    Assert.assertEquals(pc, numberOfProducers);
    connection.close();
}

From source file:be.fgov.kszbcss.rhq.websphere.process.ProcessIdentityValidator.java

private synchronized void init() throws ConnectorException {
    if (adminClient == null) {
        adminClient = parent.createAdminClient();
    }//from  w w  w .ja  va2  s.c  o m
    if (!initialized) {
        ObjectName serverMBean = adminClient.getServerMBean();
        String actualCell = serverMBean.getKeyProperty("cell");
        String actualNode = serverMBean.getKeyProperty("node");
        String actualServer = serverMBean.getKeyProperty("process");
        String actualProcessType = serverMBean.getKeyProperty("processType");
        compare("cell name", cell, actualCell);
        compare("node name", node, actualNode);
        compare("server name", server, actualServer);
        compare("process type", processType, actualProcessType);
        cell = actualCell;
        node = actualNode;
        server = actualServer;
        processType = actualProcessType;
        initialized = true;
    }
}

From source file:org.hyperic.hq.plugin.websphere.jmx.AppServerQuery.java

@Override
public boolean getAttributes(AdminClient mServer, ObjectName name) {
    String version = name.getKeyProperty(ATTR_VERSION);
    if (version != null) {
        this.attrs.put(ATTR_VERSION, version);
    }//from ww w. ja  v a2 s  .  co  m

    try {
        String[] vms = (String[]) mServer.getAttribute(name, "javaVMs");
        if (vms != null) {
            getAttributes(mServer, new ObjectName(vms[0]), VM_ATTRS);
        }

        //in the try block to catch SecurityException
        return super.getAttributes(mServer, name);
    } catch (Exception e) {
        log.error("Error getting JVM attributes for '" + name + "': " + e.getMessage(), e);
        return false;
    }
}

From source file:com.cognifide.aet.runner.util.MessagesManager.java

/**
 * Removes all messages with given correlationID. AETException is thrown when failed to remove messages.
 *
 * @param correlationID - correlationId of messages that will be removed.
 */// w w w  . j ava 2s. c om
public void remove(String correlationID) throws AETException {
    Object[] removeSelector = { JMS_CORRELATION_ID + "='" + correlationID + "'" };
    String[] signature = { STRING_SIGNATURE };

    try (JMXConnector jmxc = getJmxConnection(jmxUrl)) {
        MBeanServerConnection connection = jmxc.getMBeanServerConnection();
        for (ObjectName queue : getAetQueuesObjects(connection)) {
            String queueName = queue.getKeyProperty(DESTINATION_NAME_PROPERTY);
            int deletedMessagesNumber = (Integer) connection.invoke(queue, REMOVE_OPERATION_NAME,
                    removeSelector, signature);
            LOGGER.debug("Deleted: {} jmsMessages from: {} queue", deletedMessagesNumber, queueName);
        }
    } catch (Exception e) {
        throw new AETException(
                String.format("Error while removing messages with correlationID: %s", correlationID), e);
    }
}

From source file:net.centro.rtb.monitoringcenter.metrics.tomcat.TomcatExecutorMetricSet.java

TomcatExecutorMetricSet(ObjectName executorObjectName) {
    Preconditions.checkNotNull(executorObjectName);

    this.name = executorObjectName.getKeyProperty("name");

    Map<String, Metric> metricsByNames = new HashMap<>();

    this.currentPoolSizeGauge = JmxUtil.getJmxAttributeAsGauge(executorObjectName, "poolSize", Integer.class,
            0);/*from  ww w  .  jav a2  s. c  o  m*/
    if (currentPoolSizeGauge != null) {
        metricsByNames.put("currentPoolSize", currentPoolSizeGauge);
    }

    this.maxPoolSizeGauge = JmxUtil.getJmxAttributeAsGauge(executorObjectName, "maxThreads", Integer.class, 0);
    if (maxPoolSizeGauge != null) {
        metricsByNames.put("maxPoolSize", maxPoolSizeGauge);
    }

    this.busyThreadsGauge = JmxUtil.getJmxAttributeAsGauge(executorObjectName, "activeCount", Integer.class, 0);
    if (busyThreadsGauge != null) {
        metricsByNames.put("busyThreads", busyThreadsGauge);
    }

    this.queueSizeGauge = JmxUtil.getJmxAttributeAsGauge(executorObjectName, "queueSize", Integer.class, 0);
    if (queueSizeGauge != null) {
        metricsByNames.put("queueSize", queueSizeGauge);
    }

    this.queueCapacityGauge = JmxUtil.getJmxAttributeAsGauge(executorObjectName, "maxQueueSize", Integer.class,
            0);
    if (queueCapacityGauge != null) {
        metricsByNames.put("queueCapacity", queueCapacityGauge);
    }

    this.metricsByNames = metricsByNames;
}

From source file:org.nuxeo.ecm.core.management.jtajca.JtajcaManagementFeature.java

protected <T> void bind(Binder binder, MBeanServer mbs, Class<T> type) {
    final Set<ObjectName> names = mbs.queryNames(nameOf(type), null);
    for (ObjectName name : names) {
        T instance = type.cast(JMX.newMXBeanProxy(mbs, name, type));
        binder.bind(type).annotatedWith(Names.named(name.getKeyProperty("name"))).toInstance(instance);
    }// w w w .j av  a 2 s  .  c o m
}

From source file:com.atolcd.alfresco.audit.web.scripts.ContentStoreInfoGet.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {

    try {/* ww  w . j  a  v a  2  s.c  o  m*/
        // Map that will be passed to the template
        Map<String, Object> model = new HashMap<String, Object>();

        ObjectName query = new ObjectName("Alfresco:Name=ContentStore,Type=*,Root=*");
        MBeanServer mbs = getMBeanServerWithQuery(query);
        Set<ObjectName> storesName = mbs.queryNames(query, null);

        List<ContentStore> contentStores = new ArrayList<ContentStore>();

        for (ObjectName storeName : storesName) {
            Object writeSupported = mbs.getAttribute(storeName, "WriteSupported");
            Object totalSize = mbs.getAttribute(storeName, "SpaceUsed");

            contentStores.add(new ContentStore(storeName.getKeyProperty("Root"), String.valueOf(writeSupported),
                    String.valueOf(totalSize)));
        }

        model.put("contentStores", contentStores);

        return model;
    } catch (Exception e) {
        throw new WebScriptException("[ContentStoreInfoGet] Error in executeImpl function");
    }
}

From source file:org.hyperic.hq.plugin.weblogic.jmx.WeblogicDiscover.java

public void find(MBeanServer mServer, WeblogicQuery query, List types) throws WeblogicDiscoverException {
    ObjectName scope;/*from   www .  j a v  a  2 s.  c  om*/

    try {
        scope = new ObjectName(domain + ":" + query.getScope() + ",*");
        log.debug("[find] scope=" + scope);
    } catch (MalformedObjectNameException e) {
        // wont happen
        throw new IllegalArgumentException(e.getMessage());
    }

    try {
        for (Iterator it = mServer.queryNames(scope, null).iterator(); it.hasNext();) {
            ObjectName obj = (ObjectName) it.next();
            String name = obj.getKeyProperty("Name");
            if (name != null) {
                if (name.startsWith("__") || (name.indexOf("uuid-") != -1)) // wierdo 9.1 stuff i.e __weblogic_admin_rmi_queue
                {
                    continue;
                }
            }
            WeblogicQuery type = query.cloneInstance();
            if (type.getAttributes(mServer, obj)) {
                types.add(type);
                WeblogicQuery[] childQueries = query.getChildQueries();

                for (int i = 0; i < childQueries.length; i++) {
                    WeblogicQuery childQuery = childQueries[i];
                    childQuery.setParent(type);
                    childQuery.setVersion(type.getVersion());
                    find(mServer, childQuery, types);
                }
            }
        }
    } catch (Exception e) {
        throw new WeblogicDiscoverException(e);
    }
}

From source file:net.zcarioca.jmx.services.impl.MBeanObjectServiceImpl.java

/**
 * {@inheritDoc}/*ww  w . ja va 2 s  .co m*/
 */
@Override
public Set<MBeanDescriptor> findMBeansByType(final String domain, final String type) {
    return toMBeanObjectSet(getPlatformMBeanServer().queryMBeans(null, null), new Predicate() {
        @Override
        public boolean evaluate(Object object) {
            ObjectInstance objInst = (ObjectInstance) object;
            ObjectName name = objInst.getObjectName();
            if (StringUtils.equalsIgnoreCase(domain, objInst.getObjectName().getDomain())) {
                String objectType = name.getKeyProperty("type");
                return StringUtils.equalsIgnoreCase(type, objectType);
            }
            return false;
        }
    });
}