Search in sources :

Example 1 with MemoryNotificationInfo

use of java.lang.management.MemoryNotificationInfo in project jdk8u_jdk by JetBrains.

the class MemoryNotifInfoCompositeData method badNameCompositeData.

public static void badNameCompositeData() throws Exception {
    CompositeType ct = new CompositeType("MyCompositeType", "CompositeType for MemoryNotificationInfo", badItemNames, badItemNames, validItemTypes);
    CompositeData cd = new CompositeDataSupport(ct, badItemNames, values);
    try {
        MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
    } catch (IllegalArgumentException e) {
        System.out.println("Expected exception: " + e.getMessage());
        return;
    }
    throw new RuntimeException("IllegalArgumentException not thrown");
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) MemoryUsageCompositeData(sun.management.MemoryUsageCompositeData)

Example 2 with MemoryNotificationInfo

use of java.lang.management.MemoryNotificationInfo in project jdk8u_jdk by JetBrains.

the class MemoryNotifInfoCompositeData method createGoodCompositeData.

public static void createGoodCompositeData() throws Exception {
    // get the CompositeType for MemoryUsage
    validItemTypes[USAGE] = OpenTypeConverter.toOpenType(MemoryUsage.class);
    CompositeType ct = new CompositeType("MyCompositeType", "CompositeType for MemoryNotificationInfo", validItemNames, validItemNames, validItemTypes);
    CompositeData cd = new CompositeDataSupport(ct, validItemNames, values);
    MemoryNotificationInfo info = MemoryNotificationInfo.from(cd);
    if (!info.getPoolName().equals(values[POOL_NAME])) {
        throw new RuntimeException("pool name = " + info.getPoolName() + " expected = " + values[POOL_NAME]);
    }
    if (info.getCount() != ((Long) values[COUNT]).longValue()) {
        throw new RuntimeException("count = " + info.getCount() + " expected = " + values[COUNT]);
    }
    if (info.getUsage().getInit() != 0) {
        throw new RuntimeException("usage init = " + info.getUsage().getInit() + " expected = 0");
    }
    if (info.getUsage().getUsed() != 100) {
        throw new RuntimeException("usage used = " + info.getUsage().getUsed() + " expected = 100");
    }
    if (info.getUsage().getCommitted() != 1000) {
        throw new RuntimeException("usage committed = " + info.getUsage().getCommitted() + " expected = 1000");
    }
    if (info.getUsage().getMax() != 5000) {
        throw new RuntimeException("usage max = " + info.getUsage().getMax() + " expected = 5000");
    }
    System.out.print("Pool name = " + info.getPoolName());
    System.out.println(" Count = " + info.getCount());
    System.out.println("Usage = " + info.getUsage());
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) MemoryUsageCompositeData(sun.management.MemoryUsageCompositeData) MemoryUsage(java.lang.management.MemoryUsage)

Example 3 with MemoryNotificationInfo

use of java.lang.management.MemoryNotificationInfo in project jdk8u_jdk by JetBrains.

the class MemoryImpl method createNotification.

static void createNotification(String notifType, String poolName, MemoryUsage usage, long count) {
    MemoryImpl mbean = (MemoryImpl) ManagementFactory.getMemoryMXBean();
    if (!mbean.hasListeners()) {
        // if no listener is registered.
        return;
    }
    long timestamp = System.currentTimeMillis();
    String msg = getNotifMsg(notifType);
    Notification notif = new Notification(notifType, mbean.getObjectName(), getNextSeqNumber(), timestamp, msg);
    MemoryNotificationInfo info = new MemoryNotificationInfo(poolName, usage, count);
    CompositeData cd = MemoryNotifInfoCompositeData.toCompositeData(info);
    notif.setUserData(cd);
    mbean.sendNotification(notif);
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) CompositeData(javax.management.openmbean.CompositeData) Notification(javax.management.Notification)

Example 4 with MemoryNotificationInfo

use of java.lang.management.MemoryNotificationInfo in project openj9 by eclipse.

the class MemoryNotificationThread method dispatchMemoryNotificationHelper.

/**
 * A helper used by processNotificationLoop to construct and dispatch
 * memory threshold notification objects
 *
 * @param poolName
 *            the name of pool which we are sending notifications on behalf of
 * @param min
 *            the initial amount in bytes of memory that can be allocated by
 *            this virtual machine
 * @param used
 *            the number of bytes currently used for memory
 * @param committed
 *            the number of bytes of committed memory
 * @param max
 *            the maximum number of bytes that can be used for memory
 *            management purposes
 * @param count
 *            the number of times that the memory usage of the memory pool
 *            in question has met or exceeded the relevant threshold
 * @param sequenceNumber
 *            the sequence identifier of the current notification
 * @param isCollectionUsageNotification
 *            a <code>boolean</code> indication of whether or not the new
 *            notification is as a result of the collection threshold being
 *            exceeded. If this value is <code>false</code> then the
 *            implication is that a memory threshold has been exceeded.
 */
