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.coyote.tomcat5.MapperListener.java

/**
 * Unregister context./*w w w.j a v a 2  s. c o m*/
 */
private void unregisterContext(ObjectName objectName) throws Exception {

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

    // If the domain is the same with ours or the engine 
    // name attribute is the same... - then it's ours
    String targetDomain = objectName.getDomain();
    if (!domain.equals(targetDomain)) {
        try {
            targetDomain = (String) mBeanServer.getAttribute(objectName, "engineName");
        } catch (Exception e) {
            // Ignore
        }
        if (!domain.equals(targetDomain)) {
            // not ours
            return;
        }
    }

    String hostName = null;
    String contextName = null;
    if (name.startsWith("//")) {
        name = name.substring(2);
    }
    int slash = name.indexOf("/");
    if (slash != -1) {
        hostName = name.substring(0, slash);
        contextName = name.substring(slash);
    } else {
        return;
    }
    // Special case for the root context
    if (contextName.equals("/")) {
        contextName = "";
    }

    log.debug(sm.getString("mapperListener.unregisterContext", contextName));

    mapper.removeContext(hostName, contextName);

}

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

public synchronized List getConnectors(boolean includeRequestProcessors) throws Exception {
    boolean workerThreadNameSupported = true;

    if (!isInitialized()) {
        initialize();/*from  ww  w  .j  a  va  2  s . c o m*/
    }

    List connectors = new ArrayList(poolNames.size());

    MBeanServer server = getContainerWrapper().getResourceResolver().getMBeanServer();

    for (Iterator it = poolNames.iterator(); it.hasNext();) {

        ThreadPoolObjectName threadPoolObjectName = (ThreadPoolObjectName) it.next();
        boolean remoteAddrAvailable = true;
        try {
            ObjectName poolName = threadPoolObjectName.getThreadPoolName();

            Connector connector = new Connector();
            connector.setName(poolName.getKeyProperty("name"));

            ObjectName grpName = threadPoolObjectName.getGlobalRequestProcessorName();

            connector.setMaxTime(JmxTools.getLongAttr(server, grpName, "maxTime"));
            connector.setProcessingTime(JmxTools.getLongAttr(server, grpName, "processingTime"));
            connector.setBytesReceived(JmxTools.getLongAttr(server, grpName, "bytesReceived"));
            connector.setBytesSent(JmxTools.getLongAttr(server, grpName, "bytesSent"));
            connector.setRequestCount(JmxTools.getIntAttr(server, grpName, "requestCount"));
            connector.setErrorCount(JmxTools.getIntAttr(server, grpName, "errorCount"));

            if (includeRequestProcessors) {
                for (Iterator wrkIt = threadPoolObjectName.getRequestProcessorNames().iterator(); wrkIt
                        .hasNext();) {
                    ObjectName wrkName = (ObjectName) wrkIt.next();

                    try {
                        RequestProcessor rp = new RequestProcessor();
                        rp.setName(wrkName.getKeyProperty("name"));
                        rp.setStage(JmxTools.getIntAttr(server, wrkName, "stage"));
                        rp.setProcessingTime(JmxTools.getLongAttr(server, wrkName, "requestProcessingTime"));
                        rp.setBytesSent(JmxTools.getLongAttr(server, wrkName, "requestBytesSent"));
                        rp.setBytesReceived(JmxTools.getLongAttr(server, wrkName, "requestBytesReceived"));
                        try {
                            String remoteAddr = JmxTools.getStringAttr(server, wrkName, "remoteAddr");
                            rp.setRemoteAddr(remoteAddr);
                            rp.setRemoteAddrLocale(InetAddressLocator
                                    .getLocale(InetAddress.getByName(remoteAddr).getAddress()));
                        } catch (RuntimeOperationsException ex) {
                            /*
                             * if it's not available for this request processor, then it's
                             * not available for any request processor in this thread pool
                             */
                            remoteAddrAvailable = false;
                        }
                        rp.setVirtualHost(JmxTools.getStringAttr(server, wrkName, "virtualHost"));
                        rp.setMethod(JmxTools.getStringAttr(server, wrkName, "method"));
                        rp.setCurrentUri(JmxTools.getStringAttr(server, wrkName, "currentUri"));
                        rp.setCurrentQueryString(JmxTools.getStringAttr(server, wrkName, "currentQueryString"));
                        rp.setProtocol(JmxTools.getStringAttr(server, wrkName, "protocol"));

                        // Relies on https://issues.apache.org/bugzilla/show_bug.cgi?id=41128
                        if (workerThreadNameSupported
                                && JmxTools.hasAttribute(server, wrkName, "workerThreadName")) {
                            rp.setWorkerThreadName(JmxTools.getStringAttr(server, wrkName, "workerThreadName"));
                            rp.setWorkerThreadNameSupported(true);
                        } else {
                            //
                            // attribute should consistently either exist or be missing across all the workers so
                            // it does not make sense to check attribute existence
                            // if we have found once that it is not supported
                            //
                            rp.setWorkerThreadNameSupported(false);
                            workerThreadNameSupported = false;
                        }
                        connector.addRequestProcessor(rp);
                    } catch (InstanceNotFoundException e) {
                        logger.info("Failed to query RequestProcessor " + wrkName);
                        logger.debug("  Stack trace:", e);
                    }
                }
            }

            connectors.add(connector);
        } catch (InstanceNotFoundException e) {
            logger.error("Failed to query entire thread pool " + threadPoolObjectName);
            logger.debug("  Stack trace:", e);
        }
    }
    return connectors;
}

