Java Code Examples for java.lang.management.MemoryNotificationInfo

The following are top voted examples for showing how to use java.lang.management.MemoryNotificationInfo. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: jdk8u-jdk   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 2
Project: jdk8u-jdk   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 3
Project: openjdk-jdk10   File: PoolsIndependenceTest.java   Source Code and License 6 votes vote down vote up
@Override
public void handleNotification(Notification notification, Object handback) {
    String nType = notification.getType();
    String poolName
            = CodeCacheUtils.getPoolNameFromNotification(notification);
    // consider code cache events only
    if (CodeCacheUtils.isAvailableCodeHeapPoolName(poolName)) {
        Asserts.assertEQ(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
                nType, "Unexpected event received: " + nType);
        // receiving events from available CodeCache-related beans only
        if (counters.get(poolName) != null) {
            counters.get(poolName).incrementAndGet();
            lastEventTimestamp = System.currentTimeMillis();
        }
    }
}
 
Example 4
Project: openjdk-jdk10   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 5
Project: openjdk-jdk10   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 6
Project: openjdk9   File: PoolsIndependenceTest.java   Source Code and License 6 votes vote down vote up
@Override
public void handleNotification(Notification notification, Object handback) {
    String nType = notification.getType();
    String poolName
            = CodeCacheUtils.getPoolNameFromNotification(notification);
    // consider code cache events only
    if (CodeCacheUtils.isAvailableCodeHeapPoolName(poolName)) {
        Asserts.assertEQ(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED,
                nType, "Unexpected event received: " + nType);
        // receiving events from available CodeCache-related beans only
        if (counters.get(poolName) != null) {
            counters.get(poolName).incrementAndGet();
            lastEventTimestamp = System.currentTimeMillis();
        }
    }
}
 
Example 7
Project: openjdk9   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 8
Project: openjdk9   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 9
Project: jdk8u_jdk   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 10
Project: jdk8u_jdk   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 11
Project: lookaside_java-1.8.0-openjdk   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 12
Project: lookaside_java-1.8.0-openjdk   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 13
Project: kc-rice   File: MemoryMonitor.java   Source Code and License 6 votes vote down vote up
public MemoryMonitor() {
    LOG.info("initializing");
    this.springContextId = "Unknown";
    MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    emitter.addNotificationListener(new NotificationListener() {
        public void handleNotification(Notification n, Object hb) {
            if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
                long maxMemory = tenuredGenPool.getUsage().getMax();
                long usedMemory = tenuredGenPool.getUsage().getUsed();
                for (Listener listener : listeners) {
                    listener.memoryUsageLow(springContextId, usedMemory, maxMemory);
                }
            }
        }
    }, null, null);
}
 
Example 14
Project: mobac   File: MemoryTileCache.java   Source Code and License 6 votes vote down vote up
/**
 * In case we are running out of memory we free half of the cached down to a minimum of 25 cached tiles.
 */
public void handleNotification(Notification notification, Object handback) {
	log.trace("Memory notification: " + notification.toString());
	if (!MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED.equals(notification.getType()))
		return;
	synchronized (lruTiles) {
		int count_half = lruTiles.getElementCount() / 2;
		count_half = Math.max(25, count_half);
		if (lruTiles.getElementCount() <= count_half)
			return;
		log.warn("memory low - freeing cached tiles: " + lruTiles.getElementCount() + " -> " + count_half);
		try {
			while (lruTiles.getElementCount() > count_half) {
				removeEntry(lruTiles.getLastElement());
			}
		} catch (Exception e) {
			log.error("", e);
		}
	}
}
 
