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:com.mtgi.jmx.export.naming.AppendNamingStrategyTest.java

@Test
public void testNamingStrategy() throws MalformedObjectNameException {

    MetadataNamingStrategy delegate = new MetadataNamingStrategy();
    delegate.setAttributeSource(new AnnotationJmxAttributeSource());

    AppendNamingStrategy ans = new AppendNamingStrategy();
    ans.setDelegate(delegate);//from   w w  w.j  a v  a 2 s.com
    ans.setDomain("testApplication");

    ObjectName name = ans.getObjectName(new XmlBehaviorEventPersisterImpl(), "testPersister");
    assertNotNull("name is constructed", name);
    assertEquals("name has been transformed correctly",
            "testApplication:package=com.mtgi.analytics,name=BeetLog", name.toString());
    assertEquals("package name quoted properly", "com.mtgi.analytics", name.getKeyProperty("package"));
}

From source file:org.hyperic.hq.product.jmx.ServiceTypeFactory.java

/**
 * Returns a ServiceType containing ONLY the properties needed at construction time (the ones that guarantee uniqueness)
 * @param productName The name of the product containing the service
 * @param serverType The name of the server containing the service
 * @param serviceInfo Info about the service
 * @param objectName The {@link ObjectName} of the discovered MBean representing the service instance
 * @return A ServiceType containing ONLY the properties needed at construction time (the ones that guarantee uniqueness)
 *//*www .  ja  v a2 s.co m*/
public ServiceType getServiceType(String productName, ServerTypeInfo serverType, ModelMBeanInfo serviceInfo,
        ObjectName objectName) {
    String serviceTypeName = objectName.getKeyProperty("type");
    final String subType = objectName.getKeyProperty("subtype");
    if (subType != null) {
        serviceTypeName = serviceTypeName + " " + subType;
    }
    try {
        Descriptor serviceDescriptor = serviceInfo.getMBeanDescriptor();
        if ("false".equals(serviceDescriptor.getFieldValue("export"))) {
            return null;
        }
        String serviceType = (String) serviceDescriptor.getFieldValue("typeName");
        if (serviceType != null) {
            serviceTypeName = serviceType;
        }
    } catch (Exception e) {
        log.warn("Error obtaining MBeanInfo descriptor field values.  Default values will be used.  Cause: "
                + e.getMessage());
    }
    return new ServiceType(serviceTypeName, productName, new ServiceTypeInfo(
            serverType.getName() + ' ' + serviceTypeName, serviceInfo.getDescription(), serverType));
}

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

private void discoverInit(MBeanServer mServer) throws Exception {

    // only exists on the admin server
    final String scope = "*:Type=ApplicationConfig,*";

    for (Iterator it = mServer.queryNames(new ObjectName(scope), null).iterator(); it.hasNext();) {
        ObjectName oName = (ObjectName) it.next();
        if (this.domain == null) {
            this.domain = oName.getDomain();
        }/*from   ww  w.j a v a  2 s  . c  o  m*/
        if (this.adminName == null) {
            this.adminName = oName.getKeyProperty("Location");
        }

        String name = oName.getKeyProperty("Name");

        // special case for console so we can control it
        if (name.equals("console")) {
            continue;
        }

        boolean isInternal = ((Boolean) mServer.getAttribute(oName, "InternalApp")).booleanValue();

        if (isInternal) {
            this.internalApps.put(name, Boolean.TRUE);
        }
    }
}

From source file:org.rhq.plugins.jbosscache.JBossCacheDiscoveryComponent.java

