Example usage for javax.management InstanceNotFoundException getMessage

List of usage examples for javax.management InstanceNotFoundException getMessage

Introduction

In this page you can find the example usage for javax.management InstanceNotFoundException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.wso2.carbon.as.monitoring.collector.jmx.clients.MBeanClient.java

/**
 * Read the possible attribute values from the MBean
 *
 * @return List of Result objects//from w ww . java  2  s . com
 */
public List<Result> readPossibleAttributeValues() throws MalformedObjectNameException {
    ObjectName name = new ObjectName(getObjectNameQuery());
    Set<ObjectInstance> instances = server.queryMBeans(name, null);

    List<Result> results = new ArrayList<Result>();
    for (ObjectInstance instance : instances) {
        ObjectName objectName = instance.getObjectName();

        AttributeList attributes = null;
        try {
            attributes = server.getAttributes(objectName, getAttributeNames());
        } catch (InstanceNotFoundException ignored) {
            // Here we put best-effort to grab any attributes.
            // Missing objects are ignored. We need whatever possible.
            if (LOG.isDebugEnabled()) {
                LOG.debug(objectName + " MBean not found : " + ignored.getMessage(), ignored);
            }
        } catch (ReflectionException ignored) {
            // Here we put best-effort to grab any attributes.
            // erroneous attributes are ignored. We need whatever possible.
            if (LOG.isDebugEnabled()) {
                LOG.debug("Exception occurred while reading the attributes from " + objectName, ignored);
            }
        }

        if (attributes != null) {
            attributes.addAll(getPropertiesFromKey(objectName));
        }

        Result result = new Result(getCorrelationKey(objectName), attributes);
        results.add(result);
    }

    return results;
}

From source file:com.tribloom.module.JmxClient.java

