Example usage for javax.management ObjectName getDomain

List of usage examples for javax.management ObjectName getDomain

Introduction

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

Prototype

public String getDomain() 

Source Link

Document

Returns the domain part.

Usage

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

/**
 * Register wrapper.//www  .  ja va2s. c o  m
 */
private void registerWrapper(ObjectName objectName) throws Exception {

    // 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 wrapperName = objectName.getKeyProperty("name");
    String name = objectName.getKeyProperty("WebModule");

    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.registerWrapper", wrapperName, contextName));

    String[] mappings = (String[]) mBeanServer.invoke(objectName, "findMappings", null, null);
    Object wrapper = mBeanServer.invoke(objectName, "findMappingObject", null, null);

    for (int i = 0; i < mappings.length; i++) {
        mapper.addWrapper(hostName, contextName, mappings[i], wrapper);
    }

}

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 www.  j  a v  a2s .  c om*/
 *
 * @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:io.fabric8.mq.controller.coordination.KubernetesControl.java

private BrokerOverview populateDestinations(J4pClient client, ObjectName root,
        BrokerDestinationOverviewImpl.Type type, BrokerOverview brokerOverview) {

    try {/*from  ww  w  .jav  a  2 s . c o m*/
        Hashtable<String, String> props = root.getKeyPropertyList();
        props.put("destinationType", type == BrokerDestinationOverviewImpl.Type.QUEUE ? "Queue" : "Topic");
        props.put("destinationName", "*");
        String objectName = root.getDomain() + ":" + Utils.getOrderedProperties(props);

        J4pResponse<J4pReadRequest> response = client
                .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 == BrokerDestinationOverviewImpl.Type.QUEUE
                        ? new ActiveMQQueue(name)
                        : new ActiveMQTopic(name);
                BrokerDestinationOverviewImpl brokerDestinationOverviewImpl = new BrokerDestinationOverviewImpl(
                        destination);
                brokerDestinationOverviewImpl.setNumberOfConsumers(Integer.parseInt(consumerCount));
                brokerDestinationOverviewImpl.setNumberOfProducers(Integer.parseInt(producerCount));
                brokerDestinationOverviewImpl.setQueueDepth(Integer.parseInt(queueSize));
                brokerOverview.addDestinationStatistics(brokerDestinationOverviewImpl);
            }
        }
    } catch (Exception ex) {
        // Destinations don't exist yet on the broker
        LOG.debug("populateDestinations failed", ex);
    }
    return brokerOverview;
}

From source file:org.apache.webapp.admin.context.SaveContextAction.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  a v a2  s. c om
 */
public void addToTreeControlNode(ObjectName oname, String containerName, String parentName,
        MessageResources resources, HttpSession session) throws Exception {

    String domain = oname.getDomain();
    TreeControl control = (TreeControl) session.getAttribute("treeControlTest");
    if (control != null) {
        TreeControlNode parentNode = control.findNode(parentName);
        if (parentNode != null) {
            String type = "Context";
            String path = "";
            String host = "";
            String name = oname.getKeyProperty("name");
            if ((name != null) && (name.length() > 0)) {
                name = name.substring(2);
                int i = name.indexOf("/");
                host = name.substring(0, i);
                path = name.substring(i);
            }
            String nodeLabel = "Context (" + path + ")";
            String encodedName = URLEncoder.encode(oname.toString());
            TreeControlNode childNode = new TreeControlNode(oname.toString(), "Context.gif", nodeLabel,
                    "EditContext.do?select=" + encodedName, "content", true, domain);
            parentNode.addChild(childNode);

            // FIXME - force a redisplay
            TreeControlNode subtree = new TreeControlNode("Context Resource Administration " + containerName,
                    "folder_16_pad.gif", resources.getMessage("resources.treeBuilder.subtreeNode"), null,
                    "content", true, domain);
            childNode.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) + "&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) + "&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) + "&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) + "&forward="
                            + URLEncoder.encode("EnvEntries List Setup"),
                    "content", false, domain);
            subtree.addChild(datasources);
            subtree.addChild(mailsessions);
            subtree.addChild(resourcelinks);
            subtree.addChild(envs);
        } else {
            getServlet().log("Cannot find parent node '" + parentName + "'");
        }
    } else {
        getServlet().log("Cannot find TreeControlNode!");
    }
}

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