Example 15
Project: chai   File: MemoryNotifier.java   Source Code and License 6 votes vote down vote up
@Override
public void handleNotification(Notification notification, Object handback) {
  if(!notification.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) return;
  logger.info("MemoryNotifier::activate");

  //--- copy the list of listener's  in a thread-safe way; doesn't matter if we get an update while we're notifying this way.
  final List<Flushable> toNotify = new ArrayList<>();
  synchronized (instance) {
    toNotify.addAll(listeners);
  }

  //--- spawn a thread to handle flushing; don't do multiple because threads can be heavy on the memory usage.
  Thread deferred = new Thread() {
    public void run() {
      for (final Flushable flushable : toNotify) {
        try {
          flushable.flush();
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
    }
  };
  deferred.start();
}
 
Example 16
Project: infobip-open-jdk-8   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 17
Project: infobip-open-jdk-8   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 18
Project: jdk8u-dev-jdk   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 19
Project: jdk8u-dev-jdk   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 20
Project: galagosearch   File: Sorter.java   Source Code and License 6 votes vote down vote up
public void handleNotification(Notification notification, Object handback) {
    if (notification.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
        flushRequested = true;
        final Sorter f = this;

        Thread t = new Thread() {
            @Override
            public void run() {
                try {
                    f.flush();
                } catch (IOException e) {
                    logger.severe(e.toString());
                }
            }
        };

        t.start();
    }
}
 
Example 21
Project: jdk7-jdk   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 22
Project: jdk7-jdk   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 23
Project: openjdk-source-code-learn   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 24
Project: openjdk-source-code-learn   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 25
Project: OLE-INST   File: MemoryMonitor.java   Source Code and License 6 votes vote down vote up
public MemoryMonitor() {
    LOG.info("initializing");
    this.springContextId = "Unknown";
    ManagementFactory.getThreadMXBean().setThreadContentionMonitoringEnabled(true);
    ManagementFactory.getThreadMXBean().setThreadCpuTimeEnabled(true);
    lowMemoryListener = new NotificationListener() {
        public void handleNotification(Notification n, Object hb) {
            if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
                Map<String, String> memoryUsageStatistics = new HashMap<String, String>();
                memoryUsageStatistics.put("MemoryMXBean: " + MemoryType.HEAP, ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().toString());
                memoryUsageStatistics.put("MemoryMXBean:" + MemoryType.NON_HEAP, ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().toString());
                for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
                    memoryUsageStatistics.put("MemoryPoolMXBean: " + pool.getType(), pool.getUsage().toString());
                }
                for (Listener listener : listeners) {
                    listener.memoryUsageLow(springContextId, memoryUsageStatistics, Arrays.toString(ManagementFactory.getThreadMXBean().findMonitorDeadlockedThreads()));
                }
            }
        }
    };
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(lowMemoryListener, null, null);
}
 
Example 26
Project: OLD-OpenJDK8   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 27
Project: OLD-OpenJDK8   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 28
Project: cn1   File: ManagementUtils.java   Source Code and License 6 votes vote down vote up
/**
 * @return an instance of {@link CompositeType}for the
 *         {@link MemoryNotificationInfo}class.
 */
private static CompositeType getMemoryNotificationInfoCompositeType() {
    if (MEMORYNOTIFICATIONINFO_COMPOSITETYPE == null) {
        String[] typeNames = { "poolName", "usage", "count" };
        String[] typeDescs = { "poolName", "usage", "count" };
        OpenType[] typeTypes = { SimpleType.STRING,
                getMemoryUsageCompositeType(), SimpleType.LONG };
        try {
            MEMORYNOTIFICATIONINFO_COMPOSITETYPE = new CompositeType(
                    MemoryNotificationInfo.class.getName(),
                    MemoryNotificationInfo.class.getName(), typeNames,
                    typeDescs, typeTypes);
        } catch (OpenDataException e) {
            if (ManagementUtils.VERBOSE_MODE) {
                e.printStackTrace(System.err);
            }// end if
        }
    }
    return MEMORYNOTIFICATIONINFO_COMPOSITETYPE;
}
 
Example 29
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from() {
    final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4);
    final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42);
    
    CompositeData compositeData = ManagementUtils
            .toMemoryNotificationInfoCompositeData(memoryNotifyInfo);
    MemoryNotificationInfo fromInfo = MemoryNotificationInfo
            .from(compositeData);
    assertEquals(memoryNotifyInfo.getPoolName(), fromInfo.getPoolName());
    assertEquals(memoryNotifyInfo.getCount(), fromInfo.getCount());

    MemoryUsage fromUsage = fromInfo.getUsage();
    assertEquals(memoryUsage.getInit(), fromUsage.getInit());
    assertEquals(memoryUsage.getMax(), fromUsage.getMax());
    assertEquals(memoryUsage.getUsed(), fromUsage.getUsed());
    assertEquals(memoryUsage.getCommitted(), fromUsage.getCommitted());
}
 
