use of javax.management.ListenerNotFoundException 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 = TestUtil.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 javax.management.ListenerNotFoundException in project openj9 by eclipse.
the class TestOperatingSystemMXBean method testAvailableProcessorsNotications.
// -----------------------------------------------------------------
// Notification implementation tests follow ....
// -----------------------------------------------------------------
@Test
public void testAvailableProcessorsNotications() {
// Register a listener
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(AvailableProcessorsNotificationInfo.AVAILABLE_PROCESSORS_CHANGE);
MyTestListener listener = new MyTestListener();
this.osb.addNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener receives it.
try {
AvailableProcessorsNotificationInfo info = new AvailableProcessorsNotificationInfo(2);
CompositeData cd = TestUtil.toCompositeData(info);
Notification notification = new Notification(AvailableProcessorsNotificationInfo.AVAILABLE_PROCESSORS_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(AvailableProcessorsNotificationInfo.AVAILABLE_PROCESSORS_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 javax.management.ListenerNotFoundException in project openj9 by eclipse.
the class TestOperatingSystemMXBean method testProcessingCapacityNotications.
@Test
public void testProcessingCapacityNotications() {
// Register a listener
NotificationFilterSupport filter = new NotificationFilterSupport();
filter.enableType(ProcessingCapacityNotificationInfo.PROCESSING_CAPACITY_CHANGE);
MyTestListener listener = new MyTestListener();
this.osb.addNotificationListener(listener, filter, null);
// Fire off a notification and ensure that the listener receives it.
try {
ProcessingCapacityNotificationInfo info = new ProcessingCapacityNotificationInfo(50);
CompositeData cd = TestUtil.toCompositeData(info);
Notification notification = new Notification(ProcessingCapacityNotificationInfo.PROCESSING_CAPACITY_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(ProcessingCapacityNotificationInfo.PROCESSING_CAPACITY_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 javax.management.ListenerNotFoundException in project coprhd-controller by CoprHD.
the class DbRepairRunnable method run.
@Override
public void run() {
try (ScopeNotifier notifier = new ScopeNotifier(this)) {
log.info("prepare db repair");
// use same lock:DB_REPAIR_LOCK for both local/geo db to ensure db repair sequentially
try (InterProcessLockHolder holder = new InterProcessLockHolder(this.coordinator, DB_REPAIR_LOCK, log)) {
log.info("get {} lock, start to do db repair", DB_REPAIR_LOCK);
this.status = getRepairStatus(holder.getLock());
if (this.status != StartStatus.STARTED) {
return;
}
try (RepairJobRunner runner = createJobRunner(jmxServer)) {
// Save state to ZK before notify caller to return so it will see the result of call.
saveStates();
log.info("Repair started, notifying the triggering thread to return.");
// Notify the thread triggering the repair before we finish
notifier.close();
int repairDelay = 0;
while (true) {
ScheduledFuture<Boolean> repairTask = executor.schedule(new Callable<Boolean>() {
@Override
public Boolean call() {
boolean needRetry = false;
try {
RepairJobRunner.RepairJobStatus repairJobStatus = runner.runRepair();
needRetry = checkRepairStatus(repairJobStatus);
} catch (IOException | InterruptedException ex) {
log.error("Repair job failed with exception", ex);
}
return needRetry;
}
}, repairDelay, TimeUnit.MINUTES);
while (!repairTask.isDone()) {
log.debug("Waiting repair task finish...");
Thread.sleep(60 * 1000L);
}
log.info("Repair need retry: {}", repairTask.get());
if (!repairTask.get()) {
break;
}
repairDelay = repairRetryMin;
}
} catch (ListenerNotFoundException ex) {
this.threadException = ex;
log.error("Failed to remove notification listener", ex);
}
} catch (Exception ex) {
this.threadException = ex;
log.error("Exception starting", ex);
}
} catch (Exception ex) {
this.threadException = ex;
log.error("Exception starting", ex);
}
}
Aggregations