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.zenoss.jmxnl.NotificationListener.java

@SuppressWarnings("unchecked")
private void connect() throws IOException {
    log.info(url + ": Attempting connection (timeout in 180 seconds)");
    JMXConnector connector = JMXConnectorFactory.connect(url, environment);
    connector.addConnectionNotificationListener(this, null, "placeholder");
    MBeanServerConnection connection = connector.getMBeanServerConnection();

    log.info(url + ": Connected.");
    sendConnectionEvent("0", "JMX connection has been restored");

    Set<ObjectName> results = connection.queryNames(scope, null);
    java.util.Iterator<ObjectName> iter = results.iterator();
    while (iter.hasNext()) {
        ObjectName objName = (ObjectName) iter.next();
        String type = objName.getKeyProperty("type");
        if (type == null || !type.equals("alias")) {
            try {
                connection.addNotificationListener(objName, this, attributeFilter, zenossDevice);
                log.debug("Added notification listener: " + objName);
            } catch (IllegalArgumentException e) {
                log.debug("Can't listen to " + objName + " because it is not a notification broadcaster.");
            } catch (InstanceNotFoundException e) {
                log.debug("Can't listen to " + objName + " because it was not found on the server.");
            }/*from ww w .ja v a2s . c o m*/
        }

        // There can be a lot of listeners to add. Give other threads a
        // chance to get work done while this happens.
        Thread.yield();
    }
}

From source file:org.apache.jk.core.JkHandler.java

public ObjectName preRegister(MBeanServer server, ObjectName oname) throws Exception {
    this.oname = oname;
    mserver = server;//w w w.j  a  v  a 2  s .c om
    domain = oname.getDomain();
    if (name == null) {
        name = oname.getKeyProperty("name");
    }

    // we need to create a workerEnv or set one.
    ObjectName wEnvName = new ObjectName(domain + ":type=JkWorkerEnv");
    if (wEnv == null) {
        wEnv = new WorkerEnv();
    }
    if (!mserver.isRegistered(wEnvName)) {
        Registry.getRegistry().registerComponent(wEnv, wEnvName, null);
    }
    mserver.invoke(wEnvName, "addHandler", new Object[] { name, this },
            new String[] { "java.lang.String", "org.apache.jk.core.JkHandler" });
    return oname;
}

From source file:io.fabric8.mq.coordination.KubernetesControl.java

private BrokerOverview populateDestinations(J4pClient client, ObjectName root,
        BrokerDestinationOverview.Type type, BrokerOverview brokerOverview) {
    try {/* ww w . j  av a2  s .c  om*/
        String typeName = type == BrokerDestinationOverview.Type.QUEUE ? "Queue" : "Topic";
        List<ObjectName> list = BrokerJmxUtils.getDestinations(client, root, typeName);

        for (ObjectName objectName : list) {
            String destinationName = objectName.getKeyProperty("destinationName");
            if (!destinationName.toLowerCase().contains("advisory")
                    && !destinationName.contains(ActiveMQDestination.TEMP_DESTINATION_NAME_PREFIX)) {
                String producerCount = BrokerJmxUtils.getAttribute(client, objectName, "ProducerCount")
                        .toString().trim();
                String consumerCount = BrokerJmxUtils.getAttribute(client, objectName, "ConsumerCount")
                        .toString().trim();
                String queueSize = BrokerJmxUtils.getAttribute(client, objectName, "QueueSize").toString()
                        .trim();
                ActiveMQDestination destination = type == BrokerDestinationOverview.Type.QUEUE
                        ? new ActiveMQQueue(destinationName)
                        : new ActiveMQTopic(destinationName);
                BrokerDestinationOverview brokerDestinationOverview = new BrokerDestinationOverview(
                        destination);
                brokerDestinationOverview.setNumberOfConsumers(Integer.parseInt(consumerCount));
                brokerDestinationOverview.setNumberOfProducers(Integer.parseInt(producerCount));
                brokerDestinationOverview.setQueueDepth(Integer.parseInt(queueSize));
                brokerOverview.addDestinationStatistics(brokerDestinationOverview);
            }
        }
    } catch (Exception ex) {
        // Destinations don't exist yet on the broker
        LOG.debug("populateDestinations failed", ex);
    }
    return brokerOverview;
}