Example 30
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario3() throws Exception {
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { "TestPoolName", null, null };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
        // Expected
    }
}
 
Example 31
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario4() throws Exception { // add
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { "TestPoolName", memoryCompositeData, new Long(-42) };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
    assertEquals(values[0], info.getPoolName());
    assertEquals(values[2], info.getCount());
    MemoryUsage usage = info.getUsage();
    assertEquals(1, usage.getInit());
    assertEquals(2, usage.getUsed());
    assertEquals(3, usage.getCommitted());
    assertEquals(4, usage.getMax());
}
 
Example 32
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario5() throws Exception {
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { new Long(1), memoryCompositeData, new Long(42) };
    OpenType[] types = { SimpleType.LONG, memoryUsageCompositeType,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
 
Example 33
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario6() throws Exception {
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { "TestPoolName", new Long(1), new Long(42) };
    OpenType[] types = { SimpleType.STRING, SimpleType.LONG,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
 
Example 34
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario7() throws Exception {
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { "TestPoolName", memoryCompositeData, "42" };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.STRING };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
 
Example 35
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario11() throws Exception {
    String[] names = { "notPoolName", "usage", "count" };
    Object[] values = { "TestNotPoolName", memoryCompositeData,
            new Long(42) };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
 
Example 36
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario12() throws Exception {
    String[] names = { "poolName", "usage", "count", "extention" };
    Object[] values = { "TestPoolName", memoryCompositeData, new Long(42),
            null };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG, SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
    assertEquals(values[0], info.getPoolName());
    assertEquals(values[2], info.getCount());
    MemoryUsage usage = info.getUsage();
    assertEquals(1, usage.getInit());
    assertEquals(2, usage.getUsed());
    assertEquals(3, usage.getCommitted());
    assertEquals(4, usage.getMax());
}
 
Example 37
Project: cn1   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario13() throws Exception {
    String[] names = { "poolName", "usage", "count", "extention" };
    Object[] values = { "TestPoolName", memoryCompositeData, new Long(42),
            "Extention" };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG, SimpleType.STRING };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
    assertEquals(values[0], info.getPoolName());
    assertEquals(values[2], info.getCount());
    MemoryUsage usage = info.getUsage();
    assertEquals(1, usage.getInit());
    assertEquals(2, usage.getUsed());
    assertEquals(3, usage.getCommitted());
    assertEquals(4, usage.getMax());
}
 
Example 38
Project: cn1   File: MemoryMXBeanImplTest.java   Source Code and License 6 votes vote down vote up
public final void testGetNotificationInfo() {
    MBeanNotificationInfo[] notifications = notifierBean
            .getNotificationInfo();
    assertNotNull(notifications);
    assertTrue(notifications.length > 0);
    for (int i = 0; i < notifications.length; i++) {
        MBeanNotificationInfo info = notifications[i];
        assertEquals(Notification.class.getName(), info.getName());
        assertEquals("Memory Notification", info.getDescription());
        String[] types = info.getNotifTypes();
        for (int j = 0; j < types.length; j++) {
            String type = types[j];
            assertTrue(type
                    .equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
                    || type
                            .equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED));

        }// end for
    }// end for
}
 
Example 39
Project: kfs   File: MemoryMonitor.java   Source Code and License 6 votes vote down vote up
public MemoryMonitor() {
    LOG.info("initializing");
    this.springContextId = "Unknown";
    ManagementFactory.getThreadMXBean().setThreadContentionMonitoringEnabled(true);
    ManagementFactory.getThreadMXBean().setThreadCpuTimeEnabled(true);
    lowMemoryListener = new NotificationListener() {
        public void handleNotification(Notification n, Object hb) {
            if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
                Map<String, String> memoryUsageStatistics = new HashMap<String, String>();
                memoryUsageStatistics.put("MemoryMXBean: " + MemoryType.HEAP, ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().toString());
                memoryUsageStatistics.put("MemoryMXBean:" + MemoryType.NON_HEAP, ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().toString());
                for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
                    memoryUsageStatistics.put("MemoryPoolMXBean: " + pool.getType(), pool.getUsage().toString());
                }
                for (Listener listener : listeners) {
                    listener.memoryUsageLow(springContextId, memoryUsageStatistics, Arrays.toString(ManagementFactory.getThreadMXBean().findMonitorDeadlockedThreads()));
                }
            }
        }
    };
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(lowMemoryListener, null, null);
}
 
Example 40
Project: tigase-server   File: MemMonitor.java   Source Code and License 6 votes vote down vote up
@Override
public void handleNotification(Notification note, Object handback) {
	if (note.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
		log.info("Usage threshold exceeded, sending notification.");
		NumberFormat format = NumberFormat.getIntegerInstance();
		if (format instanceof DecimalFormat) {
			DecimalFormat decf = (DecimalFormat) format;
			decf.applyPattern(decf.toPattern() + " KB");
		}
		MemoryPoolMXBean memoryPoolMXBean = (MemoryPoolMXBean) handback;
		String message = "Threshold " +
						format.format(memoryPoolMXBean.getUsageThreshold() / 1024) +
						" for memory pool: " + memoryPoolMXBean.getName() +
						", type: " + memoryPoolMXBean.getType().toString() +
						" exceeded.";
		sendWarningOut(message, handback);
	}
}
 
Example 41
Project: JAVA_UNIT   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 42
Project: openjdk-jdk7u-jdk   File: MemoryImpl.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 43
Project: openjdk-jdk7u-jdk   File: MemoryNotifInfoCompositeData.java   Source Code and License 6 votes vote down vote up
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");
}
 
