use of com.ibm.lang.management.TotalPhysicalMemoryNotificationInfo in project openj9 by eclipse.
the class OperatingSystemNotificationThread method dispatchNotificationHelper.
private void dispatchNotificationHelper(int type, long data, long sequenceNumber) {
if (type == 1) {
// #CPUs changed
AvailableProcessorsNotificationInfo info = new AvailableProcessorsNotificationInfo((int) data);
// $NON-NLS-1$
Notification n = new Notification(AvailableProcessorsNotificationInfo.AVAILABLE_PROCESSORS_CHANGE, "java.lang:type=OperatingSystem", sequenceNumber);
n.setUserData(AvailableProcessorsNotificationInfoUtil.toCompositeData(info));
osBean.sendNotification(n);
} else if (type == 2) {
// processing capacity changed
ProcessingCapacityNotificationInfo info = new ProcessingCapacityNotificationInfo((int) data);
// $NON-NLS-1$
Notification n = new Notification(ProcessingCapacityNotificationInfo.PROCESSING_CAPACITY_CHANGE, "java.lang:type=OperatingSystem", sequenceNumber);
n.setUserData(ProcessingCapacityNotificationInfoUtil.toCompositeData(info));
osBean.sendNotification(n);
} else if (type == 3) {
// total physical memory changed
TotalPhysicalMemoryNotificationInfo info = new TotalPhysicalMemoryNotificationInfo(data);
// $NON-NLS-1$
Notification n = new Notification(TotalPhysicalMemoryNotificationInfo.TOTAL_PHYSICAL_MEMORY_CHANGE, "java.lang:type=OperatingSystem", sequenceNumber);
n.setUserData(TotalPhysicalMemoryNotificationInfoUtil.toCompositeData(info));
osBean.sendNotification(n);
}
}
use of com.ibm.lang.management.TotalPhysicalMemoryNotificationInfo in project openj9 by eclipse.
the class TestOperatingSystemMXBean method testTotalPhysicalMemoryNotifications.
@Test
public void testTotalPhysicalMemoryNotifications() {
// Register a listener
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(TotalPhysicalMemoryNotificationInfo.TOTAL_PHYSICAL_MEMORY_CHANGE);
MyTestListener listener = new MyTestListener();
this.osb.addNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener receives it.
try {
TotalPhysicalMemoryNotificationInfo info = new TotalPhysicalMemoryNotificationInfo(100 * 1024);
CompositeData cd = TotalPhysicalMemoryNotificationInfoUtil.toCompositeData(info);
Notification notification = new Notification(TotalPhysicalMemoryNotificationInfo.TOTAL_PHYSICAL_MEMORY_CHANGE, new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME), 42);
notification.setUserData(cd);
this.osb.sendNotification(notification);
AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
// Remove the listener
osb.removeNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener does
// *not* receive it.
listener.resetNotificationsReceivedCount();
notification = new Notification(TotalPhysicalMemoryNotificationInfo.TOTAL_PHYSICAL_MEMORY_CHANGE, new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME), 43);
notification.setUserData(cd);
osb.sendNotification(notification);
AssertJUnit.assertEquals(0, listener.getNotificationsReceivedCount());
// ListenerNotFoundException being thrown.
try {
osb.removeNotificationListener(listener, filter, null);
Assert.fail("Should have thrown a ListenerNotFoundException!");
} catch (Exception e) {
AssertJUnit.assertTrue(e instanceof ListenerNotFoundException);
}
} catch (MalformedObjectNameException e) {
e.printStackTrace();
Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
} catch (ListenerNotFoundException e) {
e.printStackTrace();
Assert.fail("Unexpected ListenerNotFoundException : " + e.getMessage());
}
}
use of com.ibm.lang.management.TotalPhysicalMemoryNotificationInfo in project openj9 by eclipse.
the class TestOperatingSystemMXBean method testAddListenerForTotalPhysicalMemoryNotifications.
@Test
public final void testAddListenerForTotalPhysicalMemoryNotifications() {
// Add a listener with a handback object.
MyTestListener listener = new MyTestListener();
ArrayList<String> arr = new ArrayList<String>();
arr.add("Radio ! Live transmission !");
osb.addNotificationListener(listener, null, arr);
// Fire off a notification and ensure that the listener receives it.
try {
TotalPhysicalMemoryNotificationInfo info = new TotalPhysicalMemoryNotificationInfo(100 * 1024);
CompositeData cd = TotalPhysicalMemoryNotificationInfoUtil.toCompositeData(info);
Notification notification = new Notification(TotalPhysicalMemoryNotificationInfo.TOTAL_PHYSICAL_MEMORY_CHANGE, new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME), 42);
notification.setUserData(cd);
this.osb.sendNotification(notification);
AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
// Verify that the handback is as expected.
AssertJUnit.assertNotNull(listener.getHandback());
AssertJUnit.assertSame(arr, listener.getHandback());
ArrayList arr2 = (ArrayList) listener.getHandback();
AssertJUnit.assertTrue(arr2.size() == 1);
AssertJUnit.assertEquals("Radio ! Live transmission !", arr2.get(0));
} catch (MalformedObjectNameException e) {
Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
e.printStackTrace();
}
}
Aggregations