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.webapp.admin.TomcatTreeBuilder.java

/**
 * Append nodes for all defined hosts for the specified service.
 *
 * @param serviceNode Service node for the tree control
 * @param serviceName Object name of the parent service
 * @param resources The MessageResources for our localized messages
 *  messages//from   w  w w. j  av  a  2  s.  c  o m
 *
 * @exception Exception if an exception occurs building the tree
 */
public void getHosts(TreeControlNode serviceNode, String serviceName, MessageResources resources)
        throws Exception {

    String domain = serviceNode.getDomain();
    Iterator hostNames = Lists.getHosts(mBServer, serviceName).iterator();
    while (hostNames.hasNext()) {
        String hostName = (String) hostNames.next();
        ObjectName objectName = new ObjectName(hostName);
        String nodeLabel = "Host (" + objectName.getKeyProperty("host") + ")";
        TreeControlNode hostNode = new TreeControlNode(hostName, "Host.gif", nodeLabel, "EditHost.do?select="
                + URLEncoder.encode(hostName) + "&nodeLabel=" + URLEncoder.encode(nodeLabel), "content", false,
                domain);
        serviceNode.addChild(hostNode);
        getContexts(hostNode, hostName, resources);
        getDefaultContexts(hostNode, hostName, resources);
        getLoggers(hostNode, hostName);
        getRealms(hostNode, hostName);
        getValves(hostNode, hostName);
    }

}

From source file:org.apache.webapp.admin.TomcatTreeBuilder.java

/**
 * Append nodes for all defined connectors for the specified service.
 *
 * @param serviceNode Service node for the tree control
 * @param serviceName Object name of the parent service
 *
 * @exception Exception if an exception occurs building the tree
 *///w  ww  .  j a v a 2 s.com
public void getConnectors(TreeControlNode serviceNode, String serviceName) throws Exception {

    String domain = serviceNode.getDomain();
    Iterator connectorNames = Lists.getConnectors(mBServer, serviceName).iterator();
    while (connectorNames.hasNext()) {
        String connectorName = (String) connectorNames.next();
        ObjectName objectName = new ObjectName(connectorName);
        String nodeLabel = "Connector (" + objectName.getKeyProperty("port") + ")";
        TreeControlNode connectorNode = new TreeControlNode(
                connectorName, "Connector.gif", nodeLabel, "EditConnector.do?select="
                        + URLEncoder.encode(connectorName) + "&nodeLabel=" + URLEncoder.encode(nodeLabel),
                "content", false, domain);
        serviceNode.addChild(connectorNode);
    }
}

From source file:org.apache.webapp.admin.TomcatTreeBuilder.java

/**
 * Append nodes for all defined services for the specified server.
 *
 * @param serverNode Server node for the tree control
 * @param serverName Object name of the parent server
 * @param resources The MessageResources for our localized messages
 *  messages/*from  www  .  j a va  2  s  . c om*/
 *
 * @exception Exception if an exception occurs building the tree
 */
public void getServices(TreeControlNode serverNode, String serverName, MessageResources resources)
        throws Exception {

    String domain = serverNode.getDomain();
    Iterator serviceNames = Lists.getServices(mBServer, serverName).iterator();
    while (serviceNames.hasNext()) {
        String serviceName = (String) serviceNames.next();
        ObjectName objectName = new ObjectName(serviceName);
        String nodeLabel = "Service (" + objectName.getKeyProperty("serviceName") + ")";
        TreeControlNode serviceNode = new TreeControlNode(serviceName, "Service.gif", nodeLabel,
                "EditService.do?select=" + URLEncoder.encode(serviceName) + "&nodeLabel="
                        + URLEncoder.encode(nodeLabel),
                "content", false, domain);
        serverNode.addChild(serviceNode);
        getConnectors(serviceNode, serviceName);
        getDefaultContexts(serviceNode, serviceName, resources);
        getHosts(serviceNode, serviceName, resources);
        getLoggers(serviceNode, serviceName);
        getRealms(serviceNode, serviceName);
        getValves(serviceNode, serviceName);
    }

}

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