@Override
protected Map<String, Object> executeImpl(WebScriptRequest req, Status status, Cache cache) {
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("connectionSuccess", true);
    model.put("time", System.currentTimeMillis());
    try {/* w  ww . jav a 2 s.c  o m*/
        // Create an RMI connector client and
        // connect it to the RMI connector server
        //
        echo("\nCreate an RMI connector client and " + "connect it to the RMI connector server");
        JMXServiceURL url = new JMXServiceURL(
                "service:jmx:rmi://ignored/jndi/rmi://localhost:50500/alfresco/jmxrmi");
        Map<String, Object> env = new HashMap<String, Object>();
        String[] creds = { "controlRole", "change_asap" };
        env.put(JMXConnector.CREDENTIALS, creds);
        JMXConnector jmxc = JMXConnectorFactory.connect(url, env);

        // Get an MBeanServerConnection
        //
        echo("\nGet an MBeanServerConnection");
        MBeanServerConnection mbsc = jmxc.getMBeanServerConnection();

        ObjectName memory = new ObjectName("java.lang:type=Memory");
        CompositeData heapMemUsage = (CompositeData) mbsc.getAttribute(memory, "HeapMemoryUsage");
        addCompositeData(model, heapMemUsage, "heapMemoryUsage");
        CompositeData nonHeapMemUsage = (CompositeData) mbsc.getAttribute(memory, "NonHeapMemoryUsage");
        addCompositeData(model, nonHeapMemUsage, "nonHeapMemoryUsage");

        ObjectName operatingSystem = new ObjectName("java.lang:type=OperatingSystem");
        model.put("openFileDescriptorCount", mbsc.getAttribute(operatingSystem, "OpenFileDescriptorCount"));
        model.put("maxFileDescriptorCount", mbsc.getAttribute(operatingSystem, "MaxFileDescriptorCount"));
        model.put("committedVirtualMemorySize",
                mbsc.getAttribute(operatingSystem, "CommittedVirtualMemorySize"));
        model.put("totalSwapSpaceSize", mbsc.getAttribute(operatingSystem, "TotalSwapSpaceSize"));
        model.put("freeSwapSpaceSize", mbsc.getAttribute(operatingSystem, "FreeSwapSpaceSize"));
        model.put("processCpuTime", mbsc.getAttribute(operatingSystem, "ProcessCpuTime"));
        model.put("freePhysicalMemorySize", mbsc.getAttribute(operatingSystem, "FreePhysicalMemorySize"));
        model.put("totalPhysicalMemorySize", mbsc.getAttribute(operatingSystem, "TotalPhysicalMemorySize"));
        model.put("operatingSystemName", mbsc.getAttribute(operatingSystem, "Name"));
        model.put("operatingSystemVersion", mbsc.getAttribute(operatingSystem, "Version"));
        model.put("operatingSystemArch", mbsc.getAttribute(operatingSystem, "Arch"));
        model.put("availableProcessors", mbsc.getAttribute(operatingSystem, "AvailableProcessors"));
        model.put("systemLoadAverage", mbsc.getAttribute(operatingSystem, "SystemLoadAverage"));

        try {
            ObjectName parNewGarbageCollector = new ObjectName("java.lang:type=GarbageCollector,name=ParNew");
            echo("\nparNewGarbageCollector = " + parNewGarbageCollector);
            CompositeData parNewLastGcInfo = (CompositeData) mbsc.getAttribute(parNewGarbageCollector,
                    "LastGcInfo");
            addCompositeData(model, parNewLastGcInfo, "parNewLastGcInfo");
        } catch (InstanceNotFoundException ex) {
            // No Garbage Collection has occurred yet
            echo("No Garbage Collection found: " + ex.getMessage());
        }
        try {
            ObjectName concurrentGarbageCollector = new ObjectName(
                    "java.lang:type=GarbageCollector,name=ConcurrentMarkSweep");
            echo("\nconcurrentGarbageCollector = " + concurrentGarbageCollector);
            CompositeData concurrentGarbageCollectorLastGcInfo = (CompositeData) mbsc
                    .getAttribute(concurrentGarbageCollector, "LastGcInfo");
            addCompositeData(model, concurrentGarbageCollectorLastGcInfo, "concurrentMarkSweepLastGcInfo");
        } catch (InstanceNotFoundException ex) {
            // No Garbage Collection has occurred yet
            echo("No Garbage Collection found: " + ex.getMessage());
        }

        ObjectName classLoading = new ObjectName("java.lang:type=ClassLoading");
        model.put("classLoadingLoadedClassCount", mbsc.getAttribute(classLoading, "LoadedClassCount"));
        model.put("classLoadingUnloadedClassCount", mbsc.getAttribute(classLoading, "UnloadedClassCount"));
        model.put("classLoadingTotalLoadedClassCount",
                mbsc.getAttribute(classLoading, "TotalLoadedClassCount"));

        ObjectName runtime = new ObjectName("java.lang:type=Runtime");
        model.put("runtimeName", mbsc.getAttribute(runtime, "Name"));
        model.put("runtimeClassPath", mbsc.getAttribute(runtime, "ClassPath"));

        // TODO: Tabular type...
        Object sysProps = mbsc.getAttribute(runtime, "SystemProperties");
        echo("\nsysProps = " + sysProps);

        model.put("runtimeStartTime", mbsc.getAttribute(runtime, "StartTime"));
        model.put("runtimeVmName", mbsc.getAttribute(runtime, "VmName"));
        model.put("runtimeVmVendor", mbsc.getAttribute(runtime, "VmVendor"));
        model.put("runtimeVmVersion", mbsc.getAttribute(runtime, "VmVersion"));
        model.put("runtimeLibraryPath", mbsc.getAttribute(runtime, "LibraryPath"));
        model.put("runtimeBootClassPath", mbsc.getAttribute(runtime, "BootClassPath"));
        model.put("runtimeManagementSpecVersion", mbsc.getAttribute(runtime, "ManagementSpecVersion"));
        model.put("runtimeSpecName", mbsc.getAttribute(runtime, "SpecName"));
        model.put("runtimeSpecVendor", mbsc.getAttribute(runtime, "SpecVendor"));
        model.put("runtimeSpecVersion", mbsc.getAttribute(runtime, "SpecVersion"));
        model.put("runtimeInputArguments", mbsc.getAttribute(runtime, "InputArguments")); // TODO: Array...
        model.put("runtimeUptime", mbsc.getAttribute(runtime, "Uptime"));

        try {
            ObjectName memoryPool = new ObjectName("java.lang:type=MemoryPool");
            model.put("memoryPoolName", mbsc.getAttribute(memoryPool, "Name"));
            model.put("memoryPoolType", mbsc.getAttribute(memoryPool, "Type"));
            CompositeData memoryPoolUsage = (CompositeData) mbsc.getAttribute(memoryPool, "Usage");
            addCompositeData(model, memoryPoolUsage, "memoryPoolUsage");
            CompositeData memoryPoolPeakUsage = (CompositeData) mbsc.getAttribute(memoryPool, "PeakUsage");
            addCompositeData(model, memoryPoolPeakUsage, "memoryPoolPeakUsage");
            model.put("memoryPoolMemoryManagerNames", mbsc.getAttribute(memoryPool, "MemoryManagerNames")); // Array of strings
            model.put("memoryPoolUsageThreshold", mbsc.getAttribute(memoryPool, "UsageThreshold"));
            model.put("memoryPoolUsageThresholdExceeded",
                    mbsc.getAttribute(memoryPool, "UsageThresholdExceeded"));
            model.put("memoryPoolUsageThresholdCount", mbsc.getAttribute(memoryPool, "UsageThresholdCount"));
            model.put("memoryPoolUsageThresholdSupported",
                    mbsc.getAttribute(memoryPool, "UsageThresholdSupported"));
            model.put("memoryPoolCollectionUsageThreshold",
                    mbsc.getAttribute(memoryPool, "CollectionUsageThreshold"));
            model.put("memoryPoolCollectionUsageThresholdExceeded",
                    mbsc.getAttribute(memoryPool, "CollectionUsageThresholdExceeded"));
            model.put("memoryPoolCollectionUsageThresholdCount",
                    mbsc.getAttribute(memoryPool, "CollectionUsageThresholdCount"));
            CompositeData collectionUsage = (CompositeData) mbsc.getAttribute(memoryPool, "CollectionUsage");
            addCompositeData(model, collectionUsage, "memoryPoolCollectionUsage");
            model.put("memoryPoolCollectionUsageThresholdSupported",
                    mbsc.getAttribute(memoryPool, "CollectionUsageThresholdSupported"));

        } catch (InstanceNotFoundException ex) {
            // Memory pool not initialized yet

        }

        echo("\nClose the connection to the server");
        jmxc.close();
        echo("\nBye! Bye!");
    } catch (Exception ex) {
        ex.printStackTrace();
        model.put("connectionSuccess", false);
        model.put("exception", ex.getMessage());
    }
    return model;
}

