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:be.fgov.kszbcss.rhq.websphere.component.server.WebSphereServerDiscoveryComponent.java

public DiscoveredResourceDetails discoverResource(Configuration pluginConfiguration,
        ResourceDiscoveryContext<ResourceComponent<?>> discoveryContext)
        throws InvalidPluginConfigurationException {
    ObjectName serverBeanName;
    try {/* w ww  .ja v  a2  s.  c  om*/
        AdminClient adminClient = new SecureAdminClientProvider(
                new ConfigurationBasedProcessLocator(pluginConfiguration)).createAdminClient();
        serverBeanName = adminClient.getServerMBean();
    } catch (ConnectorException ex) {
        throw new InvalidPluginConfigurationException("Unable to connect to server", ex);
    }
    String cell = serverBeanName.getKeyProperty("cell");
    String node = serverBeanName.getKeyProperty("node");
    String process = serverBeanName.getKeyProperty("process");
    String processType = serverBeanName.getKeyProperty("processType");
    boolean unmanaged;
    if (processType.equals("ManagedProcess")) {
        unmanaged = false;
    } else if (processType.equals("UnManagedProcess")) {
        unmanaged = true;
    } else {
        throw new InvalidPluginConfigurationException("Unsupported process type " + processType);
    }
    pluginConfiguration.getSimple("unmanaged").setBooleanValue(unmanaged);
    return new DiscoveredResourceDetails(discoveryContext.getResourceType(), cell + "/" + node + "/" + process,
            process, null, process + " (cell " + cell + ", node " + node + ")", pluginConfiguration, null);
}

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;
            }/*ww  w. ja  v a  2s.  c o  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;
}

From source file:org.cloudfoundry.identity.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 = VarzStringUtils.camelToUnderscore(type);
            objects = getMap(objects, type);
        }/* ww w  .  j  av a  2 s  .  c  om*/

        String key = name.getKeyProperty("name");
        if (key != null) {
            key = VarzStringUtils.camelToUnderscore(key);
            objects = getMap(objects, key);
        }

        for (String property : name.getKeyPropertyList().keySet()) {
            if (property.equals("type") || property.equals("name")) {
                continue;
            }
            key = VarzStringUtils.camelToUnderscore(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:com.groupon.odo.proxylib.BackupService.java

/**
 * Get a list of strings(scheme + host + port) that the specified connector is running on
 *
 * @param name/*from  w w w .  j av a 2  s  . c  om*/
 * @return
 */
private ArrayList<String> getConnectorStrings(String name) {
    ArrayList<String> connectorStrings = new ArrayList<String>();

    try {
        MBeanServer mbeanServer = getServerForName(name);
        Set<ObjectName> objs = mbeanServer.queryNames(new ObjectName("*:type=Connector,*"), null);
        String hostname = InetAddress.getLocalHost().getHostName();
        InetAddress[] addresses = InetAddress.getAllByName(hostname);

        for (Iterator<ObjectName> i = objs.iterator(); i.hasNext();) {
            ObjectName obj = i.next();
            String scheme = mbeanServer.getAttribute(obj, "scheme").toString();
            String port = obj.getKeyProperty("port");
            connectorStrings.add(scheme + "://localhost:" + port);
            logger.info("Adding: {}", scheme + "://localhost:" + port);
        }
    } catch (Exception e) {
    }

    return connectorStrings;
}

From source file:org.fluentd.jvmwatcher.proxy.JvmClientProxy.java

/**
 * @return//from   w w w.ja v  a 2 s. co  m
 * @throws IOException
 */
public synchronized Collection<GarbageCollectorMXBean> getGarbageCollectorMXBeans() throws IOException {
    if (this.garbageCollectorMBeanList_ == null) {
        ObjectName gcName = null;

        try {
            gcName = new ObjectName(GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",*");
        } catch (MalformedObjectNameException ex) {
            log.error("GarbageCollectorMXBean get error.", ex);
            return null;
        }

        Set<ObjectName> objNameSet = this.server_.queryNames(gcName, null);

        if (objNameSet != null) {
            Iterator<ObjectName> iterator = objNameSet.iterator();
            this.garbageCollectorMBeanList_ = new ArrayList<GarbageCollectorMXBean>();

            while (iterator.hasNext()) {
                ObjectName objName = iterator.next();
                String name = GARBAGE_COLLECTOR_MXBEAN_DOMAIN_TYPE + ",name=" + objName.getKeyProperty("name");

                GarbageCollectorMXBean mBean = newPlatformMXBeanProxy(this.server_, name,
                        GarbageCollectorMXBean.class);
                this.garbageCollectorMBeanList_.add(mBean);
            }
        }
    }

    return this.garbageCollectorMBeanList_;
}

From source file:org.apache.catalina.logger.LoggerBase.java

public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception {
    oname = name;/*from   w w w. ja  va  2s. com*/
    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

public void stopService() throws Exception {

    String objectNameS = catalinaDomain + ":type=server";
    ObjectName objectName = new ObjectName(objectNameS);

    server.invoke(objectName, "stop", new Object[] {}, new String[] {});

    server.invoke(objectName, "destroy", new Object[] {}, new String[] {});

    server.unregisterMBean(objectName);/* w ww.  j ava  2  s  .  c  om*/

    MBeanServer server2 = server;

    // deregister with MainDeployer
    mainDeployer.removeDeployer(thisProxy);

    // Unregister any remaining jboss.web or Catalina MBeans
    ObjectName queryObjectName = new ObjectName(catalinaDomain + ":*");
    Iterator iterator = server2.queryMBeans(queryObjectName, null).iterator();
    while (iterator.hasNext()) {
        ObjectInstance oi = (ObjectInstance) iterator.next();
        ObjectName toRemove = oi.getObjectName();
        // Exception: Don't unregister the service right now
        if (!"WebServer".equals(toRemove.getKeyProperty("service"))) {
            if (server2.isRegistered(toRemove)) {
                server2.unregisterMBean(toRemove);
            }
        }
    }
    queryObjectName = new ObjectName("Catalina:*");
    iterator = server2.queryMBeans(queryObjectName, null).iterator();
    while (iterator.hasNext()) {
        ObjectInstance oi = (ObjectInstance) iterator.next();
        ObjectName name = oi.getObjectName();
        server2.unregisterMBean(name);
    }

}

From source file:com.spotify.reaper.cassandra.JmxProxy.java

@Override
public Map.Entry<String, ColumnFamilyStoreMBean> next() {
    ObjectName objectName = resIter.next();
    String keyspaceName = objectName.getKeyProperty("keyspace");
    ColumnFamilyStoreMBean cfsProxy = JMX.newMBeanProxy(mbeanServerConn, objectName,
            ColumnFamilyStoreMBean.class);
    return new AbstractMap.SimpleImmutableEntry<>(keyspaceName, cfsProxy);
}

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

public void startService() throws Exception {

    System.setProperty("catalina.ext.dirs",
            (System.getProperty("jboss.server.home.dir") + File.separator + "lib"));

    String objectNameS = catalinaDomain + ":type=server";
    ObjectName objectName = new ObjectName(objectNameS);

    // Set the modeler Registry MBeanServer to the that of the tomcat service
    Registry.getRegistry().setMBeanServer(server);

    server.createMBean("org.apache.commons.modeler.BaseModelMBean", objectName,
            new Object[] { "org.apache.catalina.startup.Catalina" }, new String[] { "java.lang.String" });

    server.setAttribute(objectName, new Attribute("catalinaHome", System.getProperty("jboss.server.home.dir")));
    server.setAttribute(objectName, new Attribute("configFile", serverConfigFile));
    server.setAttribute(objectName, new Attribute("useNaming", new Boolean(false)));
    server.setAttribute(objectName, new Attribute("useShutdownHook", new Boolean(false)));
    server.setAttribute(objectName, new Attribute("await", new Boolean(false)));
    server.setAttribute(objectName, new Attribute("redirectStreams", new Boolean(false)));

    server.invoke(objectName, "create", new Object[] {}, new String[] {});

    server.invoke(objectName, "start", new Object[] {}, new String[] {});

    // Configure any SingleSignOn valves      

    ObjectName ssoQuery = new ObjectName("*:type=Valve,*");
    Iterator iterator = server.queryMBeans(ssoQuery, null).iterator();
    while (iterator.hasNext()) {
        ObjectName ssoObjectName = ((ObjectInstance) iterator.next()).getObjectName();
        String name = ssoObjectName.getKeyProperty("name");

        /* Ensure that the SingleSignOn valve requires that each
           request be reauthenticated to the security mgr. Should not
           be neccessary now that we cache the principal in the session.
        if ((name != null) && (name.indexOf("SingleSignOn") >= 0))
        {//from  w  w w  .j  av  a2s  .c om
           log.info("Turning on reauthentication of each request on " +
             ssoObjectName);
           server.setAttribute(ssoObjectName, new Attribute
              ("requireReauthentication", Boolean.TRUE));
        }
        */

        // If the valve is a ClusteredSingleSignOn and we have a shared
        // TreeCache configured, configure the valve to use the shared one
        if (cacheName != null && "ClusteredSingleSignOn".equals(name)) {
            String tcName = (String) server.getAttribute(ssoObjectName, "treeCacheName");
            tcName = (tcName != null ? tcName : DEFAULT_CACHE_NAME);
            ObjectName ssoCacheName = new ObjectName(tcName);
            // Only override if the valve's cacheName property was not
            // explicitly set in server.xml to a non-default value
            if (ssoCacheName.equals(new ObjectName(DEFAULT_CACHE_NAME))) {
                log.info("Setting the cache name to " + cacheName + " on " + ssoObjectName);
                server.setAttribute(ssoObjectName, new Attribute("treeCacheName", cacheName));
            }
        }
    }

    // Register the web container JACC PolicyContextHandlers
    HttpServletRequestPolicyContextHandler handler = new HttpServletRequestPolicyContextHandler();
    PolicyContext.registerHandler(HttpServletRequestPolicyContextHandler.WEB_REQUEST_KEY, handler, true);

    // The ServiceController used to control web app startup dependencies
    serviceController = (ServiceControllerMBean) MBeanProxyExt.create(ServiceControllerMBean.class,
            ServiceControllerMBean.OBJECT_NAME, server);

    // make a proxy to myself, so that calls from the MainDeployer
    // can go through the MBeanServer, so interceptors can be added
    thisProxy = (SubDeployerExt) MBeanProxyExt.create(SubDeployerExt.class, super.getServiceName(),
            super.getServer());

    // Register with the main deployer
    mainDeployer.addDeployer(thisProxy);

    // If we are hot-deployed *after* the overall server is started
    // we'll never receive Server.START_NOTIFICATION_TYPE, so check
    // with the Server and start the connectors immediately, if this is the case.
    // Otherwise register to receive the server start-up notification.
    Boolean started = (Boolean) server.getAttribute(ServerImplMBean.OBJECT_NAME, "Started");
    if (started.booleanValue() == true) {
        log.debug("Server '" + ServerImplMBean.OBJECT_NAME + "' already started, starting connectors now");

        startConnectors();
    } else {
        // Register for notification of the overall server startup
        log.debug("Server '" + ServerImplMBean.OBJECT_NAME
                + "' not started, registering for start-up notification");

        server.addNotificationListener(ServerImplMBean.OBJECT_NAME, this, null, null);
    }
}

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

/**
 * Stop all the connectors/*from  w  ww . ja v a2s  .  co  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();
            }
        }
    }
}