Example usage for javax.management MalformedObjectNameException getMessage

List of usage examples for javax.management MalformedObjectNameException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.sf.ehcache.management.ManagementService.java

/**
 * Stop the listener and free any resources.
 * Removes registered ObjectNames/*from www.  ja va2  s .co  m*/
 *
 * @throws net.sf.ehcache.CacheException - all exceptions are wrapped in CacheException
 */
public void dispose() throws CacheException {
    Set registeredObjectNames = null;

    try {
        //CacheManager MBean
        registeredObjectNames = mBeanServer.queryNames(CacheManager.createObjectName(backingCacheManager),
                null);
        //Other MBeans for this CacheManager
        registeredObjectNames.addAll(mBeanServer.queryNames(
                new ObjectName("net.sf.ehcache:*,CacheManager=" + backingCacheManager.toString()), null));
    } catch (MalformedObjectNameException e) {
        //this should not happen
        LOG.error("Error querying MBeanServer. Error was " + e.getMessage(), e);
    }
    for (Iterator iterator = registeredObjectNames.iterator(); iterator.hasNext();) {
        ObjectName objectName = (ObjectName) iterator.next();
        try {
            mBeanServer.unregisterMBean(objectName);
        } catch (Exception e) {
            LOG.error("Error unregistering object instance " + objectName + " . Error was " + e.getMessage(),
                    e);
        }
    }
    status = Status.STATUS_SHUTDOWN;
}

From source file:FullThreadDump.java

/**
 * Constructs a ThreadMonitor object to get thread information in a remote
 * JVM./*ww w  .  j  av  a  2  s.c o m*/
 */
public ThreadMonitor(MBeanServerConnection server) throws IOException {
    this.server = server;
    this.tmbean = newPlatformMXBeanProxy(server, THREAD_MXBEAN_NAME, ThreadMXBean.class);
    try {
        objname = new ObjectName(THREAD_MXBEAN_NAME);
    } catch (MalformedObjectNameException e) {
        // should not reach here
        InternalError ie = new InternalError(e.getMessage());
        ie.initCause(e);
        throw ie;
    }
    parseMBeanInfo();
}

From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java

