Search in sources :

Example 11 with Notification

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

the class NotificationAccessControllerTest method checkNotifs.

/**
     * Check received notifications
     */
public int checkNotifs(int size, List<Notification> received, List<ObjectName> expected) {
    if (received.size() != size) {
        echo("Error: expecting " + size + " notifications, got " + received.size());
        return 1;
    } else {
        for (Notification n : received) {
            echo("Received notification: " + n);
            if (!n.getType().equals("nb")) {
                echo("Notification type must be \"nb\"");
                return 1;
            }
            ObjectName o = (ObjectName) n.getSource();
            int index = (int) n.getSequenceNumber();
            ObjectName nb = expected.get(index);
            if (!o.equals(nb)) {
                echo("Notification source must be " + nb);
                return 1;
            }
        }
    }
    return 0;
}
Also used : Notification(javax.management.Notification) ObjectName(javax.management.ObjectName)

Example 12 with Notification

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

the class DistributedSystemDUnitTest method addAlertListener.

private void addAlertListener(final VM managerVM) {
    managerVM.invoke("addAlertListener", () -> {
        AlertNotificationListener listener = AlertNotificationListener.getInstance();
        listener.resetCount();
        NotificationFilter notificationFilter = (Notification notification) -> notification.getType().equals(JMXNotificationType.SYSTEM_ALERT);
        getPlatformMBeanServer().addNotificationListener(getDistributedSystemName(), listener, notificationFilter, null);
    });
}
Also used : NotificationFilter(javax.management.NotificationFilter) Notification(javax.management.Notification)

Example 13 with Notification

use of javax.management.Notification in project spring-framework by spring-projects.

the class NotificationListenerTests method testRegisterNotificationListenerWithFilter.

@SuppressWarnings("serial")
@Test
public void testRegisterNotificationListenerWithFilter() throws Exception {
    ObjectName objectName = ObjectName.getInstance("spring:name=Test");
    JmxTestBean bean = new JmxTestBean();
    Map<String, Object> beans = new HashMap<>();
    beans.put(objectName.getCanonicalName(), bean);
    CountingAttributeChangeNotificationListener listener = new CountingAttributeChangeNotificationListener();
    NotificationListenerBean listenerBean = new NotificationListenerBean();
    listenerBean.setNotificationListener(listener);
    listenerBean.setNotificationFilter(new NotificationFilter() {

        @Override
        public boolean isNotificationEnabled(Notification notification) {
            if (notification instanceof AttributeChangeNotification) {
                AttributeChangeNotification changeNotification = (AttributeChangeNotification) notification;
                return "Name".equals(changeNotification.getAttributeName());
            } else {
                return false;
            }
        }
    });
    MBeanExporter exporter = new MBeanExporter();
    exporter.setServer(server);
    exporter.setBeans(beans);
    exporter.setNotificationListeners(new NotificationListenerBean[] { listenerBean });
    start(exporter);
    // update the attributes
    String nameAttribute = "Name";
    String ageAttribute = "Age";
    server.setAttribute(objectName, new Attribute(nameAttribute, "Rob Harrop"));
    server.setAttribute(objectName, new Attribute(ageAttribute, new Integer(90)));
    assertEquals("Listener not notified for Name", 1, listener.getCount(nameAttribute));
    assertEquals("Listener incorrectly notified for Age", 0, listener.getCount(ageAttribute));
}
Also used : AttributeChangeNotification(javax.management.AttributeChangeNotification) HashMap(java.util.HashMap) Attribute(javax.management.Attribute) Notification(javax.management.Notification) AttributeChangeNotification(javax.management.AttributeChangeNotification) ObjectName(javax.management.ObjectName) JmxTestBean(org.springframework.jmx.JmxTestBean) NotificationFilter(javax.management.NotificationFilter) Test(org.junit.Test)

Example 14 with Notification

use of javax.management.Notification in project cassandra by apache.

the class LegacyJMXProgressSupport method progress.

@Override
public void progress(String tag, ProgressEvent event) {
    if (tag.startsWith("repair:")) {
        Optional<int[]> legacyUserData = getLegacyUserdata(tag, event);
        if (legacyUserData.isPresent()) {
            Notification jmxNotification = new Notification("repair", jmxObjectName, notificationSerialNumber.incrementAndGet(), event.getMessage());
            jmxNotification.setUserData(legacyUserData.get());
            broadcaster.sendNotification(jmxNotification);
        }
    }
}
Also used : Notification(javax.management.Notification)

Example 15 with Notification

use of javax.management.Notification in project camel by apache.

the class SimpleBean method userData.

public void userData(String aUserData) {
    Notification n = new Notification("userData", this, mSequence++, mTimestamp, "Here's my user data");
    n.setUserData(aUserData);
    sendNotification(n);
}
Also used : JMXConnectionNotification(javax.management.remote.JMXConnectionNotification) MBeanServerNotification(javax.management.MBeanServerNotification) TimerNotification(javax.management.timer.TimerNotification) AttributeChangeNotification(javax.management.AttributeChangeNotification) Notification(javax.management.Notification) RelationNotification(javax.management.relation.RelationNotification)

Aggregations

Notification (javax.management.Notification)204 ObjectName (javax.management.ObjectName)68 NotificationListener (javax.management.NotificationListener)35 AttributeChangeNotification (javax.management.AttributeChangeNotification)29 CompositeData (javax.management.openmbean.CompositeData)25 IOException (java.io.IOException)23 Test (org.junit.Test)20 HashMap (java.util.HashMap)19 MalformedObjectNameException (javax.management.MalformedObjectNameException)19 Test (org.testng.annotations.Test)18 ListenerNotFoundException (javax.management.ListenerNotFoundException)17 ArrayList (java.util.ArrayList)16 MBeanServer (javax.management.MBeanServer)16 NotificationFilter (javax.management.NotificationFilter)15 NotificationEmitter (javax.management.NotificationEmitter)14 JMXConnector (javax.management.remote.JMXConnector)14 JMXServiceURL (javax.management.remote.JMXServiceURL)14 MBeanServerConnection (javax.management.MBeanServerConnection)12 MalformedURLException (java.net.MalformedURLException)11 JMXConnectorServer (javax.management.remote.JMXConnectorServer)11