TomcatConnectorMetricSet(ObjectName threadPoolObjectName) {
    Preconditions.checkNotNull(threadPoolObjectName);

    MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();

    this.name = threadPoolObjectName.getKeyProperty("name");
    this.port = JmxUtil.getJmxAttribute(threadPoolObjectName, "port", Integer.class, null);

    Set<ObjectName> connectorObjectNames = null;
    try {//from  w w  w  .j av  a2  s. c om
        connectorObjectNames = mBeanServer.queryNames(new ObjectName("Catalina:type=Connector,port=" + port),
                null);
    } catch (MalformedObjectNameException e) {
        logger.debug("Invalid ObjectName defined for the Tomcat's Connector MxBean for the {} thread pool",
                name, e);
    }

    if (connectorObjectNames != null && !connectorObjectNames.isEmpty()) {
        ObjectName connectorObjectName = connectorObjectNames.iterator().next();
        String internalPortStr = JmxUtil.getJmxAttribute(connectorObjectName, "internalPort", String.class,
                Boolean.FALSE.toString());
        this.isInternalPort = Boolean.TRUE.toString().equalsIgnoreCase(internalPortStr);
    }

    this.isSecure = JmxUtil.getJmxAttribute(threadPoolObjectName, "sSLEnabled", Boolean.class, Boolean.FALSE);
    this.isAjp = isAjpFromName(name);

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

    this.currentPoolSizeGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "currentThreadCount",
            Integer.class, 0);
    if (currentPoolSizeGauge != null) {
        metricsByNames.put("currentPoolSize", currentPoolSizeGauge);
    }

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

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

    this.activeConnectionsGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "connectionCount",
            Long.class, 0L);
    if (activeConnectionsGauge != null) {
        metricsByNames.put("activeConnections", activeConnectionsGauge);
    }

    this.maxConnectionsGauge = JmxUtil.getJmxAttributeAsGauge(threadPoolObjectName, "maxConnections",
            Integer.class, 0);
    if (maxConnectionsGauge != null) {
        metricsByNames.put("maxConnections", maxConnectionsGauge);
    }

    Set<ObjectName> globalRequestProcessorObjectNames = null;
    try {
        globalRequestProcessorObjectNames = mBeanServer
                .queryNames(new ObjectName("Catalina:type=GlobalRequestProcessor,name=" + name), null);
    } catch (MalformedObjectNameException e) {
        logger.debug(
                "Invalid ObjectName defined for the Tomcat's GlobalRequestProcessor MxBean for the {} thread pool",
                name, e);
    }

    if (globalRequestProcessorObjectNames != null && !globalRequestProcessorObjectNames.isEmpty()) {
        ObjectName globalRequestProcessorObjectName = globalRequestProcessorObjectNames.iterator().next();
        this.totalRequestsGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName,
                "requestCount", Integer.class, 0);

        if (totalRequestsGauge != null) {
            metricsByNames.put("totalRequests", totalRequestsGauge);

            this.qpsHolder = new AtomicInteger();
            this.previousRequestCount = totalRequestsGauge.getValue();

            this.qpsGauge = new Gauge<Integer>() {
                @Override
                public Integer getValue() {
                    return qpsHolder.get();
                }
            };
            metricsByNames.put("qps", qpsGauge);
        }

        this.errorsGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName, "errorCount",
                Integer.class, 0);
        if (errorsGauge != null) {
            metricsByNames.put("errors", errorsGauge);
        }

        this.receivedBytesGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName,
                "bytesReceived", Long.class, 0L);
        if (receivedBytesGauge != null) {
            metricsByNames.put("receivedBytes", receivedBytesGauge);
        }

        this.sentBytesGauge = JmxUtil.getJmxAttributeAsGauge(globalRequestProcessorObjectName, "bytesSent",
                Long.class, 0L);
        if (sentBytesGauge != null) {
            metricsByNames.put("sentBytes", sentBytesGauge);
        }
    }

    this.metricsByNames = metricsByNames;
}

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

