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;
}
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);
});
}
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));
}
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);
}
}
}
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);
}
Aggregations