Example usage for javax.management MBeanServer getClass

List of usage examples for javax.management MBeanServer getClass

Introduction

In this page you can find the example usage for javax.management MBeanServer getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.googlecode.arit.mbeans.MBeanScanner.java

public void scanForResources(ResourceListener resourceEventListener) {
    ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
    for (MBeanServer mbs : mbeanServers) {
        MBeanAccessor mbeanAccessor = mbsInspector.inspect(mbs);
        if (mbeanAccessor == null) {
            String errorMsg = "Unable to inspect MBeanServer of type " + mbs.getClass().getName();
            LOG.error(errorMsg);// w  w  w .  j  ava  2  s  .c  om
            if (messages != null) {
                messages.addMessage(errorMsg);
            }
        } else {
            Set<ObjectName> mbeans;
            try {
                mbeans = mbs.queryNames(new ObjectName("*:*"), null);
            } catch (MalformedObjectNameException ex) {
                // We should never get here
                throw new Error(ex);
            }

            for (ObjectName name : mbeans) {
                Object mbean = mbeanAccessor.retrieve(name);
                SimpleResource<Object> mbeanResource = new SimpleResource<Object>(resourceType, mbean,
                        "MBean: " + name);
                mbeanResource.addClassloaderReference(mbean.getClass().getClassLoader(),
                        "Implementation class: " + mbean.getClass().getName());
                resourceEventListener.onResourceFound(mbeanResource);
            }
        }
    }
}

From source file:com.googlecode.arit.mbeans.MBeanScanner.java

public void clean(ClassLoader classLoader) {
    ArrayList<MBeanServer> mbeanServers = MBeanServerFactory.findMBeanServer(null);
    for (MBeanServer mbs : mbeanServers) {
        MBeanAccessor mbeanAccessor = mbsInspector.inspect(mbs);
        if (mbeanAccessor == null) {
            String errorMsg = "Unable to inspect MBeanServer of type " + mbs.getClass().getName();
            LOG.error(errorMsg);//from   ww w  .jav a2 s  .c om
            if (messages != null) {
                messages.addMessage(errorMsg);
            }
        } else {
            Set<ObjectName> mbeans;
            try {
                mbeans = mbs.queryNames(new ObjectName("*:*"), null);
            } catch (MalformedObjectNameException ex) {
                // We should never get here
                throw new Error(ex);
            }

            for (ObjectName name : mbeans) {
                Object mbean = mbeanAccessor.retrieve(name);
                if (mbean.getClass().getClassLoader().equals(classLoader)) {
                    try {
                        mbs.unregisterMBean(name);
                    } catch (JMException ex) {
                        String errorMsg = "Error during cleanup of mbean - unregistration of mbean "
                                + name.toString() + " failed";
                        LOG.error(errorMsg, ex);
                        if (messages != null) {
                            messages.addMessage(errorMsg);
                        }
                    }
                }
            }
        }
    }
}