Search in sources :

Example 31 with ListenerNotFoundException

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());
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) TotalPhysicalMemoryNotificationInfo(com.ibm.lang.management.TotalPhysicalMemoryNotificationInfo) CompositeData(javax.management.openmbean.CompositeData) NotificationFilterSupport(javax.management.NotificationFilterSupport) ListenerNotFoundException(javax.management.ListenerNotFoundException) Notification(javax.management.Notification) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Example 32 with ListenerNotFoundException

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());
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) NotificationFilterSupport(javax.management.NotificationFilterSupport) ListenerNotFoundException(javax.management.ListenerNotFoundException) AvailableProcessorsNotificationInfo(com.ibm.lang.management.AvailableProcessorsNotificationInfo) Notification(javax.management.Notification) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Example 33 with ListenerNotFoundException

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());
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) ProcessingCapacityNotificationInfo(com.ibm.lang.management.ProcessingCapacityNotificationInfo) NotificationFilterSupport(javax.management.NotificationFilterSupport) ListenerNotFoundException(javax.management.ListenerNotFoundException) Notification(javax.management.Notification) AttributeNotFoundException(javax.management.AttributeNotFoundException) IntrospectionException(javax.management.IntrospectionException) InstanceNotFoundException(javax.management.InstanceNotFoundException) ReflectionException(javax.management.ReflectionException) MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanException(javax.management.MBeanException) ListenerNotFoundException(javax.management.ListenerNotFoundException) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Example 34 with ListenerNotFoundException

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);
    }
}
Also used : InterProcessLockHolder(com.emc.storageos.coordinator.client.service.InterProcessLockHolder) ListenerNotFoundException(javax.management.ListenerNotFoundException) IOException(java.io.IOException) ListenerNotFoundException(javax.management.ListenerNotFoundException)

Aggregations

ListenerNotFoundException (javax.management.ListenerNotFoundException)34 ObjectName (javax.management.ObjectName)13 Notification (javax.management.Notification)11 NotificationEmitter (javax.management.NotificationEmitter)10 MalformedObjectNameException (javax.management.MalformedObjectNameException)9 InstanceNotFoundException (javax.management.InstanceNotFoundException)8 CompositeData (javax.management.openmbean.CompositeData)8 Test (org.testng.annotations.Test)8 IOException (java.io.IOException)5 NotificationFilterSupport (javax.management.NotificationFilterSupport)5 MemoryNotificationInfo (java.lang.management.MemoryNotificationInfo)4 MemoryUsage (java.lang.management.MemoryUsage)4 MBeanException (javax.management.MBeanException)4 NotificationListener (javax.management.NotificationListener)4 ReflectionException (javax.management.ReflectionException)4 MemoryMXBean (java.lang.management.MemoryMXBean)3 ArrayList (java.util.ArrayList)3 AttributeNotFoundException (javax.management.AttributeNotFoundException)3 IntrospectionException (javax.management.IntrospectionException)3 MemoryMXBeanImpl (com.ibm.java.lang.management.internal.MemoryMXBeanImpl)2