public boolean getAttributes(MBeanServer mServer, ObjectName name) {

    setName(name.getKeyProperty("Name"));
    setVersion(getDiscover().getVersion()); //type version

    if (!super.getAttributes(mServer, name, SERVER_ATTRS)) {
        return false;
    }//from w w w.  j  ava 2  s  .c om

    if (isAdminPortEnabled()) {
        //gone in 9.1+
        super.getAttributes(mServer, name, new String[] { ATTR_ADMIN_OVERRIDE_PORT });
    }

    ObjectName runtimeName = getServerRuntime();
    ObjectName logName = getLogMBean();

    boolean isAdminName = getName().equals(this.discover.getAdminName());

    if (isAdminName) {
        //this is the admin server instance
        super.getAttributes(mServer, runtimeName, SERVER_RUNTIME_ATTRS);
        super.getAttributes(mServer, getJVMRuntime(), JVM_RUNTIME_ATTRS);
        super.getAttributes(mServer, logName, LOG_ATTRS);
        if (getSSLListenPort() == null) {
            getSSLAttrs(mServer);
        }
        configureUrl();
    } else {
        getSSLAttrs(mServer);

        //this is a node server
        configureUrl();

        try {
            MBeanServer nodeServer = this.discover.getMBeanServer(this.url);
            this.isRunning = super.getAttributes(nodeServer, runtimeName, SERVER_RUNTIME_ATTRS);
            if (this.isRunning) {
                if (getJVMRuntime() == null) {
                    this.isRunning = false;
                } else {
                    super.getAttributes(nodeServer, getJVMRuntime(), JVM_RUNTIME_ATTRS);
                }
                super.getAttributes(nodeServer, logName, LOG_ATTRS);
            }
            configureUrl(); //attributes may differ now (e.g. ListenAddress)
        } catch (Exception e) {
            //ok; server is not running.
            this.isRunning = false;
        }
    }

    String serverVersion = getAttribute("ServerVersion");

    if (isValidVersion(serverVersion)) {
        this.wlsVersion = serverVersion.substring(0, 3);
    } else if ((serverVersion == null) || serverVersion.equals("unknown")) {
        //6.1 does not have a ServerVersion attribute.
        //9.1 might be == "unknown"
        this.wlsVersion = getWeblogicVersion();
    }

    if (!this.isRunning) {
        return true;
    }

    /*
    //6.1 does not have the AdminServer attribute.
    //PeopleSoft may have AdminServer = true for nodes.
    String adminServer = getAttribute("AdminServer");
    if (adminServer != null) {
    this.isAdmin = "true".equals(adminServer);
    }
    */
    this.isAdmin = isAdminName;

    //XXX if node is started by the nodemanager
    //this value is different than when started by hand
    File path = new File(getAttribute("CurrentDirectory"));
    if (path.getName().equals(".")) {
        path = path.getParentFile();
    }
    this.cwd = path;

    return true;
}

From source file:com.heliosapm.opentsdb.TSDBSubmitterImpl.java

/**
 * Cleans the object name property identified by the passed key
 * @param on The ObjectName to extract the value from
 * @param key The key property name/*  w ww  . j a  va  2 s .  c o m*/
 * @return the cleaned key property value
 */
public static String clean(final ObjectName on, final String key) {
    if (on == null)
        throw new IllegalArgumentException("The passed ObjectName was null");
    if (key == null || key.trim().isEmpty())
        throw new IllegalArgumentException("The passed key was null or empty");
    return clean(on.getKeyProperty(key.trim()));
}

From source file:org.apache.webapp.admin.TomcatTreeBuilder.java

/**
 * Append nodes for any define resources for the specified Context.
 *
 * @param containerNode Container node for the tree control
 * @param containerName Object name of the parent container
 * @param resources The MessageResources for our localized messages
 *  messages/*from w  ww  .  j av a 2 s  . c o m*/
 */
public void getResources(TreeControlNode containerNode, String containerName, MessageResources resources)
        throws Exception {

    String domain = containerNode.getDomain();
    ObjectName oname = new ObjectName(containerName);
    String type = oname.getKeyProperty("type");
    if (type == null) {
        type = oname.getKeyProperty("j2eeType");
        if (type.equals("WebModule")) {
            type = "Context";
        } else {
            type = "";
        }
    }
    String path = "";
    String host = "";
    String name = oname.getKeyProperty("name");
    if ((name != null) && (name.length() > 0)) {
        // context resource
        name = name.substring(2);
        int i = name.indexOf("/");
        host = name.substring(0, i);
        path = name.substring(i);
    }
    TreeControlNode subtree = new TreeControlNode("Context Resource Administration " + containerName,
            "folder_16_pad.gif", resources.getMessage("resources.treeBuilder.subtreeNode"), null, "content",
            true, domain);
    containerNode.addChild(subtree);
    TreeControlNode datasources = new TreeControlNode("Context Data Sources " + containerName, "Datasource.gif",
            resources.getMessage("resources.treeBuilder.datasources"),
            "resources/listDataSources.do?resourcetype=" + URLEncoder.encode(type) + "&path="
                    + URLEncoder.encode(path) + "&host=" + URLEncoder.encode(host) + "&domain="
                    + URLEncoder.encode(domain) + "&forward=" + URLEncoder.encode("DataSources List Setup"),
            "content", false, domain);
    TreeControlNode mailsessions = new TreeControlNode("Context Mail Sessions " + containerName,
            "Mailsession.gif", resources.getMessage("resources.treeBuilder.mailsessions"),
            "resources/listMailSessions.do?resourcetype=" + URLEncoder.encode(type) + "&path="
                    + URLEncoder.encode(path) + "&host=" + URLEncoder.encode(host) + "&domain="
                    + URLEncoder.encode(domain) + "&forward=" + URLEncoder.encode("MailSessions List Setup"),
            "content", false, domain);
    TreeControlNode resourcelinks = new TreeControlNode("Resource Links " + containerName, "ResourceLink.gif",
            resources.getMessage("resources.treeBuilder.resourcelinks"),
            "resources/listResourceLinks.do?resourcetype=" + URLEncoder.encode(type) + "&path="
                    + URLEncoder.encode(path) + "&host=" + URLEncoder.encode(host) + "&domain="
                    + URLEncoder.encode(domain) + "&forward=" + URLEncoder.encode("ResourceLinks List Setup"),
            "content", false, domain);
    TreeControlNode envs = new TreeControlNode("Context Environment Entries " + containerName,
            "EnvironmentEntries.gif", resources.getMessage("resources.env.entries"),
            "resources/listEnvEntries.do?resourcetype=" + URLEncoder.encode(type) + "&path="
                    + URLEncoder.encode(path) + "&host=" + URLEncoder.encode(host) + "&domain="
                    + URLEncoder.encode(domain) + "&forward=" + URLEncoder.encode("EnvEntries List Setup"),
            "content", false, domain);
    subtree.addChild(datasources);
    subtree.addChild(mailsessions);
    subtree.addChild(resourcelinks);
    subtree.addChild(envs);
}