From source file:com.googlecode.psiprobe.beans.JBossResourceResolverBean.java

public List getApplicationResources() throws NamingException {

    List resources = new ArrayList();

    MBeanServer server = getMBeanServer();
    if (server != null) {
        try {//w w w.java 2  s . co  m
            Set dsNames = server.queryNames(new ObjectName("jboss.jca:service=ManagedConnectionPool,*"), null);
            for (Iterator it = dsNames.iterator(); it.hasNext();) {
                ObjectName managedConnectionPoolOName = (ObjectName) it.next();

                ApplicationResource resource = new ApplicationResource();
                resource.setName(managedConnectionPoolOName.getKeyProperty("name"));
                resource.setType("jboss");
                String criteria = (String) server.getAttribute(managedConnectionPoolOName, "Criteria");
                if ("ByApplication".equals(criteria)) {
                    resource.setAuth("Application");
                } else if ("ByContainerAndApplication".equals(criteria)) {
                    resource.setAuth("Both");
                } else {
                    resource.setAuth("Container");
                }
                DataSourceInfo dsInfo = new DataSourceInfo();
                dsInfo.setMaxConnections(
                        ((Integer) server.getAttribute(managedConnectionPoolOName, "MaxSize")).intValue());
                dsInfo.setEstablishedConnections(
                        ((Integer) server.getAttribute(managedConnectionPoolOName, "ConnectionCount"))
                                .intValue());
                dsInfo.setBusyConnections(
                        ((Long) server.getAttribute(managedConnectionPoolOName, "InUseConnectionCount"))
                                .intValue());

                ObjectName connectionFactoryOName = new ObjectName(
                        "jboss.jca:service=ManagedConnectionFactory,name=" + resource.getName());
                Element elm = (Element) server.getAttribute(connectionFactoryOName,
                        "ManagedConnectionFactoryProperties");

                if (elm != null) {
                    NodeList nl = elm.getChildNodes();
                    for (int i = 0; i < nl.getLength(); i++) {
                        Node n = nl.item(i);
                        Node na = n.getAttributes().getNamedItem("name");
                        if (na != null) {
                            if ("ConnectionURL".equals(na.getNodeValue())) {
                                dsInfo.setJdbcURL(n.getFirstChild().getNodeValue());
                            }

                            if ("UserName".equals(na.getNodeValue())) {
                                dsInfo.setUsername(n.getFirstChild().getNodeValue());
                            }

                            //
                            // JMS datasource
                            //
                            if ("JmsProviderAdapterJNDI".equals(na.getNodeValue())) {
                                dsInfo.setJdbcURL(n.getFirstChild().getNodeValue());
                                resource.setType("jms");
                            }
                        }
                    }
                }

                dsInfo.setResettable(true);

                resource.setDataSourceInfo(dsInfo);
                resources.add(resource);
            }
        } catch (Exception e) {
            //
            logger.fatal("There was an error querying JBoss JMX server:", e);
        }
    }
    return resources;
}

From source file:org.xmatthew.spy2servers.component.spy.jmx.TomcatJmxSpyComponent.java

@Override
protected void inspectMBean(ObjectInstance objectInstance, MBeanServerConnection mbsc) throws Exception {
    super.inspectMBean(objectInstance, mbsc);

    String mBeanClass = objectInstance.getClassName();
    ObjectName objectName = objectInstance.getObjectName();

    if (BASEMODELBEAN_CLASS.equals(mBeanClass) || BASEMODELBAEN_CLASS_CHANGED.equals(mBeanClass)) {
        String type = objectName.getKeyProperty(JmxSpySupportComponent.TYPE);
        String name = objectName.getKeyProperty(JmxSpySupportComponent.NAME);
        name = StringUtils.remove(name, "\"");
        //is a DataSource mbean
        if (DATASOURCE.equals(type)) {
            dataSourceMBeanSpy(name, getAttributesAsMap(objectName.toString(), mbsc, getDataSourceKeys()));

        } else if (MANAGER.equals(type)) { //is a web module mbean 

        }/* w ww . j a v  a2s.com*/
    }
}