From source file:net.testdriven.psiprobe.beans.ContainerListenerBean.java

public synchronized List getConnectors(boolean includeRequestProcessors) throws Exception {
    boolean workerThreadNameSupported = true;

    if (!isInitialized()) {
        initialize();/*  ww  w  . jav  a2s  .c om*/
    }

    List connectors = new ArrayList(poolNames.size());

    MBeanServer server = getContainerWrapper().getResourceResolver().getMBeanServer();

    for (Iterator it = poolNames.iterator(); it.hasNext();) {

        ThreadPoolObjectName threadPoolObjectName = (ThreadPoolObjectName) it.next();
        try {
            ObjectName poolName = threadPoolObjectName.getThreadPoolName();

            Connector connector = new Connector();
            connector.setName(poolName.getKeyProperty("name"));

            ObjectName grpName = threadPoolObjectName.getGlobalRequestProcessorName();

            connector.setMaxTime(JmxTools.getLongAttr(server, grpName, "maxTime"));
            connector.setProcessingTime(JmxTools.getLongAttr(server, grpName, "processingTime"));
            connector.setBytesReceived(JmxTools.getLongAttr(server, grpName, "bytesReceived"));
            connector.setBytesSent(JmxTools.getLongAttr(server, grpName, "bytesSent"));
            connector.setRequestCount(JmxTools.getIntAttr(server, grpName, "requestCount"));
            connector.setErrorCount(JmxTools.getIntAttr(server, grpName, "errorCount"));

            if (includeRequestProcessors) {
                for (Iterator wrkIt = threadPoolObjectName.getRequestProcessorNames().iterator(); wrkIt
                        .hasNext();) {
                    ObjectName wrkName = (ObjectName) wrkIt.next();

                    try {
                        RequestProcessor rp = new RequestProcessor();
                        rp.setName(wrkName.getKeyProperty("name"));
                        rp.setStage(JmxTools.getIntAttr(server, wrkName, "stage"));
                        rp.setProcessingTime(JmxTools.getLongAttr(server, wrkName, "requestProcessingTime"));
                        rp.setBytesSent(JmxTools.getLongAttr(server, wrkName, "requestBytesSent"));
                        rp.setBytesReceived(JmxTools.getLongAttr(server, wrkName, "requestBytesReceived"));
                        try {
                            String remoteAddr = JmxTools.getStringAttr(server, wrkName, "remoteAddr");
                            rp.setRemoteAddr(remoteAddr);
                            rp.setRemoteAddrLocale(InetAddressLocator
                                    .getLocale(InetAddress.getByName(remoteAddr).getAddress()));
                        } catch (RuntimeOperationsException ex) {
                            /*
                             * if it's not available for this request processor, then it's
                             * not available for any request processor in this thread pool
                             */
                        }
                        rp.setVirtualHost(JmxTools.getStringAttr(server, wrkName, "virtualHost"));
                        rp.setMethod(JmxTools.getStringAttr(server, wrkName, "method"));
                        rp.setCurrentUri(JmxTools.getStringAttr(server, wrkName, "currentUri"));
                        rp.setCurrentQueryString(JmxTools.getStringAttr(server, wrkName, "currentQueryString"));
                        rp.setProtocol(JmxTools.getStringAttr(server, wrkName, "protocol"));

                        // Relies on https://issues.apache.org/bugzilla/show_bug.cgi?id=41128
                        if (workerThreadNameSupported
                                && JmxTools.hasAttribute(server, wrkName, "workerThreadName")) {
                            rp.setWorkerThreadName(JmxTools.getStringAttr(server, wrkName, "workerThreadName"));
                            rp.setWorkerThreadNameSupported(true);
                        } else {
                            //
                            // attribute should consistently either exist or be missing across all the workers so
                            // it does not make sense to check attribute existence
                            // if we have found once that it is not supported
                            //
                            rp.setWorkerThreadNameSupported(false);
                            workerThreadNameSupported = false;
                        }
                        connector.addRequestProcessor(rp);
                    } catch (InstanceNotFoundException e) {
                        logger.info("Failed to query RequestProcessor " + wrkName);
                        logger.debug("  Stack trace:", e);
                    }
                }
            }

            connectors.add(connector);
        } catch (InstanceNotFoundException e) {
            logger.error("Failed to query entire thread pool " + threadPoolObjectName);
            logger.debug("  Stack trace:", e);
        }
    }
    return connectors;
}

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