From source file:net.nicoll.boot.daemon.SpringApplicationAdminClient.java

/**
 * Check if the spring application managed by this instance is ready. Returns
 * {@code false} if the mbean is not yet deployed so this method should be repeatedly
 * called until a timeout is reached.//from   w  w w .  j a  v a  2 s  . com
 * @return {@code true} if the application is ready to service requests
 * @throws org.springframework.jmx.JmxException if the JMX service could not be contacted
 */
public boolean isReady() {
    try {
        return (Boolean) this.connection.getAttribute(this.objectName, "Ready");
    } catch (InstanceNotFoundException ex) {
        return false; // Instance not available yet
    } catch (AttributeNotFoundException ex) {
        throw new IllegalStateException("Unexpected: attribute 'Ready' not available", ex);
    } catch (ReflectionException ex) {
        throw new JmxException("Failed to retrieve Ready attribute", ex.getCause());
    } catch (MBeanException ex) {
        throw new JmxException(ex.getMessage(), ex);
    } catch (IOException ex) {
        throw new JmxException(ex.getMessage(), ex);
    }
}

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

private static void cleanupResource(ManagedResource resource) {
    synchronized (MBeanUtil.managedResources) {
        MBeanUtil.managedResources.remove(resource.getObjectName());
    }/*from   w ww  . j  av a2  s .  co  m*/
    resource.cleanupResource();

    // get the notifications for the specified client...
    Map<RefreshNotificationType, Integer> notifications = null;
    synchronized (refreshClients) {
        notifications = (Map<RefreshNotificationType, Integer>) refreshClients.remove(resource);
    }

    // never registered before if null ...
    // Also as of current, there is ever only 1 Notification type per
    // MBean, so we do need need a while loop here
    if (notifications != null) {

        // Fix for findbugs reported inefficiency with keySet().
        Set<Map.Entry<RefreshNotificationType, Integer>> entries = notifications.entrySet();

        for (Map.Entry<RefreshNotificationType, Integer> e : entries) {
            Integer timerNotificationId = e.getValue();
            if (null != timerNotificationId) {
                try {
                    // found one, so let's remove it...
                    refreshTimer.removeNotification(timerNotificationId);
                } catch (InstanceNotFoundException xptn) {
                    // that's ok cause we just wanted to remove it anyway
                    logStackTrace(Level.DEBUG, xptn);
                }
            }
        }

        try {
            if (mbeanServer != null && mbeanServer.isRegistered(refreshTimerObjectName)) {
                // remove client as a listener with MBeanServer...
                mbeanServer.removeNotificationListener(refreshTimerObjectName, // timer to listen to
                        (NotificationListener) resource // the NotificationListener object
                );
            }
        } catch (ListenerNotFoundException xptn) {
            // should not happen since we already checked refreshTimerObjectName
            logStackTrace(Level.WARN, null, xptn.getMessage());
        } catch (InstanceNotFoundException xptn) {
            // should not happen since we already checked refreshTimerObjectName
            logStackTrace(Level.WARN, null,
                    LocalizedStrings.MBeanUtil_WHILE_UNREGISTERING_COULDNT_FIND_MBEAN_WITH_OBJECTNAME_0
                            .toLocalizedString(new Object[] { refreshTimerObjectName }));
        }
    }
}

