Example usage for javax.management MBeanException getStackTrace

List of usage examples for javax.management MBeanException getStackTrace

Introduction

In this page you can find the example usage for javax.management MBeanException getStackTrace.

Prototype

public StackTraceElement[] getStackTrace() 

Source Link

Document

Provides programmatic access to the stack trace information printed by #printStackTrace() .

Usage

From source file:org.apache.hadoop.test.system.AbstractDaemonClient.java

/**
 * Method implements all logic for receiving a bean's attribute.
 * If any initializations such as establishing bean server connections, etc.
 * are need it will do it.//from  w w  w. j av  a  2s.  co m
 * @param serviceName name of the service where MBean is registered (NameNode)
 * @param type name of the MXBean class
 * @param attributeName name of the attribute to be retrieved
 * @return Object value of the attribute or <code>null</code> if not found
 * @throws IOException is thrown in case of any errors
 */
protected Object getJmxAttribute(String serviceName, String type, String attributeName) throws IOException {
    Object retAttribute = null;
    String domain = null;
    if (isJmxEnabled()) {
        try {
            MBeanServerConnection conn = establishJmxConnection(getHostName(), getJmxPortNumber());
            for (String d : conn.getDomains()) {
                if (d != null && d.startsWith(HADOOP_JMX_DOMAIN))
                    domain = d;
            }
            if (!jmxObjectNames.containsKey(type))
                jmxObjectNames.put(type, getJmxBeanName(domain, serviceName, type));
            retAttribute = conn.getAttribute(jmxObjectNames.get(type), attributeName);
        } catch (MBeanException e) {
            LOG.debug(e.getStackTrace());
            throw new IOException(e);
        } catch (AttributeNotFoundException e) {
            LOG.warn(e.getStackTrace());
            throw new IOException(e);
        } catch (InstanceNotFoundException e) {
            LOG.warn(e.getStackTrace());
            throw new IOException(e);
        } catch (ReflectionException e) {
            LOG.debug(e.getStackTrace());
            throw new IOException(e);
        }
    }
    return retAttribute;
}