Search in sources :

Example 21 with NotificationFilter

use of javax.management.NotificationFilter in project jdk8u_jdk by JetBrains.

the class DirectoryScannerTest method doTestOperation.

private void doTestOperation(DirectoryScannerMXBean proxy, Call op, EnumSet<ScanState> after, String testName) throws Exception {
    System.out.println("doTestOperation: " + testName);
    final LinkedBlockingQueue<Notification> queue = new LinkedBlockingQueue<Notification>();
    NotificationListener listener = new NotificationListener() {

        public void handleNotification(Notification notification, Object handback) {
            try {
                queue.put(notification);
            } catch (Exception x) {
                System.err.println("Failed to queue notif: " + x);
            }
        }
    };
    NotificationFilter filter = null;
    Object handback = null;
    final ScanState before;
    final NotificationEmitter emitter = (NotificationEmitter) makeNotificationEmitter(proxy, DirectoryScannerMXBean.class);
    emitter.addNotificationListener(listener, filter, handback);
    before = proxy.getState();
    op.call();
    try {
        final Notification notification = queue.poll(3000, TimeUnit.MILLISECONDS);
        assertEquals(AttributeChangeNotification.ATTRIBUTE_CHANGE, notification.getType());
        assertEquals(AttributeChangeNotification.class, notification.getClass());
        assertEquals(getObjectName(proxy), notification.getSource());
        AttributeChangeNotification acn = (AttributeChangeNotification) notification;
        assertEquals("State", acn.getAttributeName());
        assertEquals(ScanState.class.getName(), acn.getAttributeType());
        assertEquals(before, ScanState.valueOf((String) acn.getOldValue()));
        assertContained(after, ScanState.valueOf((String) acn.getNewValue()));
        emitter.removeNotificationListener(listener, filter, handback);
    } finally {
        try {
            op.cancel();
        } catch (Exception x) {
            System.err.println("Failed to cleanup: " + x);
        }
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) AttributeChangeNotification(javax.management.AttributeChangeNotification) ScanState(com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification) AttributeChangeNotification(javax.management.AttributeChangeNotification) NotificationListener(javax.management.NotificationListener)

Example 22 with NotificationFilter

use of javax.management.NotificationFilter in project felix by apache.

the class RMIConnectionInvoker method addNotificationListener.

public void addNotificationListener(ObjectName name, ObjectName listener, MarshalledObject filter, MarshalledObject handback, Subject delegate) throws InstanceNotFoundException, IOException {
    NotificationFilter f = (NotificationFilter) RMIMarshaller.unmarshal(filter, server.getClassLoaderFor(name), defaultLoader);
    Object h = RMIMarshaller.unmarshal(handback, server.getClassLoaderFor(name), defaultLoader);
    server.addNotificationListener(name, listener, f, h);
}
Also used : MarshalledObject(java.rmi.MarshalledObject) NotificationFilter(javax.management.NotificationFilter)

Example 23 with NotificationFilter

use of javax.management.NotificationFilter in project quasar by puniverse.

the class MonitoringServices method addStructuralNotificationListener.

public synchronized void addStructuralNotificationListener(NotificationListener listener, Object handback) {
    timer.addNotificationListener(listener, new NotificationFilter() {

        @Override
        public boolean isNotificationEnabled(Notification notification) {
            return "structTimer".equals(notification.getType());
        }
    }, handback);
    structuralTimerListeners++;
    manageTimer();
}
Also used : NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification)

Example 24 with NotificationFilter

use of javax.management.NotificationFilter in project quasar by puniverse.

the class MonitoringServices method addPerfNotificationListener.

public synchronized void addPerfNotificationListener(NotificationListener listener, Object handback) {
    timer.addNotificationListener(listener, new NotificationFilter() {

        @Override
        public boolean isNotificationEnabled(Notification notification) {
            return "perfTimer".equals(notification.getType());
        }
    }, handback);
    perfTimerListeners++;
    manageTimer();
}
Also used : NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification)

Aggregations

NotificationFilter (javax.management.NotificationFilter)24 Notification (javax.management.Notification)16 NotificationListener (javax.management.NotificationListener)11 ObjectName (javax.management.ObjectName)8 HashMap (java.util.HashMap)4 NotificationEmitter (javax.management.NotificationEmitter)4 MarshalledObject (java.rmi.MarshalledObject)3 Date (java.util.Date)3 AttributeChangeNotification (javax.management.AttributeChangeNotification)3 ScanState (com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState)2 GarbageCollectionNotificationInfo (com.sun.management.GarbageCollectionNotificationInfo)2 GcInfo (com.sun.management.GcInfo)2 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)2 MemoryUsage (java.lang.management.MemoryUsage)2 Map (java.util.Map)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 MBeanServer (javax.management.MBeanServer)2 MBeanServerNotification (javax.management.MBeanServerNotification)2 NotificationFilterSupport (javax.management.NotificationFilterSupport)2 TargetedNotification (javax.management.remote.TargetedNotification)2