From source file:org.opennms.tools.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);//  w ww  .  ja  v a  2  s  .  com
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        for (String domainName : mBeanServerConnection.getDomains()) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.debug("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }

    return xmlJmxDatacollectionConfig;
}

From source file:org.opennms.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans,
        Map<String, String> dictionary) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans + "\n dictionary" + dictionary);
    nameCutter.setDictionary(dictionary);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);//  ww  w .j a v  a  2s.co  m
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        for (String domainName : mBeanServerConnection.getDomains()) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.debug("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }

    return xmlJmxDatacollectionConfig;
}

From source file:org.opennms.features.jmxconfiggenerator.jmxconfig.JmxDatacollectionConfiggenerator.java

public JmxDatacollectionConfig generateJmxConfigModel(MBeanServerConnection mBeanServerConnection,
        String serviceName, Boolean runStandardVmBeans, Boolean runWritableMBeans,
        Map<String, String> dictionary) {

    logger.debug("Startup values: \n serviceName: " + serviceName + "\n runStandardVmBeans: "
            + runStandardVmBeans + "\n runWritableMBeans: " + runWritableMBeans + "\n dictionary" + dictionary);
    nameCutter.setDictionary(dictionary);
    JmxDatacollectionConfig xmlJmxDatacollectionConfig = xmlObjectFactory.createJmxDatacollectionConfig();
    JmxCollection xmlJmxCollection = xmlObjectFactory.createJmxCollection();

    xmlJmxCollection.setName("JSR160-" + serviceName);
    xmlJmxCollection.setRrd(rrd);/*from  w w w . j  a  v a 2 s  .  c  om*/
    xmlJmxDatacollectionConfig.getJmxCollection().add(xmlJmxCollection);
    xmlJmxCollection.setMbeans(xmlObjectFactory.createMbeans());

    if (runStandardVmBeans) {
        ignores.clear();
    } else {
        ignores.addAll(standardVmBeans);
    }

    try {
        String[] domains = mBeanServerConnection.getDomains();
        logger.info("Found " + domains.length + " domains");
        logger.info("domains: " + Arrays.toString(domains));
        for (String domainName : domains) {

            // just domains that are relevant for the service
            if (!ignores.contains(domainName)) {
                logger.info("domain: " + domainName);

                // for all mBeans of the actual domain
                for (ObjectInstance jmxObjectInstance : mBeanServerConnection
                        .queryMBeans(new ObjectName(domainName + ":*"), null)) {
                    Mbean xmlMbean = xmlObjectFactory.createMbean();
                    xmlMbean.setObjectname(jmxObjectInstance.getObjectName().toString());
                    String typeAndOthers = StringUtils
                            .substringAfterLast(jmxObjectInstance.getObjectName().getCanonicalName(), "=");
                    xmlMbean.setName(domainName + "." + typeAndOthers);

                    logger.debug("\t" + jmxObjectInstance.getObjectName());

                    MBeanInfo jmxMbeanInfo;
                    try {
                        jmxMbeanInfo = mBeanServerConnection.getMBeanInfo(jmxObjectInstance.getObjectName());
                    } catch (InstanceNotFoundException e) {
                        logger.error("InstanceNotFoundException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (IntrospectionException e) {
                        logger.error("IntrospectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (ReflectionException e) {
                        logger.error("ReflectionException skipping MBean '{}' message: '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    } catch (Throwable e) {
                        logger.error(
                                "problem during remote call to get MBeanInfo for '{}' skipping this MBean. Message '{}'",
                                jmxObjectInstance.getObjectName(), e.getMessage());
                        continue;
                    }

                    logger.debug("--- Attributes for " + jmxObjectInstance.getObjectName());

                    for (MBeanAttributeInfo jmxBeanAttributeInfo : jmxMbeanInfo.getAttributes()) {

                        // process just readable mbeans
                        if (jmxBeanAttributeInfo.isReadable()) {
                            // precess writable mbeans if run writable
                            // mbeans is set
                            if (!jmxBeanAttributeInfo.isWritable() || runWritableMBeans) {

                                logger.debug("Check mBean: '{}', attribute: '{}'",
                                        jmxObjectInstance.getObjectName().toString(),
                                        jmxBeanAttributeInfo.getName());
                                logger.debug("isWritable: '{}', type: '{}'", jmxBeanAttributeInfo.isWritable(),
                                        jmxBeanAttributeInfo.getType());

                                // check for CompositeData
                                if ("javax.management.openmbean.CompositeData"
                                        .equals(jmxBeanAttributeInfo.getType())) {
                                    logger.error("actual mBean: '{}'", jmxObjectInstance.getObjectName());
                                    CompAttrib compAttrib = createCompAttrib(mBeanServerConnection,
                                            jmxObjectInstance, jmxBeanAttributeInfo);
                                    if (compAttrib != null) {
                                        logger.debug("xmlMbean got CompAttrib");
                                        xmlMbean.getCompAttrib().add(compAttrib);
                                    }
                                }

                                if (numbers.contains(jmxBeanAttributeInfo.getType())) {
                                    Attrib xmlJmxAttribute = createAttr(jmxBeanAttributeInfo);
                                    logger.debug("Added MBean: '{}' Added attribute: '{}'",
                                            xmlMbean.getObjectname(),
                                            xmlJmxAttribute.getName() + " as " + xmlJmxAttribute.getAlias());
                                    xmlMbean.getAttrib().add(xmlJmxAttribute);
                                }
                            }
                        }
                    }

                    if (xmlMbean.getAttrib().size() > 0 || xmlMbean.getCompAttrib().size() > 0) {
                        xmlJmxCollection.getMbeans().getMbean().add(xmlMbean);
                    } else {
                        logger.debug("mbean: " + xmlMbean.getName() + " has no relavant attributes.");
                    }
                }
            } else {
                logger.debug("ignored: " + domainName);
            }
        }

    } catch (MalformedObjectNameException e) {
        logger.error("MalformedObjectNameException '{}'", e.getMessage());
    } catch (IOException e) {
        logger.error("IOException '{}'", e.getMessage());
    }
    logger.debug("finish collection!");
    return xmlJmxDatacollectionConfig;
}

From source file:org.jolokia.handler.list.MBeanInfoData.java

/**
 * Add an exception which occurred during extraction of an {@link MBeanInfo} for
 * a certain {@link ObjectName} to this map.
 *
 * @param pName MBean name for which the error occurred
 * @param pExp exception occurred/*from w  ww .  j  a  v  a 2 s  .c om*/
 * @throws IllegalStateException if this method decides to rethrow the exception
 */
public void handleException(ObjectName pName, InstanceNotFoundException pExp) throws InstanceNotFoundException {
    // This happen happens for JBoss 7.1 in some cases (i.e. ResourceAdapterModule)
    if (pathStack.size() == 0) {
        addException(pName, pExp);
    } else {
        throw new InstanceNotFoundException(
                "InstanceNotFoundException for MBean " + pName + " (" + pExp.getMessage() + ")");
    }
}

From source file:com.cisco.oss.foundation.monitoring.RMIMonitoringAgent.java

private void unregisterServices() {
    try {/*w w  w  .  j a va 2  s  . c  om*/
        if (this.servicesObjectName != null)
            mbs.unregisterMBean(this.servicesObjectName);
    } catch (InstanceNotFoundException e) {
        LOGGER.trace("Failed to unregister services" + e.getMessage());
    } catch (MBeanRegistrationException e) {
        LOGGER.trace("Failed to unregister services" + e.getMessage());
    }
}

From source file:com.cisco.oss.foundation.monitoring.RMIMonitoringAgent.java

private void unregisterComponentInfo() {
    try {//from w  w  w  .  j  av a2  s .c o m
        if (this.connetctionsObjectName != null)
            mbs.unregisterMBean(this.componentInfoObjectName);
    } catch (InstanceNotFoundException e) {
        LOGGER.trace("Failed to unregister ComponentInfo" + e.getMessage());
    } catch (MBeanRegistrationException e) {
        LOGGER.trace("Failed to unregister ComponentInfo" + e.getMessage());
    }
}