private MetricValue getPercentActiveConnections(MBeanServerConnection connection, Metric metric)
        throws MetricUnreachableException, MetricNotFoundException, PluginException {
    int numActiveConnections = 0;
    int maxActiveConnections = 0;

    try {//from  ww  w . j a v  a 2s.  co m
        ObjectName dataSourceObjectName = new ObjectName(metric.getObjectName());
        numActiveConnections = ((Integer) connection.getAttribute(dataSourceObjectName, "numActive"))
                .intValue();
        maxActiveConnections = ((Integer) connection.getAttribute(dataSourceObjectName, "maxActive"))
                .intValue();
    } catch (MalformedObjectNameException e) {
        throw new MetricInvalidException("Error querying for DataSource MBeans: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MetricUnreachableException("Error querying for DataSource MBeans:" + e.getMessage(), e);
    } catch (AttributeNotFoundException e) {
        throw new MetricNotFoundException("Error querying for DataSource MBeans:" + e.getMessage(), e);
    } catch (InstanceNotFoundException e) {
        throw new MetricNotFoundException("Error querying for DataSource MBeans:" + e.getMessage(), e);
    } catch (MBeanException e) {
        throw new PluginException("Error querying for DataSource MBeans:" + e.getMessage(), e);
    } catch (ReflectionException e) {
        throw new PluginException("Error querying for DataSource MBeans:" + e.getMessage(), e);
    } catch (NullPointerException e) {
        throw new PluginException("Error querying for DataSource MBeans:" + e.getMessage(), e);
    }

    return new MetricValue(100d * (double) numActiveConnections / (double) maxActiveConnections);
}

From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java

private MetricValue getPercentAllocatedThreads(MBeanServerConnection connection, Metric metric)
        throws MetricUnreachableException, MetricNotFoundException, PluginException {
    int currentThreadCount = 0;
    int maxThreads = 0;

    try {//from w  w  w  . j ava  2s .  co  m
        ObjectName threadPoolObjectName = new ObjectName(metric.getObjectName());
        currentThreadCount = ((Integer) connection.getAttribute(threadPoolObjectName, "currentThreadCount"))
                .intValue();
        maxThreads = ((Integer) connection.getAttribute(threadPoolObjectName, "maxThreads")).intValue();
    } catch (MalformedObjectNameException e) {
        throw new MetricInvalidException("Error querying for Thread Pool MBeans: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MetricUnreachableException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (AttributeNotFoundException e) {
        throw new MetricNotFoundException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (InstanceNotFoundException e) {
        throw new MetricNotFoundException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (MBeanException e) {
        throw new PluginException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (ReflectionException e) {
        throw new PluginException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (NullPointerException e) {
        throw new PluginException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    }

    return new MetricValue(100d * (double) currentThreadCount / (double) maxThreads);
}

From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java

private MetricValue getPercentActiveThreads(MBeanServerConnection connection, Metric metric)
        throws MetricUnreachableException, MetricNotFoundException, PluginException {
    int currentThreadsBusy = 0;
    int maxThreads = 0;

    try {//from  ww w. j  ava 2 s  .c  o  m
        ObjectName threadPoolObjectName = new ObjectName(metric.getObjectName());
        currentThreadsBusy = ((Integer) connection.getAttribute(threadPoolObjectName, "currentThreadsBusy"))
                .intValue();
        maxThreads = ((Integer) connection.getAttribute(threadPoolObjectName, "maxThreads")).intValue();
    } catch (MalformedObjectNameException e) {
        throw new MetricInvalidException("Error querying for Thread Pool MBeans: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MetricUnreachableException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (AttributeNotFoundException e) {
        throw new MetricNotFoundException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (InstanceNotFoundException e) {
        throw new MetricNotFoundException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (MBeanException e) {
        throw new PluginException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (ReflectionException e) {
        throw new PluginException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    } catch (NullPointerException e) {
        throw new PluginException("Error querying for Thread Pool MBeans:" + e.getMessage(), e);
    }

    return new MetricValue(100d * (double) currentThreadsBusy / (double) maxThreads);
}

From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java

private int getDeadlockedThreadCount(MBeanServerConnection connection)
        throws MetricInvalidException, MetricUnreachableException {
    int deadlockCount = 0;
    try {/*from w  w  w . j  a  va 2s  .  c  o  m*/
        // in version 1.6+ there is a findDeadlockedThreads method
        long[] deadlocks;
        try {
            deadlocks = (long[]) connection.invoke(new ObjectName("java.lang:type=Threading"),
                    "findDeadlockedThreads", null, null);
        } catch (MalformedObjectNameException e) {
            throw new MetricInvalidException("Error querying for deadlock thread mbean: " + e.getMessage(), e);
        } catch (JMException e) {
            LOGGER.debug("Method 'findDeadlockedThreads' for objectname 'java.lang:type=Threading'"
                    + "was not found. Trying method findMonitorDeadlockedThreads...", e);
            // If this occurs then the issue is most likely related to the
            // Java version.
            // Now check for the method on java 1.5
            try {
                deadlocks = (long[]) connection.invoke(new ObjectName("java.lang:type=Threading"),
                        "findMonitorDeadlockedThreads", null, null);
            } catch (MalformedObjectNameException me) {
                throw new MetricInvalidException("Error querying for deadlock thread mbean: " + me.getMessage(),
                        me);
            } catch (JMException ex) {
                LOGGER.debug("Unable to retrieve DeadlockedThreads count: ", ex);
                throw new MetricUnreachableException(
                        "Unable to reach deadlock thread mbean: " + ex.getMessage(), ex);
            }
        }

        if (deadlocks != null) {
            deadlockCount = deadlocks.length;
        }
        return deadlockCount;
    } catch (IOException e) {
        throw new MetricUnreachableException("Error querying for deadlock thread mbean: " + e.getMessage(), e);
    }
}

From source file:com.springsource.hq.plugin.tcserver.plugin.TomcatMeasurementPlugin.java

private long getTotalGarbageCollectionTime(MBeanServerConnection connection)
        throws MetricUnreachableException, MetricNotFoundException, PluginException {

    long totalGcTimeMillis = 0;

    try {//  w  w w  . j a va  2 s  .co m

        // Use of the MXBean replaced by plain old JMX query for TCS-71
        //
        // Set<ObjectName> garbageCollectors = connection.queryNames(
        // new ObjectName("java.lang:type=GarbageCollector,*"), null);
        // for (ObjectName garbageCollectorName : garbageCollectors) {
        // GarbageCollectorMXBean garbageCollector = getGarbageCollectorMXBean(
        // connection, garbageCollectorName);
        // long collectionTime = garbageCollector.getCollectionTime();

        ObjectName gcObjName = new ObjectName("java.lang:type=GarbageCollector,*");
        Set<ObjectInstance> garbageCollectors = connection.queryMBeans(gcObjName, null);

        for (ObjectInstance instance : garbageCollectors) {
            ObjectName instanceName = instance.getObjectName();
            Long l = (Long) connection.getAttribute(instance.getObjectName(), "CollectionTime");
            long collectionTime = l.longValue();
            LOGGER.debug(instanceName + "::CollectionTime=" + collectionTime);

            if (collectionTime > -1) {
                totalGcTimeMillis += collectionTime;
            }
        }
    } catch (MalformedObjectNameException e) {
        throw new MetricInvalidException("Error querying for GarbageCollector MBeans: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new MetricUnreachableException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e);
    } catch (AttributeNotFoundException e) {
        throw new MetricNotFoundException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e);
    } catch (InstanceNotFoundException e) {
        throw new MetricNotFoundException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e);
    } catch (MBeanException e) {
        throw new PluginException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e);
    } catch (ReflectionException e) {
        throw new PluginException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e);
    } catch (NullPointerException e) {
        throw new PluginException("Error querying for GarbageCollector MBeans:" + e.getMessage(), e);
    }

    return totalGcTimeMillis;
}

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

private ObjectName getJVMRuntime() {
    String jvm = getAttribute(ATTR_JVM_RUNTIME);
    if (jvm == null) {
        return null;
    }/* ww w. j a v  a  2 s. c  o  m*/
    try {
        return new ObjectName(jvm);
    } catch (MalformedObjectNameException e) {
        //wont happen.
        throw new IllegalArgumentException(e.getMessage());
    }
}

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

private ObjectName getServerRuntime() {
    Hashtable attributes = new Hashtable();

    attributes.put("Type", "ServerRuntime");
    attributes.put("Name", getName());
    attributes.put("Location", getName());

    try {//from   ww w .ja va  2  s . co  m
        return new ObjectName(this.discover.getDomain(), attributes);
    } catch (MalformedObjectNameException e) {
        //wont happen.
        throw new IllegalArgumentException(e.getMessage());
    }
}

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

private ObjectName getSSL() {
    Hashtable attributes = new Hashtable();

    attributes.put("Type", "SSL");
    attributes.put("Name", getName());
    attributes.put("Server", getName());

    try {/*from  ww  w  .  j  a  va2  s.  c  o m*/
        return new ObjectName(this.discover.getDomain(), attributes);
    } catch (MalformedObjectNameException e) {
        //wont happen.
        throw new IllegalArgumentException(e.getMessage());
    }
}