use of javax.management.NotificationListener in project jdk8u_jdk by JetBrains.
the class DefaultMBeanServerInterceptor method removeNotificationListener.
private void removeNotificationListener(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback, boolean removeAll) throws InstanceNotFoundException, ListenerNotFoundException {
if (MBEANSERVER_LOGGER.isLoggable(Level.FINER)) {
MBEANSERVER_LOGGER.logp(Level.FINER, DefaultMBeanServerInterceptor.class.getName(), "removeNotificationListener", "ObjectName = " + name);
}
DynamicMBean instance = getMBean(name);
checkMBeanPermission(instance, null, name, "removeNotificationListener");
/* We could simplify the code by assigning broadcaster after
assigning listenerWrapper, but that would change the error
behavior when both the broadcaster and the listener are
erroneous. */
Class<? extends NotificationBroadcaster> reqClass = removeAll ? NotificationBroadcaster.class : NotificationEmitter.class;
NotificationBroadcaster broadcaster = getNotificationBroadcaster(name, instance, reqClass);
NotificationListener listenerWrapper = getListenerWrapper(listener, name, instance, false);
if (listenerWrapper == null)
throw new ListenerNotFoundException("Unknown listener");
if (removeAll)
broadcaster.removeNotificationListener(listenerWrapper);
else {
NotificationEmitter emitter = (NotificationEmitter) broadcaster;
emitter.removeNotificationListener(listenerWrapper, filter, handback);
}
}
use of javax.management.NotificationListener in project jdk8u_jdk by JetBrains.
the class SnmpMibTable method sendNotification.
// ----------------------------------------------------------------------
// PRIVATE METHODS
// ----------------------------------------------------------------------
/**
* Enable this <CODE>SnmpMibTable</CODE> to send a notification.
*
* <p>
* @param notification The notification to send.
*/
private synchronized void sendNotification(Notification notification) {
//
for (java.util.Enumeration<NotificationListener> k = handbackTable.keys(); k.hasMoreElements(); ) {
NotificationListener listener = k.nextElement();
// Get the associated handback list and the associated filter list
//
java.util.Vector<?> handbackList = handbackTable.get(listener);
java.util.Vector<NotificationFilter> filterList = filterTable.get(listener);
// loop on handback
//
java.util.Enumeration<NotificationFilter> f = filterList.elements();
for (java.util.Enumeration<?> h = handbackList.elements(); h.hasMoreElements(); ) {
Object handback = h.nextElement();
NotificationFilter filter = f.nextElement();
if ((filter == null) || (filter.isNotificationEnabled(notification))) {
listener.handleNotification(notification, handback);
}
}
}
}
use of javax.management.NotificationListener in project jdk8u_jdk by JetBrains.
the class LoggingExceptionTest method main.
public static void main(String[] args) {
Handler handler = new ConsoleHandler();
Logger logger = Logger.getLogger("javax.management.modelmbean");
logger.addHandler(handler);
logger.setLevel(Level.FINEST);
try {
for (int i = 0; i < tests.length; i++) {
System.out.println(">>> DescriptorSupportLoggingTest: Test Case " + i);
DescriptorSupport ds;
String msg = "Instantiate " + tests[i];
System.out.println(msg);
switch(i) {
case 0:
ds = new DescriptorSupport();
break;
case 1:
ds = new DescriptorSupport(10);
break;
case 2:
ds = new DescriptorSupport(new DescriptorSupport().toXMLString());
break;
case 3:
ds = new DescriptorSupport("name1=value1", "name2=value2");
break;
case 4:
ds = new DescriptorSupport(new String[] { "name" }, new Object[] { "value" });
break;
case 5:
ds = new DescriptorSupport(new DescriptorSupport());
break;
case 6:
RequiredModelMBean mbean = new RequiredModelMBean();
NotificationListener nl = new NotificationListener() {
public void handleNotification(Notification notification, Object handback) {
}
};
mbean.addAttributeChangeNotificationListener(nl, null, null);
break;
default:
throw new AssertionError();
}
System.out.println(msg + " OK");
}
} catch (Exception e) {
System.out.println("Got unexpected exception = " + e);
String msg = "Test FAILED!";
System.out.println(msg);
throw new IllegalArgumentException(msg);
}
System.out.println("Test PASSED!");
}
use of javax.management.NotificationListener in project Payara by payara.
the class ListenerTest method testAddRemoveNotificationListener.
public void testAddRemoveNotificationListener() throws Exception {
final long start = now();
final Set<AMX> all = getAllAMX();
final NotificationListener listener1 = new DummyListener();
final NotificationListener listener2 = new DummyListener();
final NotificationFilter filter = new NotificationFilterSupport();
final Object handback = "handback";
for (final AMX amx : all) {
amx.getNotificationInfo();
amx.addNotificationListener(listener1, null, null);
amx.addNotificationListener(listener2, filter, handback);
}
for (final AMX amx : all) {
amx.removeNotificationListener(listener1);
amx.removeNotificationListener(listener2, filter, handback);
}
printElapsed("Added/removed NotificationListener", all.size(), start);
}
use of javax.management.NotificationListener in project fabric8 by jboss-fuse.
the class ManagedApiFeature method initialize.
@Override
public void initialize(Server server, Bus bus) {
final ManagedApi mApi = new ManagedApi(bus, server.getEndpoint(), server);
final InstrumentationManager iMgr = bus.getExtension(InstrumentationManager.class);
if (iMgr != null) {
try {
iMgr.register(mApi);
final ServerLifeCycleManager slcMgr = bus.getExtension(ServerLifeCycleManager.class);
if (slcMgr != null) {
slcMgr.registerListener(mApi);
slcMgr.startServer(server);
}
// Register notification listener to propagate unregistration of endpoint MBeans
final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
if (mBeanServer == null) {
return;
}
NotificationListener listener = new NotificationListener() {
@Override
public void handleNotification(Notification notification, Object handback) {
MBeanServerNotification mbsNotification = (MBeanServerNotification) notification;
ObjectName objectName = mbsNotification.getMBeanName();
String type = mbsNotification.getType();
try {
if (MBeanServerNotification.UNREGISTRATION_NOTIFICATION.equals(type) && mApi.isCompanion(objectName)) {
if (slcMgr != null) {
slcMgr.unRegisterListener(mApi);
}
iMgr.unregister(mApi);
mBeanServer.removeNotificationListener(MBeanServerDelegate.DELEGATE_NAME, this);
}
} catch (JMException e) {
LOG.log(Level.WARNING, "Unregistering ManagedApi failed.", e);
}
}
};
mBeanServer.addNotificationListener(MBeanServerDelegate.DELEGATE_NAME, listener, mBeanServerNotificationFilter, null);
} catch (JMException jmex) {
jmex.printStackTrace();
LOG.log(Level.WARNING, "Registering ManagedApi failed.", jmex);
}
}
}
Aggregations