@Override
public Set<DiscoveredResourceDetails> discoverResources(ResourceDiscoveryContext<JMXComponent<?>> context) {

    ResourceContext parentCtx = context.getParentResourceContext();
    JMXComponent<JBossASServerComponent<?>> gparentComponent = (JMXComponent<JBossASServerComponent<?>>) parentCtx
            .getParentResourceComponent();

    Set<DiscoveredResourceDetails> discovered = super.performDiscovery(context.getDefaultPluginConfiguration(),
            gparentComponent, context.getResourceType(), false);

    Set<DiscoveredResourceDetails> results = new HashSet<DiscoveredResourceDetails>(discovered.size());

    // Normalize the base object names from the key
    for (DiscoveredResourceDetails detail : discovered) {
        boolean isTreeCache = false;
        String key = detail.getResourceKey();
        if (key.contains("treecache-interceptor="))
            isTreeCache = true;/*from   ww w .  j  a  va2s  .  co m*/

        try {
            ObjectName on = ObjectName.getInstance(key);
            key = on.getDomain();
            key += ":";
            Set<String> propKeys = on.getKeyPropertyList().keySet();
            for (String prop : propKeys) {
                if (!(prop.contains("cache"))) {
                    key += prop + "=" + on.getKeyProperty(prop);
                    key += ",";
                }
            }
            if (key.endsWith(","))
                key = key.substring(0, key.length() - 1);
            if (log.isDebugEnabled())
                log.debug("Translated " + detail.getResourceKey() + " to " + key);
            detail.setResourceKey(key);
            detail.setResourceName(key);
            String descr = "";
            if (isTreeCache)
                descr = "Tree";
            descr += "Cache at " + key;
            detail.setResourceDescription(descr);

            Configuration pluginConfiguration = detail.getPluginConfiguration();
            PropertySimple onProp = pluginConfiguration.getSimple("objectName");
            onProp.setStringValue(key);

            PropertySimple isTC = new PropertySimple("isTreeCache", isTreeCache);
            pluginConfiguration.put(isTC);

            results.add(detail);
        } catch (MalformedObjectNameException e) {
            log.warn("Invalid obectname : " + key);
        }
    }

    return results;
}

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

public synchronized List getThreadPools() throws Exception {

    if (!isInitialized()) {
        initialize();// w  w w .j  a v a 2s.co m
    }

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

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

    for (Iterator it = executorNames.iterator(); it.hasNext();) {
        ObjectName executorName = (ObjectName) it.next();

        ThreadPool threadPool = new ThreadPool();
        threadPool.setName(executorName.getKeyProperty("name"));
        threadPool.setMaxThreads(JmxTools.getIntAttr(server, executorName, "maxThreads"));
        threadPool.setMaxSpareThreads(JmxTools.getIntAttr(server, executorName, "largestPoolSize"));
        threadPool.setMinSpareThreads(JmxTools.getIntAttr(server, executorName, "minSpareThreads"));
        threadPool.setCurrentThreadsBusy(JmxTools.getIntAttr(server, executorName, "activeCount"));
        threadPool.setCurrentThreadCount(JmxTools.getIntAttr(server, executorName, "poolSize"));

        threadPools.add(threadPool);
    }

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

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

            ThreadPool threadPool = new ThreadPool();
            threadPool.setName(poolName.getKeyProperty("name"));
            threadPool.setMaxThreads(JmxTools.getIntAttr(server, poolName, "maxThreads"));

            if (JmxTools.hasAttribute(server, poolName, "maxSpareThreads")) {
                threadPool.setMaxSpareThreads(JmxTools.getIntAttr(server, poolName, "maxSpareThreads"));
                threadPool.setMinSpareThreads(JmxTools.getIntAttr(server, poolName, "minSpareThreads"));
            }

            threadPool.setCurrentThreadsBusy(JmxTools.getIntAttr(server, poolName, "currentThreadsBusy"));
            threadPool.setCurrentThreadCount(JmxTools.getIntAttr(server, poolName, "currentThreadCount"));

            // Tomcat 6.0.21+ will return -1 for maxThreads if the connector uses an executor for its threads.
            // In this case, don't add its ThreadPool to the results.
            if (threadPool.getMaxThreads() > -1) {
                threadPools.add(threadPool);
            }
        } catch (InstanceNotFoundException e) {
            logger.error("Failed to query entire thread pool " + threadPoolObjectName);
            logger.debug("  Stack trace:", e);
        }
    }
    return threadPools;
}