From source file:org.apache.coyote.tomcat5.MapperListener.java

public void handleNotification(Notification notification, java.lang.Object handback) {

    if (notification instanceof MBeanServerNotification) {
        ObjectName objectName = ((MBeanServerNotification) notification).getMBeanName();
        String j2eeType = objectName.getKeyProperty("j2eeType");
        String engineName = null;
        if (j2eeType != null) {
            if ((j2eeType.equals("WebModule")) || (j2eeType.equals("Servlet"))) {
                if (mBeanServer.isRegistered(objectName)) {
                    try {
                        engineName = (String) mBeanServer.getAttribute(objectName, "engineName");
                    } catch (Exception e) {
                        // Ignore  
                    }/*ww w.j  ava  2  s  .c om*/
                }
            }
        }

        // At deployment time, engineName is always = null.
        if ((!"*".equals(domain)) && (!domain.equals(objectName.getDomain()))
                && ((!domain.equals(engineName)) && (engineName != null))) {
            return;
        }

        log.debug("Handle " + objectName);
        if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
            String type = objectName.getKeyProperty("type");
            if ("Host".equals(type)) {
                try {
                    registerHost(objectName);
                } catch (Exception e) {
                    log.warn("Error registering Host " + objectName, e);
                }
            }

            if (j2eeType != null) {
                if (j2eeType.equals("WebModule")) {
                    try {
                        registerContext(objectName);
                    } catch (Throwable t) {
                        log.warn("Error registering Context " + objectName, t);
                    }
                } else if (j2eeType.equals("Servlet")) {
                    try {
                        registerWrapper(objectName);
                    } catch (Throwable t) {
                        log.warn("Error registering Wrapper " + objectName, t);
                    }
                }
            }
        } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
            String type = objectName.getKeyProperty("type");
            if ("Host".equals(type)) {
                try {
                    unregisterHost(objectName);
                } catch (Exception e) {
                    log.warn("Error unregistering Host " + objectName, e);
                }
            }

            if (j2eeType != null) {
                if (j2eeType.equals("WebModule")) {
                    try {
                        unregisterContext(objectName);
                    } catch (Throwable t) {
                        log.warn("Error unregistering webapp " + objectName, t);
                    }
                }
            }
        }
    }

}

From source file:org.apache.catalina.manager.StatusManagerServlet.java

public void handleNotification(Notification notification, java.lang.Object handback) {

    if (notification instanceof MBeanServerNotification) {
        ObjectName objectName = ((MBeanServerNotification) notification).getMBeanName();
        if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
            String type = objectName.getKeyProperty("type");
            if (type != null) {
                if (type.equals("ProtocolHandler")) {
                    protocolHandlers.addElement(objectName);
                } else if (type.equals("ThreadPool")) {
                    threadPools.addElement(objectName);
                } else if (type.equals("GlobalRequestProcessor")) {
                    globalRequestProcessors.addElement(objectName);
                } else if (type.equals("RequestProcessor")) {
                    requestProcessors.addElement(objectName);
                }/* ww  w  . j  av a 2s .co m*/
            }
        } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
            String type = objectName.getKeyProperty("type");
            if (type != null) {
                if (type.equals("ProtocolHandler")) {
                    protocolHandlers.removeElement(objectName);
                } else if (type.equals("ThreadPool")) {
                    threadPools.removeElement(objectName);
                } else if (type.equals("GlobalRequestProcessor")) {
                    globalRequestProcessors.removeElement(objectName);
                } else if (type.equals("RequestProcessor")) {
                    requestProcessors.removeElement(objectName);
                }
            }
            String j2eeType = objectName.getKeyProperty("j2eeType");
            if (j2eeType != null) {

            }
        }
    }

}