Search in sources :

Example 81 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project openj9 by eclipse.

the class TestOperatingSystemMXBean method testAddListenerForAvailableProcessorNotifications.

@Test
public final void testAddListenerForAvailableProcessorNotifications() {
    // Add a listener with a handback object.
    MyTestListener listener = new MyTestListener();
    ArrayList<String> arr = new ArrayList<String>();
    arr.add("Stone by stone in this big dark forest");
    osb.addNotificationListener(listener, null, arr);
    // 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());
        // 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("Stone by stone in this big dark forest", arr2.get(0));
    } catch (MalformedObjectNameException e) {
        Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) AvailableProcessorsNotificationInfo(com.ibm.lang.management.AvailableProcessorsNotificationInfo) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Example 82 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project openj9 by eclipse.

the class TestManagementFactory method testExtOperatingSystemMXBeanProxyDoesRemoveListeners.

/**
 * For IBM extensions on the OperatingSystemMXBean
 */
@Test
public void testExtOperatingSystemMXBeanProxyDoesRemoveListeners() {
    try {
        com.ibm.lang.management.OperatingSystemMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=OperatingSystem", getOperatingSystemInterface());
        OperatingSystemMXBean stdProxy = proxy;
        AssertJUnit.assertNotNull(stdProxy);
        AssertJUnit.assertFalse(proxy instanceof com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl);
        AssertJUnit.assertTrue(proxy instanceof NotificationEmitter);
        NotificationEmitter proxyEmitter = (NotificationEmitter) proxy;
        MyTestListener listener = new MyTestListener();
        proxyEmitter.addNotificationListener(listener, null, null);
        // Fire off a notification and ensure that the listener receives it.
        try {
            ProcessingCapacityNotificationInfo info = new ProcessingCapacityNotificationInfo(240);
            CompositeData cd = TestUtil.toCompositeData(info);
            Notification notification = new Notification(ProcessingCapacityNotificationInfo.PROCESSING_CAPACITY_CHANGE, new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME), 12);
            notification.setUserData(cd);
            ((ExtendedOperatingSystemMXBeanImpl) (ManagementFactory.getOperatingSystemMXBean())).sendNotification(notification);
            AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
            // Verify the user data of the notification.
            Notification n = listener.getNotification();
            AssertJUnit.assertNotNull(n);
            verifyProcessingCapacityNotificationUserData(n.getUserData());
            // Remove the listener
            proxyEmitter.removeNotificationListener(listener);
            // 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), 13);
            notification.setUserData(cd);
            ((ExtendedOperatingSystemMXBeanImpl) (ManagementFactory.getOperatingSystemMXBean())).sendNotification(notification);
            AssertJUnit.assertEquals(0, listener.getNotificationsReceivedCount());
            // ListenerNotFoundException being thrown.
            try {
                proxyEmitter.removeNotificationListener(listener);
                Assert.fail("Should have thrown a ListenerNotFoundException!");
            } catch (ListenerNotFoundException e) {
                logger.debug("ListenerNotFoundException occurred, as expected: " + e.getMessage());
            }
        } catch (MalformedObjectNameException e) {
            Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
            e.printStackTrace();
        }
    } catch (ListenerNotFoundException e) {
        Assert.fail("Unexpected ListenerNotFoundException : " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        Assert.fail("Unexpected IOException : " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) IOException(java.io.IOException) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) NotificationEmitter(javax.management.NotificationEmitter) ExtendedOperatingSystemMXBeanImpl(com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl) ProcessingCapacityNotificationInfo(com.ibm.lang.management.ProcessingCapacityNotificationInfo) ListenerNotFoundException(javax.management.ListenerNotFoundException) ExtendedOperatingSystemMXBeanImpl(com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Test(org.testng.annotations.Test)

Example 83 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project openj9 by eclipse.

the class TestManagementFactory method testMemoryBeanRegisteredWithServer.

@Test
public final void testMemoryBeanRegisteredWithServer() {
    MBeanServer pServer = ManagementFactory.getPlatformMBeanServer();
    AssertJUnit.assertNotNull(pServer);
    try {
        AssertJUnit.assertTrue(pServer.isRegistered(new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME)));
    } catch (MalformedObjectNameException e) {
        Assert.fail("Unexpected MalformedObjectNameException !");
        e.printStackTrace();
    } catch (NullPointerException e) {
        Assert.fail("Unexpected NullPointerException !");
        e.printStackTrace();
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Example 84 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project openj9 by eclipse.

the class TestManagementFactory method testExtOperatingSystemMXBeanProxyEmitsNotifications.

/**
 * For IBM extension on the OperatingSystemMXBean
 */
@Test
public void testExtOperatingSystemMXBeanProxyEmitsNotifications() {
    try {
        com.ibm.lang.management.OperatingSystemMXBean proxy = ManagementFactory.newPlatformMXBeanProxy(ManagementFactory.getPlatformMBeanServer(), "java.lang:type=OperatingSystem", getOperatingSystemInterface());
        OperatingSystemMXBean stdProxy = proxy;
        AssertJUnit.assertNotNull(stdProxy);
        AssertJUnit.assertFalse(proxy instanceof com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl);
        AssertJUnit.assertTrue(proxy instanceof NotificationEmitter);
        NotificationEmitter proxyEmitter = (NotificationEmitter) proxy;
        // Add a listener with a handback object.
        MyTestListener listener = new MyTestListener();
        ArrayList<String> arr = new ArrayList<>();
        arr.add("Save your money for the children.");
        proxyEmitter.addNotificationListener(listener, null, arr);
        // Fire off a notification and ensure that the listener receives it.
        try {
            ProcessingCapacityNotificationInfo info = new ProcessingCapacityNotificationInfo(24);
            CompositeData cd = TestUtil.toCompositeData(info);
            Notification notification = new Notification(ProcessingCapacityNotificationInfo.PROCESSING_CAPACITY_CHANGE, new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME), 12);
            notification.setUserData(cd);
            ((ExtendedOperatingSystemMXBeanImpl) (ManagementFactory.getOperatingSystemMXBean())).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.assertEquals(1, arr2.size());
            AssertJUnit.assertEquals("Save your money for the children.", arr2.get(0));
        } catch (MalformedObjectNameException e) {
            Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
            e.printStackTrace();
        }
    } catch (IOException e) {
        Assert.fail("Unexpected IOException : " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) NotificationEmitter(javax.management.NotificationEmitter) ExtendedOperatingSystemMXBeanImpl(com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl) ProcessingCapacityNotificationInfo(com.ibm.lang.management.ProcessingCapacityNotificationInfo) ExtendedOperatingSystemMXBeanImpl(com.ibm.lang.management.internal.ExtendedOperatingSystemMXBeanImpl) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) Test(org.testng.annotations.Test)

Example 85 with MalformedObjectNameException

use of javax.management.MalformedObjectNameException in project openj9 by eclipse.

the class TestManagementFactory method testOperatingSystemBeanRegisteredWithServer.

@Test
public final void testOperatingSystemBeanRegisteredWithServer() {
    MBeanServer pServer = ManagementFactory.getPlatformMBeanServer();
    AssertJUnit.assertNotNull(pServer);
    try {
        AssertJUnit.assertTrue(pServer.isRegistered(new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME)));
    } catch (MalformedObjectNameException e) {
        Assert.fail("Unexpected MalformedObjectNameException !");
        e.printStackTrace();
    } catch (NullPointerException e) {
        Assert.fail("Unexpected NullPointerException !");
        e.printStackTrace();
    }
}
Also used : MalformedObjectNameException(javax.management.MalformedObjectNameException) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Aggregations

MalformedObjectNameException (javax.management.MalformedObjectNameException)309 ObjectName (javax.management.ObjectName)285 InstanceNotFoundException (javax.management.InstanceNotFoundException)88 MBeanServer (javax.management.MBeanServer)80 MBeanRegistrationException (javax.management.MBeanRegistrationException)75 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)63 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)59 IOException (java.io.IOException)53 ArrayList (java.util.ArrayList)45 ReflectionException (javax.management.ReflectionException)30 MBeanException (javax.management.MBeanException)23 Test (org.testng.annotations.Test)23 CompositeData (javax.management.openmbean.CompositeData)18 Notification (javax.management.Notification)15 MBeanInfo (javax.management.MBeanInfo)14 AttributeNotFoundException (javax.management.AttributeNotFoundException)13 HashMap (java.util.HashMap)11 Map (java.util.Map)11 IntrospectionException (javax.management.IntrospectionException)11 MalformedURLException (java.net.MalformedURLException)10