private void dispatchMemoryNotificationHelper(String poolName, long min, long used, long committed, long max, long count, long sequenceNumber, boolean isCollectionUsageNotification) {
    MemoryNotificationInfo info = new MemoryNotificationInfo(poolName, new MemoryUsage(min, used, committed, max), count);
    Notification notification = new Notification(isCollectionUsageNotification ? MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED : MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, // $NON-NLS-1$
    "java.lang:type=Memory", sequenceNumber);
    notification.setUserData(MemoryNotificationInfoUtil.toCompositeData(info));
    memBean.sendNotification(notification);
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) MemoryUsage(java.lang.management.MemoryUsage) Notification(javax.management.Notification)

Example 5 with MemoryNotificationInfo

use of java.lang.management.MemoryNotificationInfo in project openj9 by eclipse.

the class MyTestListener method testRemoveNotificationListenerNotificationListener.

/*
	 * Class under test for void
	 * removeNotificationListener(NotificationListener)
	 */
@Test
public final void testRemoveNotificationListenerNotificationListener() {
    // Add a listener without a filter object.
    MyTestListener listener = new MyTestListener();
    mb.addNotificationListener(listener, null, null);
    // Fire off a notification and ensure that the listener receives it.
    try {
        MemoryUsage mu = new MemoryUsage(1, 2, 3, 4);
        MemoryNotificationInfo info = new MemoryNotificationInfo("Tim", mu, 42);
        CompositeData cd = TestUtil.toCompositeData(info);
        Notification notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 42);
        notification.setUserData(cd);
        mb.sendNotification(notification);
        AssertJUnit.assertEquals(1, listener.getNotificationsReceivedCount());
        // Verify that the handback is as expected.
        AssertJUnit.assertNull(listener.getHandback());
        // Verify the user data of the notification.
        Notification n = listener.getNotification();
        AssertJUnit.assertNotNull(n);
        verifyNotificationUserData(n.getUserData());
        // Remove the listener
        mb.removeNotificationListener(listener);
        // Fire off a notification and ensure that the listener does
        // *not* receive it.
        listener.resetNotificationsReceivedCount();
        notification = new Notification(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED, new ObjectName(ManagementFactory.MEMORY_MXBEAN_NAME), 43);
        notification.setUserData(cd);
        mb.sendNotification(notification);
        AssertJUnit.assertEquals(0, listener.getNotificationsReceivedCount());
        // ListenerNotFoundException being thrown.
        try {
            mb.removeNotificationListener(listener);
            Assert.fail("Should have thrown a ListenerNotFoundException!");
        } catch (ListenerNotFoundException e) {
        }
    } catch (MalformedObjectNameException e) {
        Assert.fail("Unexpected MalformedObjectNameException : " + e.getMessage());
        e.printStackTrace();
    } catch (ListenerNotFoundException e) {
        Assert.fail("Unexpected ListenerNotFoundException : " + e.getMessage());
        e.printStackTrace();
    }
}
Also used : MemoryNotificationInfo(java.lang.management.MemoryNotificationInfo) MalformedObjectNameException(javax.management.MalformedObjectNameException) CompositeData(javax.management.openmbean.CompositeData) ListenerNotFoundException(javax.management.ListenerNotFoundException) MemoryUsage(java.lang.management.MemoryUsage) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.testng.annotations.Test)

Aggregations

MemoryNotificationInfo (java.lang.management.MemoryNotificationInfo)16 MemoryUsage (java.lang.management.MemoryUsage)11 CompositeData (javax.management.openmbean.CompositeData)11 Notification (javax.management.Notification)10 Test (org.testng.annotations.Test)8 MalformedObjectNameException (javax.management.MalformedObjectNameException)7 ObjectName (javax.management.ObjectName)7 IOException (java.io.IOException)5 MemoryMXBeanImpl (com.ibm.java.lang.management.internal.MemoryMXBeanImpl)4 MemoryMXBean (java.lang.management.MemoryMXBean)4 ListenerNotFoundException (javax.management.ListenerNotFoundException)4 NotificationEmitter (javax.management.NotificationEmitter)4 ArrayList (java.util.ArrayList)3 MemoryUsageCompositeData (sun.management.MemoryUsageCompositeData)3 LowMemoryHandler (com.sun.btrace.shared.LowMemoryHandler)1 NotificationFilterSupport (javax.management.NotificationFilterSupport)1 NotificationListener (javax.management.NotificationListener)1 NotifyDescriptor (org.openide.NotifyDescriptor)1 BeforeClass (org.testng.annotations.BeforeClass)1