From source file:be.fgov.kszbcss.rhq.websphere.config.CellConfiguration.java

ConfigObject getConfigObject(ObjectName objectName) {
    String id = objectName.getKeyProperty(SystemAttributes._WEBSPHERE_CONFIG_DATA_ID);
    synchronized (configObjectCache) {
        ConfigObject configObject = configObjectCache.get(id);
        if (configObject != null) {
            if (log.isDebugEnabled()) {
                log.debug("Config object cache hit for " + id);
            }/*from ww w .jav a2 s .c  om*/
        } else {
            if (log.isDebugEnabled()) {
                log.debug("Config object cache miss for " + id);
            }
            // TODO: null check (unknown config object type)
            configObject = ConfigObjectTypeRegistry
                    .getDescriptor(objectName.getKeyProperty(SystemAttributes._WEBSPHERE_CONFIG_DATA_TYPE))
                    .createInstance(this, objectName);
            configObjectCache.put(id, configObject);
        }
        return configObject;
    }
}

From source file:com.sun.grizzly.http.jk.core.JkHandler.java

public ObjectName preRegister(MBeanServer server, ObjectName oname) throws Exception {
    this.oname = oname;
    mserver = server;//from  ww  w .j a  v  a  2s. c  o  m
    domain = oname.getDomain();
    if (name == null) {
        name = oname.getKeyProperty("name");
    }

    // we need to create a workerEnv or set one.
    ObjectName wEnvName = new ObjectName(domain + ":type=JkWorkerEnv");
    if (wEnv == null) {
        wEnv = new WorkerEnv();
    }
    if (!mserver.isRegistered(wEnvName)) {
        Registry.getRegistry(null, null).registerComponent(wEnv, wEnvName, null);
    }
    mserver.invoke(wEnvName, "addHandler", new Object[] { name, this },
            new String[] { "java.lang.String", "com.sun.grizzly.http.jk.core.JkHandler" });
    return oname;
}

From source file:org.jboss.web.tomcat.tc5.StatusServlet.java

/**
 * Process a GET request for the specified resource.
 *
 * @param request  The servlet request we are processing
 * @param response The servlet response we are creating
 * @throws IOException      if an input/output error occurs
 * @throws ServletException if a servlet-specified error occurs
 *///from w  ww.  j a v  a 2 s. c o m
public void doGet(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    // mode is flag for HTML or XML output
    int mode = 0;
    // if ?XML=true, set the mode to XML
    if ("true".equals(request.getParameter("XML"))) {
        mode = 1;
    }
    StatusTransformer.setContentType(response, mode);

    PrintWriter writer = response.getWriter();

    boolean completeStatus = false;
    if ("true".equals(request.getParameter("full"))) {
        completeStatus = true;
    }

    // use StatusTransformer to output status
    if (mode == 0) {
        // HTML Header Section
        writer.print(HTML_HEADER);
    } else if (mode == 1) {
        writer.write(Constants.XML_DECLARATION);
        writer.write(Constants.XML_STYLE);
        writer.write("<status>");
    }

    try {

        // Display virtual machine statistics
        StatusTransformer.writeVMState(writer, mode);

        Enumeration i = threadPools.elements();
        while (i.hasMoreElements()) {
            ObjectName objectName = (ObjectName) i.nextElement();
            String name = objectName.getKeyProperty("name");
            // use StatusTransformer to output status
            StatusTransformer.writeConnectorState(writer, objectName, name, mBeanServer,
                    globalRequestProcessors, requestProcessors, mode);
        }

        if (completeStatus) {
            // Note: Retrieving the full status is much slower
            // use StatusTransformer to output status
            StatusTransformer.writeDetailedState(writer, mBeanServer, mode);
        }

    } catch (Exception e) {
        throw new ServletException(e);
    }

    if (mode == 0) {
        writer.print(HTML_FOOTER);
    } else if (mode == 1) {
        writer.write("</status>");
    }

}