Example 44
Project: rice   File: MemoryMonitor.java   Source Code and License 6 votes vote down vote up
public MemoryMonitor() {
    LOG.info("initializing");
    this.springContextId = "Unknown";
    MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    emitter.addNotificationListener(new NotificationListener() {
        public void handleNotification(Notification n, Object hb) {
            if (n.getType().equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
                long maxMemory = tenuredGenPool.getUsage().getMax();
                long usedMemory = tenuredGenPool.getUsage().getUsed();
                for (Listener listener : listeners) {
                    listener.memoryUsageLow(springContextId, usedMemory, maxMemory);
                }
            }
        }
    }, null, null);
}
 
Example 45
Project: maven-framework-project   File: MemoryWarningService.java   Source Code and License 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void handleNotification(Notification notification, Object handback) {

	if (notification.getType().equals(
			MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)) {
		long maxMemory = tenuredGenPool.getUsage().getMax();
		long usedMemory = tenuredGenPool.getUsage().getUsed();
		LOG.warn("Memory usage low!!!");
		double percentageUsed = (double) usedMemory / maxMemory;
		LOG.warn("percentageUsed = " + percentageUsed);
		threadDumper.dumpStacks();

	} else {
		LOG.info("Other notification received..."
				+ notification.getMessage());
	}

}
 
Example 46
Project: freeVM   File: ManagementUtils.java   Source Code and License 6 votes vote down vote up
/**
 * @param info
 *            a {@link java.lang.management.MemoryNotificationInfo}object.
 * @return a {@link CompositeData}object that represents the supplied
 *         <code>info</code> object.
 */
public static CompositeData toMemoryNotificationInfoCompositeData(
        MemoryNotificationInfo info) {
    // Bail out early on null input.
    if (info == null) {
        return null;
    }

    CompositeData result = null;
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { new String(info.getPoolName()),
            toMemoryUsageCompositeData(info.getUsage()),
            new Long(info.getCount()) };
    CompositeType cType = getMemoryNotificationInfoCompositeType();
    try {
        result = new CompositeDataSupport(cType, names, values);
    } catch (OpenDataException e) {
        if (ManagementUtils.VERBOSE_MODE) {
            e.printStackTrace(System.err);
        }// end if
    }
    return result;
}
 
Example 47
Project: freeVM   File: ManagementUtils.java   Source Code and License 6 votes vote down vote up
/**
 * @return an instance of {@link CompositeType}for the
 *         {@link MemoryNotificationInfo}class.
 */