From source file:com.mtgi.jmx.export.naming.AppendNamingStrategyTest.java

@Test
public void testNewKey() throws MalformedObjectNameException {
    MetadataNamingStrategy delegate = new MetadataNamingStrategy();
    delegate.setAttributeSource(new AnnotationJmxAttributeSource());

    AppendNamingStrategy ans = new AppendNamingStrategy();
    ans.setDelegate(delegate);//from w w  w .j av  a2s.  c  o  m
    ans.setValue("testPersister");
    ans.setDomain("testApplication");

    ObjectName name = ans.getObjectName(new XmlBehaviorEventPersisterImpl(), "testPersister");
    assertNotNull("name is constructed", name);
    assertEquals("name has been transformed correctly",
            "testApplication:package=com.mtgi.analytics,group=BeetLog,name=testPersister", name.toString());
    assertEquals("package name quoted properly", "com.mtgi.analytics", name.getKeyProperty("package"));
}

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

/**
 * Unregister host.//from  w  w  w  . j  a va  2s  .  com
 */
private void unregisterHost(ObjectName objectName) throws Exception {
    String name = objectName.getKeyProperty("host");
    mapper.removeHost(name);
}

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

/**
 * Register host.// w  w  w  .  j  a v a2  s. c  o  m
 */
private void registerHost(ObjectName objectName) throws Exception {
    String name = objectName.getKeyProperty("host");
    if (name != null) {
        String[] aliases = (String[]) mBeanServer.invoke(objectName, "findAliases", null, null);
        mapper.addHost(name, aliases, objectName);
    }
}

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

public boolean getAttributes(MBeanServer mServer, ObjectName name, String[] attrNames) {

    if (name == null) {
        return false;
    }/*from w  ww  .  jav a  2  s . co  m*/
    if (attrNames.length == 0) {
        setName(name.getKeyProperty("Name"));
        return true;
    }

    AttributeList list;

    try {
        list = mServer.getAttributes(name, attrNames);
    } catch (InstanceNotFoundException e) {
        //given that the ObjectName is from queryNames
        //returned by the server this should not happen.
        //however, it is possible when nodes are not properly
        //configured.
        logAttrFailure(name, attrNames, e);
        return false;
    } catch (ReflectionException e) {
        //this should not happen either
        logAttrFailure(name, attrNames, e);
        return false;
    }

    if (list == null) {
        //only 6.1 seems to behave this way,
        //modern weblogics throw exceptions.
        return false;
    }

    for (int i = 0; i < list.size(); i++) {
        Attribute attr = (Attribute) list.get(i);
        Object obj = attr.getValue();
        if (obj != null) {
            this.attrs.put(attr.getName(), obj.toString());
        }
    }

    return true;
}

From source file:org.apache.geode.admin.jmx.internal.SystemMemberCacheJmxImpl.java

/**
 * Cleans up managed resources created for the region that was (created and) destroyed in a cache
 * represented by this Managed Resource.
 * /*  www.j ava 2s  . com*/
 * @param regionPath path of the region that got destroyed
 * @return a managed resource related to this region path
 */
public ManagedResource cleanupRegionResources(String regionPath) {
    ManagedResource cleaned = null;

    synchronized (this.managedRegionResourcesMap) {
        Set<Entry<String, SystemMemberRegionJmxImpl>> entries = managedRegionResourcesMap.entrySet();
        for (Iterator<Entry<String, SystemMemberRegionJmxImpl>> it = entries.iterator(); it.hasNext();) {
            Entry<String, SystemMemberRegionJmxImpl> entry = it.next();
            SystemMemberRegionJmxImpl managedResource = entry.getValue();
            ObjectName objName = managedResource.getObjectName();

            String pathProp = objName.getKeyProperty("path");
            if (pathProp != null && pathProp.equals(regionPath)) {
                cleaned = managedResource;
                it.remove();

                break;
            }
        }
    }

    return cleaned;
}