From source file:com.googlecode.psiprobe.beans.ContainerListenerBean.java

/**
 * Load ObjectNames for the relevant MBeans so they can be queried at a later stage without searching MBean server
 * over and over again./*from w  ww  .java  2 s  . c o  m*/
 *
 * @throws Exception - this method does not handle any of the exceptions that may be thrown when querying MBean server.
 */
private synchronized void initialize() throws Exception {

    MBeanServer server = getContainerWrapper().getResourceResolver().getMBeanServer();
    String serverName = getContainerWrapper().getTomcatContainer().getName();
    Set threadPools = server.queryMBeans(new ObjectName(serverName + ":type=ThreadPool,*"), null);
    poolNames = new ArrayList(threadPools.size());
    for (Iterator it = threadPools.iterator(); it.hasNext();) {

        ThreadPoolObjectName threadPoolObjectName = new ThreadPoolObjectName();
        ObjectName threadPoolName = ((ObjectInstance) it.next()).getObjectName();

        String name = threadPoolName.getKeyProperty("name");

        threadPoolObjectName.setThreadPoolName(threadPoolName);
        ObjectName grpName = server
                .getObjectInstance(new ObjectName(
                        threadPoolName.getDomain() + ":type=GlobalRequestProcessor,name=" + name))
                .getObjectName();
        threadPoolObjectName.setGlobalRequestProcessorName(grpName);

        //
        // unfortunately exact workers could not be found at the time of testing
        // so we filter out the relevant workers within the loop
        //
        Set workers = server
                .queryMBeans(new ObjectName(threadPoolName.getDomain() + ":type=RequestProcessor,*"), null);

        for (Iterator wrkIt = workers.iterator(); wrkIt.hasNext();) {
            ObjectName wrkName = ((ObjectInstance) wrkIt.next()).getObjectName();
            if (name.equals(wrkName.getKeyProperty("worker"))) {
                threadPoolObjectName.getRequestProcessorNames().add(wrkName);
            }
        }

        poolNames.add(threadPoolObjectName);
    }

    Set executors = server.queryMBeans(new ObjectName(serverName + ":type=Executor,*"), null);
    executorNames = new ArrayList(executors.size());
    for (Iterator it = executors.iterator(); it.hasNext();) {
        ObjectName executorName = ((ObjectInstance) it.next()).getObjectName();
        executorNames.add(executorName);
    }

    // Register with MBean server
    server.addNotificationListener(new ObjectName("JMImplementation:type=MBeanServerDelegate"), this, null,
            null);

}

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

private List discover(AdminClient mServer, String domain, WebSphereQuery query) throws PluginException {

    List res = new ArrayList();
    boolean isApp = query instanceof ApplicationQuery;

    ObjectName scope;/*from  w w  w  . j  a v  a  2  s  .com*/
    try {
        scope = new ObjectName(domain + ":" + query.getScope() + ",*");
    } catch (MalformedObjectNameException e) {
        throw new PluginException(e.getMessage(), e);
    }

    Set beans;

    try {
        query.setMBeanServer(mServer);
        beans = mServer.queryNames(scope, null);
    } catch (ConnectorException e) {
        throw new PluginException(e.getMessage(), e);
    }

    for (Iterator it = beans.iterator(); it.hasNext();) {
        ObjectName obj = (ObjectName) it.next();

        WebSphereQuery type = query.cloneInstance();
        type.setName(obj.getKeyProperty("name"));
        type.setObjectName(obj);
        type.getAttributes(mServer, obj);

        if (type.apply()) {
            res.add(type);
            if (isApp) {
                for (WebSphereQuery moduleQuery : moduleQueries) {
                    moduleQuery.setParent(type);
                    res.addAll(discover(mServer, domain, moduleQuery));
                }
            }
        } else {
            log.debug("[discover] MBean discarted. obj:'" + obj + "'");
        }
    }
    return res;
}