private static CompositeType getMemoryNotificationInfoCompositeType() {
    if (MEMORYNOTIFICATIONINFO_COMPOSITETYPE == null) {
        String[] typeNames = { "poolName", "usage", "count" };
        String[] typeDescs = { "poolName", "usage", "count" };
        OpenType[] typeTypes = { SimpleType.STRING,
                getMemoryUsageCompositeType(), SimpleType.LONG };
        try {
            MEMORYNOTIFICATIONINFO_COMPOSITETYPE = new CompositeType(
                    MemoryNotificationInfo.class.getName(),
                    MemoryNotificationInfo.class.getName(), typeNames,
                    typeDescs, typeTypes);
        } catch (OpenDataException e) {
            if (ManagementUtils.VERBOSE_MODE) {
                e.printStackTrace(System.err);
            }// end if
        }
    }
    return MEMORYNOTIFICATIONINFO_COMPOSITETYPE;
}
 
Example 48
Project: freeVM   File: MemoryMXBeanImplTest.java   Source Code and License 6 votes vote down vote up
public final void testGetNotificationInfo() {
    MBeanNotificationInfo[] notifications = notifierBean
            .getNotificationInfo();
    assertNotNull(notifications);
    assertTrue(notifications.length > 0);
    for (int i = 0; i < notifications.length; i++) {
        MBeanNotificationInfo info = notifications[i];
        assertEquals(Notification.class.getName(), info.getName());
        assertEquals("Memory Notification", info.getDescription());
        String[] types = info.getNotifTypes();
        for (int j = 0; j < types.length; j++) {
            String type = types[j];
            assertTrue(type
                    .equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
                    || type
                            .equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED));

        }// end for
    }// end for
}
 
Example 49
Project: freeVM   File: ManagementUtils.java   Source Code and License 6 votes vote down vote up
/**
 * @param info
 *            a {@link java.lang.management.MemoryNotificationInfo}object.
 * @return a {@link CompositeData}object that represents the supplied
 *         <code>info</code> object.
 */
public static CompositeData toMemoryNotificationInfoCompositeData(
        MemoryNotificationInfo info) {
    // Bail out early on null input.
    if (info == null) {
        return null;
    }

    CompositeData result = null;
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { info.getPoolName(),
            toMemoryUsageCompositeData(info.getUsage()),
            Long.valueOf(info.getCount()) };
    CompositeType cType = getMemoryNotificationInfoCompositeType();
    try {
        result = new CompositeDataSupport(cType, names, values);
    } catch (OpenDataException e) {
        if (ManagementUtils.VERBOSE_MODE) {
            e.printStackTrace(System.err);
        }// end if
    }
    return result;
}
 
Example 50
Project: freeVM   File: ManagementUtils.java   Source Code and License 6 votes vote down vote up
/**
 * @return an instance of {@link CompositeType}for the
 *         {@link MemoryNotificationInfo}class.
 */
private static CompositeType getMemoryNotificationInfoCompositeType() {
    if (MEMORYNOTIFICATIONINFO_COMPOSITETYPE == null) {
        String[] typeNames = { "poolName", "usage", "count" };
        String[] typeDescs = { "poolName", "usage", "count" };
        OpenType[] typeTypes = { SimpleType.STRING,
                getMemoryUsageCompositeType(), SimpleType.LONG };
        try {
            MEMORYNOTIFICATIONINFO_COMPOSITETYPE = new CompositeType(
                    MemoryNotificationInfo.class.getName(),
                    MemoryNotificationInfo.class.getName(), typeNames,
                    typeDescs, typeTypes);
        } catch (OpenDataException e) {
            if (ManagementUtils.VERBOSE_MODE) {
                e.printStackTrace(System.err);
            }// end if
        }
    }
    return MEMORYNOTIFICATIONINFO_COMPOSITETYPE;
}
 
Example 51
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from() {
    final MemoryUsage memoryUsage = new MemoryUsage(1, 2, 3, 4);
    final MemoryNotificationInfo memoryNotifyInfo = new MemoryNotificationInfo("Lloyd", memoryUsage, 42);
    
    CompositeData compositeData = ManagementUtils
            .toMemoryNotificationInfoCompositeData(memoryNotifyInfo);
    MemoryNotificationInfo fromInfo = MemoryNotificationInfo
            .from(compositeData);
    assertEquals(memoryNotifyInfo.getPoolName(), fromInfo.getPoolName());
    assertEquals(memoryNotifyInfo.getCount(), fromInfo.getCount());

    MemoryUsage fromUsage = fromInfo.getUsage();
    assertEquals(memoryUsage.getInit(), fromUsage.getInit());
    assertEquals(memoryUsage.getMax(), fromUsage.getMax());
    assertEquals(memoryUsage.getUsed(), fromUsage.getUsed());
    assertEquals(memoryUsage.getCommitted(), fromUsage.getCommitted());
}
 
