下面列出了怎么用javax.management.NotificationFilterSupport的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Sets up event listeners for this MBean as described in the descriptor.
* The descriptor contains a map with layout
* {item -> Map[event:"...", from:ObjectName, callback:&Closure],...,}
*
* @param server the MBeanServer is to be registered.
* @param descriptor a map containing info about the event
*/
public void addEventListeners(MBeanServer server, Map<String, Map<String, Object>> descriptor) {
for (Map.Entry<String, Map<String, Object>> item : descriptor.entrySet()) {
Map<String, Object> listener = item.getValue();
// register with server
ObjectName broadcaster = (ObjectName) listener.get("from");
try {
String eventType = (String) listener.get("event");
if (eventType != null) {
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(eventType);
server.addNotificationListener(broadcaster, JmxEventListener.getListener(), filter, listener);
} else {
server.addNotificationListener(broadcaster, JmxEventListener.getListener(), null, listener);
}
} catch (InstanceNotFoundException e) {
throw new JmxBuilderException(e);
}
}
}
@Test
public void testNotificationTccl() throws Exception {
ObjectName objName = createName("test.domain:bean=test-tccl");
server.registerMBean(new TestBean(objName), objName);
ClassLoader oldTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
ClassLoader newOutTccl = new URLClassLoader(new URL[]{}, oldTccl); // creating a new class loader here
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(newOutTccl);
try {
final AtomicBoolean differ = new AtomicBoolean(false);
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType("testtccl");
server.addNotificationListener(objName, new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {
Assert.assertEquals("callback", handback.toString());
ClassLoader newInTccl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
Assert.assertNotEquals(newInTccl, newOutTccl);
differ.set(true);
}
}, filter, "callback");
server.invoke(objName, "proceed", null, null);
Assert.assertTrue(differ.get());
} finally {
WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldTccl);
}
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
/**
* the INITTASKS calling connectToDS across ThreadGroups
* should be executed with the keyword SEQUENTIAL
* <p>
* Must be invoked after the JMX agents have been created, started, and
* connected using {@link hydra.AgentHelper}.
*/
public static void connectToDS() throws Exception
{
// Connect To DS
connectToDSButDoNotAttachListeners();
//Register the stat alert notification listener as well.
listener = new StatAlertNotificationListener(40);
NotificationFilterSupport support = new NotificationFilterSupport();
support.enableType(AdminDistributedSystemJmxImpl.NOTIF_STAT_ALERT);
mbsc.addNotificationListener(distributedSys, listener, support, new Object());
logger.info("Connected to JMX ADS " + distributedSys);
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
/**
* the INITTASKS calling connectToDS across ThreadGroups
* should be executed with the keyword SEQUENTIAL
* <p>
* Must be invoked after the JMX agents have been created, started, and
* connected using {@link hydra.AgentHelper}.
*/
public static void connectToDS() throws Exception
{
// Connect To DS
connectToDSButDoNotAttachListeners();
//Register the stat alert notification listener as well.
listener = new StatAlertNotificationListener(40);
NotificationFilterSupport support = new NotificationFilterSupport();
support.enableType(AdminDistributedSystemJmxImpl.NOTIF_STAT_ALERT);
mbsc.addNotificationListener(distributedSys, listener, support, new Object());
logger.info("Connected to JMX ADS " + distributedSys);
}
/**
* Registers listeners for operation calls (i.e. method, getter, and setter calls) when
* invoked on this bean from the MBeanServer. Descriptor should contain a map with layout
* {@code item -> [Map[methodListener:[target:"", tpe:"", callback:&Closure], ... ,]]}
*
* @param descriptor MetaMap descriptor containing description of operation call listeners
*/
public void addOperationCallListeners(Map<String, Map<String, Map<String, Object>>> descriptor) {
if (descriptor == null) return;
for (Map.Entry<String, Map<String, Map<String, Object>>> item : descriptor.entrySet()) {
// set up method listeners (such as attributeListener and Operation Listeners)
// item -> [Map[methodListener:[target:"", tpe:"", callback:&Closure], ... ,]]
if (item.getValue().containsKey("methodListener")) {
Map<String, Object> listener = item.getValue().get("methodListener");
String target = (String) listener.get("target");
methodListeners.add(target);
String listenerType = (String) listener.get("type");
listener.put("managedObject", this.managedObject);
// register an attribute change notification listener with model mbean
if (listenerType.equals("attributeChangeListener")) {
try {
this.addAttributeChangeNotificationListener(
AttributeChangedListener.getListener(), (String) listener.get("attribute"), listener
);
} catch (MBeanException e) {
throw new JmxBuilderException(e);
}
}
if (listenerType.equals("operationCallListener")) {
String eventType = "jmx.operation.call." + target;
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(eventType);
this.addNotificationListener(JmxEventListener.getListener(), filter, listener);
}
}
}
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
protected Integer addListenerForMBeanRemovedNotif()
throws IOException, InstanceNotFoundException {
NotificationFilterSupport clientFilter =
new NotificationFilterSupport();
clientFilter.enableType(
MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
MarshalledObject<NotificationFilter> sFilter =
new MarshalledObject<NotificationFilter>(clientFilter);
Integer[] listenerIDs;
final ObjectName[] names =
new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
final MarshalledObject<NotificationFilter>[] filters =
Util.cast(new MarshalledObject<?>[] {sFilter});
final Subject[] subjects = new Subject[] {null};
try {
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
} catch (IOException ioe) {
communicatorAdmin.gotIOException(ioe);
listenerIDs =
connection.addNotificationListeners(names,
filters,
subjects);
}
return listenerIDs[0];
}
/**
* Matches any of the given notification types.
* @see {@link NotificationFilterSupport#enableType(String)}
*/
public static NotificationFilter matchesTypes(String... types) {
NotificationFilterSupport result = new NotificationFilterSupport();
for (String type : types) {
result.enableType(type);
}
return result;
}
public void doTestMBeanServerNotification_REGISTRATION_NOTIFICATION(MBeanServerConnection connection, boolean mustReceiveNotification) throws Exception {
final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test");
final ObjectName childObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,single=only");
final CountDownLatch notificationEmitted = new CountDownLatch(1);
final AtomicReference<Notification> notification = new AtomicReference<>();
NotificationListener listener = new MbeanServerNotificationListener(notification, notificationEmitted, LEGACY_DOMAIN);
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(MBeanServerNotification.REGISTRATION_NOTIFICATION);
connection.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
// add a management resource
connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()});
if (mustReceiveNotification) {
Assert.assertTrue("Did not receive expected notification", notificationEmitted.await(1, TimeUnit.SECONDS));
Notification notif = notification.get();
Assert.assertNotNull(notif);
Assert.assertTrue(notif instanceof MBeanServerNotification);
MBeanServerNotification mBeanServerNotification = (MBeanServerNotification) notif;
Assert.assertEquals(MBeanServerNotification.REGISTRATION_NOTIFICATION, notif.getType());
Assert.assertEquals(childObjectName, mBeanServerNotification.getMBeanName());
} else {
Assert.assertFalse("Did receive unexpected notification", notificationEmitted.await(500, TimeUnit.MILLISECONDS));
}
connection.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
}
private void doTestMBeanServerNotification_UNREGISTRATION_NOTIFICATION(MBeanServerConnection connection, boolean mustReceiveNotification) throws Exception {
final ObjectName testObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test");
final ObjectName childObjectName = createObjectName(LEGACY_DOMAIN + ":subsystem=test,single=only");
final CountDownLatch notificationEmitted = new CountDownLatch(1);
final AtomicReference<Notification> notification = new AtomicReference<>();
NotificationListener listener = new MbeanServerNotificationListener(notification, notificationEmitted, LEGACY_DOMAIN);
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
connection.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
// add a management resource
connection.invoke(testObjectName, "addSingleOnly", new Object[]{123}, new String[]{String.class.getName()});
// and remove it
connection.invoke(childObjectName, "remove", new Object[0], new String[0]);
if (mustReceiveNotification) {
Assert.assertTrue("Did not receive expected notification", notificationEmitted.await(1, TimeUnit.SECONDS));
Notification notif = notification.get();
Assert.assertNotNull(notif);
Assert.assertTrue(notif instanceof MBeanServerNotification);
MBeanServerNotification mBeanServerNotification = (MBeanServerNotification) notif;
Assert.assertEquals(MBeanServerNotification.UNREGISTRATION_NOTIFICATION, mBeanServerNotification.getType());
Assert.assertEquals(childObjectName, mBeanServerNotification.getMBeanName());
} else {
Assert.assertFalse("Did receive unexpected notification", notificationEmitted.await(500, TimeUnit.MILLISECONDS));
}
connection.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, filter, null);
}
public ClientGui(final Client client) throws IOException, JMException {
this.client = Objects.requireNonNull(client, "client");
createWidgets();
populateWidgets();
// register for Notifications if LoggerContext MBean was added/removed
final ObjectName addRemoveNotifs = MBeanServerDelegate.DELEGATE_NAME;
final NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(Server.DOMAIN); // only interested in Log4J2 MBeans
client.getConnection().addNotificationListener(addRemoveNotifs, this, null, null);
}
private void registerListeners(final StatusLoggerAdminMBean status) throws InstanceNotFoundException,
MalformedObjectNameException, IOException {
final NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(StatusLoggerAdminMBean.NOTIF_TYPE_MESSAGE);
final ObjectName objName = status.getObjectName();
// System.out.println("Add listener for " + objName);
client.getConnection().addNotificationListener(objName, this, filter, status.getContextName());
}