Search in sources :

Example 6 with JMRuntimeException

use of javax.management.JMRuntimeException in project geode by apache.

the class MBeanUtil method registerServerNotificationListener.

static void registerServerNotificationListener() {
    if (mbeanServer == null) {
        return;
    }
    try {
        // the MBeanServerDelegate name is spec'ed as the following...
        ObjectName delegate = ObjectName.getInstance("JMImplementation:type=MBeanServerDelegate");
        mbeanServer.addNotificationListener(delegate, new NotificationListener() {

            public void handleNotification(Notification notification, Object handback) {
                MBeanServerNotification serverNotification = (MBeanServerNotification) notification;
                if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(serverNotification.getType())) {
                    ObjectName objectName = serverNotification.getMBeanName();
                    synchronized (MBeanUtil.managedResources) {
                        Object entry = MBeanUtil.managedResources.get(objectName);
                        if (entry == null)
                            return;
                        if (!(entry instanceof ManagedResource)) {
                            throw new ClassCastException(LocalizedStrings.MBeanUtil_0_IS_NOT_A_MANAGEDRESOURCE.toLocalizedString(new Object[] { entry.getClass().getName() }));
                        }
                        ManagedResource resource = (ManagedResource) entry;
                        {
                            // call cleanup on managedResource
                            cleanupResource(resource);
                        }
                    }
                }
            }
        }, null, null);
    } catch (JMException e) {
        logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
    } catch (JMRuntimeException e) {
        logStackTrace(Level.WARN, e, LocalizedStrings.MBeanUtil_FAILED_TO_REGISTER_SERVERNOTIFICATIONLISTENER.toLocalizedString());
    }
}
Also used : MBeanServerNotification(javax.management.MBeanServerNotification) JMException(javax.management.JMException) JMRuntimeException(javax.management.JMRuntimeException) Notification(javax.management.Notification) MBeanServerNotification(javax.management.MBeanServerNotification) ObjectName(javax.management.ObjectName) NotificationListener(javax.management.NotificationListener)

Aggregations

JMRuntimeException (javax.management.JMRuntimeException)6 ObjectName (javax.management.ObjectName)4 JMException (javax.management.JMException)2 MBeanInfo (javax.management.MBeanInfo)2 AuthInfo (com.sun.jdmk.comm.AuthInfo)1 HtmlAdaptorServer (com.sun.jdmk.comm.HtmlAdaptorServer)1 SnmpAdaptorServer (com.sun.management.comm.SnmpAdaptorServer)1 SnmpStatusException (com.sun.management.snmp.SnmpStatusException)1 File (java.io.File)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 DynamicMBean (javax.management.DynamicMBean)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 InstanceNotFoundException (javax.management.InstanceNotFoundException)1 MBeanAttributeInfo (javax.management.MBeanAttributeInfo)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 MBeanServer (javax.management.MBeanServer)1