/**
 * Register context.//from w  w  w .jav  a  2 s  . c  om
 */
private void registerContext(ObjectName objectName) throws Exception {

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

    // If the domain is the same with ours or the engine 
    // name attribute is the same... - then it's ours
    String targetDomain = objectName.getDomain();
    if (!domain.equals(targetDomain)) {
        try {
            targetDomain = (String) mBeanServer.getAttribute(objectName, "engineName");
        } catch (Exception e) {
            // Ignore
        }
        if (!domain.equals(targetDomain)) {
            // not ours
            return;
        }
    }

    String hostName = null;
    String contextName = null;
    if (name.startsWith("//")) {
        name = name.substring(2);
    }
    int slash = name.indexOf("/");
    if (slash != -1) {
        hostName = name.substring(0, slash);
        contextName = name.substring(slash);
    } else {
        return;
    }
    // Special case for the root context
    if (contextName.equals("/")) {
        contextName = "";
    }

    log.debug(sm.getString("mapperListener.registerContext", contextName));

    Object context = mBeanServer.invoke(objectName, "findMappingObject", null, null);
    //mBeanServer.getAttribute(objectName, "mappingObject");
    javax.naming.Context resources = (javax.naming.Context) mBeanServer.invoke(objectName,
            "findStaticResources", null, null);
    //mBeanServer.getAttribute(objectName, "staticResources");
    String[] welcomeFiles = (String[]) mBeanServer.getAttribute(objectName, "welcomeFiles");

    mapper.addContext(hostName, contextName, context, welcomeFiles, resources);

}

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

/**
 * Handles creation and deletion of new "worker" threads.
 *//*ww  w.j  a va 2  s  . c  om*/
