+ private static final class ModuleNotificationListener implements NotificationListener {
+ private final ObjectName objectNameInternal;
+ private final MBeanServer internalServer;
+ private final ObjectName thisWrapperObjectName;
+ private final MBeanServer configMBeanServer;
+
+ private ModuleNotificationListener(final ObjectName objectNameInternal, final MBeanServer internalServer,
+ final ObjectName thisWrapperObjectName, final MBeanServer configMBeanServer) {
+ this.objectNameInternal = objectNameInternal;
+ this.internalServer = internalServer;
+ this.thisWrapperObjectName = thisWrapperObjectName;
+ this.configMBeanServer = configMBeanServer;
+ }
+
+ @Override
+ public void handleNotification(final Notification n, final Object handback) {
+ if (n instanceof MBeanServerNotification
+ && n.getType()
+ .equals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
+ if (((MBeanServerNotification) n).getMBeanName().equals(
+ thisWrapperObjectName)) {
+ try {
+ internalServer.unregisterMBean(objectNameInternal);
+ configMBeanServer.removeNotificationListener(
+ MBeanServerDelegate.DELEGATE_NAME, this);
+ } catch (MBeanRegistrationException
+ | ListenerNotFoundException
+ | InstanceNotFoundException e) {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+ }
+ }