/**
 * Unregister context.//from ww w .  j  a  va  2  s  .  c  om
 */
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:org.apache.coyote.tomcat5.MapperListener.java

/**
 * Register context./* w w w. j a  v  a  2s  .  c  o m*/
 */
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:org.apache.catalina.logger.LoggerBase.java

public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
    oname = name;/*ww w.jav a2s  .c om*/
    mserver = server;
    // FIXME null pointer exception 
    if (name == null) {
        return null;
    }
    domain = name.getDomain();
    host = name.getKeyProperty("host");
    path = name.getKeyProperty("path");
    if (container == null) {
        // Register with the parent
        try {
            ObjectName cname = null;
            if (host == null) {
                // global
                cname = new ObjectName(domain + ":type=Engine");
            } else if (path == null) {
                cname = new ObjectName(domain + ":type=Host,host=" + host);
            } else {
                cname = new ObjectName(domain + ":j2eeType=WebModule,name=//" + host + "/" + path);
            }
            log.debug("Register with " + cname);
            mserver.invoke(cname, "setLogger", new Object[] { this },
                    new String[] { "org.apache.catalina.Logger" });
        } catch (Exception e) {
            e.printStackTrace(); //To change body of catch statement use Options | File Templates.
        }
    }

    return name;
}

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

/**
 * Stop all the connectors//w w  w  . ja  v  a2 s  . c o m
 * 
 * @throws JMException
 * @throws LifecycleException
 */
private void stopAllConnectors() throws JMException, LifecycleException {
    ObjectName oname = new ObjectName("*:type=Service,*");
    Set services = server.queryMBeans(oname, null);
    Iterator iter = services.iterator();
    while (iter.hasNext()) {
        ObjectInstance oi = (ObjectInstance) iter.next();
        ObjectName on = oi.getObjectName();
        //Ignore jboss.web:*
        if (this.catalinaDomain.equals(on.getDomain()))
            continue;
        String key = on.getKeyProperty("serviceName");
        if (key != null) {
            Connector[] connectors = (Connector[]) server.invoke(on, "findConnectors", new Object[0],
                    new String[0]);
            for (int n = 0; n < connectors.length; n++) {
                Lifecycle lc = (Lifecycle) connectors[n];
                lc.stop();
            }
        }
    }
}

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

/**
 * Start all the connectors/*from  w  w w.  j a v  a  2  s .c om*/
 * 
 * @throws JMException
 * @throws LifecycleException
 */
private void startAllConnectors() throws JMException, LifecycleException {
    /**
     * Not able to query the Catalina server for the services that it has
     * registered. A usuable solution is to query the MBean server for the
     * tomcat services.
     * http://www.jboss.com/index.html?module=bb&op=viewtopic&t=75353
     */
    ObjectName oname = new ObjectName("*:type=Service,*");
    Set services = server.queryMBeans(oname, null);
    Iterator iter = services.iterator();
    while (iter.hasNext()) {
        ObjectInstance oi = (ObjectInstance) iter.next();
        ObjectName on = oi.getObjectName();
        //Ignore jboss.web:*
        if (this.catalinaDomain.equals(on.getDomain()))
            continue;
        String key = on.getKeyProperty("serviceName");
        if (key != null) {
            Connector[] connectors = (Connector[]) server.invoke(on, "findConnectors", new Object[0],
                    new String[0]);
            for (int n = 0; n < connectors.length; n++) {
                Lifecycle lc = (Lifecycle) connectors[n];
                lc.start();
            }
        }
    }
}

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;
            }//w ww . j ava  2  s  . co 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;
}