public synchronized void handleNotification(Notification notification, Object object) {
    if (notification instanceof MBeanServerNotification) {
        ObjectName objectName = ((MBeanServerNotification) notification).getMBeanName();

        if (notification.getType().equals(MBeanServerNotification.REGISTRATION_NOTIFICATION)) {

            if ("RequestProcessor".equals(objectName.getKeyProperty("type"))) {
                ThreadPoolObjectName threadPoolObjectName = findPool(objectName.getKeyProperty("worker"));
                if (threadPoolObjectName != null) {
                    threadPoolObjectName.getRequestProcessorNames().add(objectName);
                }
            }

        } else if (notification.getType().equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {

            if ("RequestProcessor".equals(objectName.getKeyProperty("type"))) {
                ThreadPoolObjectName threadPoolObjectName = findPool(objectName.getKeyProperty("worker"));
                if (threadPoolObjectName != null) {
                    threadPoolObjectName.getRequestProcessorNames().remove(objectName);
                }
            }
        }
    }
}

From source file:org.taverna.server.master.interaction.InteractionFeedSupport.java

@PostConstruct
void determinePorts() {
    try {//from w  w w  .jav a 2  s .c o  m
        MBeanServer mbs = getPlatformMBeanServer();
        for (ObjectName obj : mbs.queryNames(new ObjectName("*:type=Connector,*"),
                match(attr("protocol"), value("HTTP/1.1")))) {
            String scheme = mbs.getAttribute(obj, "scheme").toString();
            String port = obj.getKeyProperty("port");
            endPoints.put(scheme, new URL(scheme + "://localhost:" + port));
        }
        getLog(getClass()).info("installed feed port publication mapping for " + endPoints.keySet());
    } catch (Exception e) {
        getLog(getClass()).error("failure in determining local port mapping", e);
    }
}

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

/**
 * Append nodes for all defined contexts for the specified host.
 *
 * @param hostNode Host node for the tree control
 * @param hostName Object name of the parent host
 * @param resources The MessageResources for our localized messages
 *  messages/*from  w  w w.j a  va 2  s.  c  o  m*/
 *
 * @exception Exception if an exception occurs building the tree
 */
public void getContexts(TreeControlNode hostNode, String hostName, MessageResources resources)
        throws Exception {

    String domain = hostNode.getDomain();
    Iterator contextNames = Lists.getContexts(mBServer, hostName).iterator();
    while (contextNames.hasNext()) {
        String contextName = (String) contextNames.next();
        ObjectName objectName = new ObjectName(contextName);
        String name = objectName.getKeyProperty("name");
        name = name.substring(2);
        int i = name.indexOf("/");
        String path = name.substring(i);
        String nodeLabel = "Context (" + path + ")";
        TreeControlNode contextNode = new TreeControlNode(contextName, "Context.gif", nodeLabel,
                "EditContext.do?select=" + URLEncoder.encode(contextName) + "&nodeLabel="
                        + URLEncoder.encode(nodeLabel),
                "content", false, domain);
        hostNode.addChild(contextNode);
        getResources(contextNode, contextName, resources);
        getLoggers(contextNode, contextName);
        getRealms(contextNode, contextName);
        getValves(contextNode, contextName);
    }
}

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

/**
 * Resolve the input virtual host names to the names of the configured Hosts
 * @param vhostNames Iterator<String> for the jboss-web/virtual-host elements 
 * @return Iterator<String> of the unique Host names
 * @throws Exception/*w w w .  j  a  va  2s  .  co  m*/
 */
protected synchronized Iterator mapVirtualHosts(Iterator vhostNames) throws Exception {
    if (vhostToHostNames.size() == 0) {
        // Query the configured Host mbeans
        String hostQuery = config.getCatalinaDomain() + ":type=Host,*";
        ObjectName query = new ObjectName(hostQuery);
        Set hosts = server.queryNames(query, null);
        Iterator iter = hosts.iterator();
        while (iter.hasNext()) {
            ObjectName host = (ObjectName) iter.next();
            String name = host.getKeyProperty("host");
            if (name != null) {
                vhostToHostNames.put(name, name);
                String[] aliases = (String[]) server.invoke(host, "findAliases", null, null);
                int count = aliases != null ? aliases.length : 0;
                for (int n = 0; n < count; n++) {
                    vhostToHostNames.put(aliases[n], name);
                }
            }
        }
    }

    // Map the virtual host names to the hosts
    HashSet hosts = new HashSet();
    while (vhostNames.hasNext()) {
        String vhost = (String) vhostNames.next();
        String host = (String) vhostToHostNames.get(vhost);
        if (host == null) {
            log.warn("Failed to map vhost: " + vhost);
            // This will cause a new host to be created
            host = vhost;
        }
        hosts.add(host);
    }
    return hosts.iterator();
}

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);
        }//www  . j  a v a 2 s.  c  o  m

        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:org.lilyproject.hadooptestfw.HBaseProxy.java

/**
 * obtains a map of the replication ids to the last sep event timestamp
 *//*w  w w. ja va2s  .  c o m*/
private Map<String, Long> getLastSepTimestamps(JmxLiaison jmxLiaison) throws Exception {
    ObjectName replicationSources = new ObjectName("hadoop:service=SEP,name=*");
    Set<ObjectName> mbeans = jmxLiaison.queryNames(replicationSources);
    Map<String, Long> result = new HashMap<String, Long>(mbeans.size());
    for (ObjectName mbean : mbeans) {
        result.put(mbean.getKeyProperty("name"), (Long) jmxLiaison.getAttribute(mbean, "lastSepTimestamp"));
    }
    return result;
}