Example 52
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario3() throws Exception {
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { "TestPoolName", null, null };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw NullPointerException");
    } catch (NullPointerException e) {
        // Expected
    }
}
 
Example 53
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario4() throws Exception { // add
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { "TestPoolName", memoryCompositeData, new Long(-42) };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
    assertEquals(values[0], info.getPoolName());
    assertEquals(values[2], info.getCount());
    MemoryUsage usage = info.getUsage();
    assertEquals(1, usage.getInit());
    assertEquals(2, usage.getUsed());
    assertEquals(3, usage.getCommitted());
    assertEquals(4, usage.getMax());
}
 
Example 54
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario5() throws Exception {
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { new Long(1), memoryCompositeData, new Long(42) };
    OpenType[] types = { SimpleType.LONG, memoryUsageCompositeType,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
 
Example 55
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario6() throws Exception {
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { "TestPoolName", new Long(1), new Long(42) };
    OpenType[] types = { SimpleType.STRING, SimpleType.LONG,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
 
Example 56
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario7() throws Exception {
    String[] names = { "poolName", "usage", "count" };
    Object[] values = { "TestPoolName", memoryCompositeData, "42" };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.STRING };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
 
Example 57
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario11() throws Exception {
    String[] names = { "notPoolName", "usage", "count" };
    Object[] values = { "TestNotPoolName", memoryCompositeData,
            new Long(42) };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    try {
        MemoryNotificationInfo.from(data);
        fail("should throw IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // Expected
    }
}
 
Example 58
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario12() throws Exception {
    String[] names = { "poolName", "usage", "count", "extention" };
    Object[] values = { "TestPoolName", memoryCompositeData, new Long(42),
            null };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG, SimpleType.LONG };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
    assertEquals(values[0], info.getPoolName());
    assertEquals(values[2], info.getCount());
    MemoryUsage usage = info.getUsage();
    assertEquals(1, usage.getInit());
    assertEquals(2, usage.getUsed());
    assertEquals(3, usage.getCommitted());
    assertEquals(4, usage.getMax());
}
 
Example 59
Project: freeVM   File: MemoryNotificationInfoTest.java   Source Code and License 6 votes vote down vote up
public void test_from_scenario13() throws Exception {
    String[] names = { "poolName", "usage", "count", "extention" };
    Object[] values = { "TestPoolName", memoryCompositeData, new Long(42),
            "Extention" };
    OpenType[] types = { SimpleType.STRING, memoryUsageCompositeType,
            SimpleType.LONG, SimpleType.STRING };

    CompositeType compositeType = getCompositeType(names, types);
    CompositeData data = new CompositeDataSupport(compositeType, names,
            values);
    MemoryNotificationInfo info = MemoryNotificationInfo.from(data);
    assertEquals(values[0], info.getPoolName());
    assertEquals(values[2], info.getCount());
    MemoryUsage usage = info.getUsage();
    assertEquals(1, usage.getInit());
    assertEquals(2, usage.getUsed());
    assertEquals(3, usage.getCommitted());
    assertEquals(4, usage.getMax());
}
 
Example 60
Project: freeVM   File: MemoryMXBeanImplTest.java   Source Code and License 6 votes vote down vote up
public final void testGetNotificationInfo() {
    MBeanNotificationInfo[] notifications = notifierBean
            .getNotificationInfo();
    assertNotNull(notifications);
    assertTrue(notifications.length > 0);
    for (int i = 0; i < notifications.length; i++) {
        MBeanNotificationInfo info = notifications[i];
        assertEquals(Notification.class.getName(), info.getName());
        assertEquals("Memory Notification", info.getDescription());
        String[] types = info.getNotifTypes();
        for (int j = 0; j < types.length; j++) {
            String type = types[j];
            assertTrue(type
                    .equals(MemoryNotificationInfo.MEMORY_THRESHOLD_EXCEEDED)
                    || type
                            .equals(MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED));

        }// end for
    }// end for
}