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: OpenJSharp   File: MemoryImpl.java   View source code 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: MemoryImpl.java   View source code 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 3
Project: jdk8u-jdk   File: MemoryNotifInfoCompositeData.java   View source code 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 4
Project: openjdk-jdk10   File: PoolsIndependenceTest.java   View source code 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 5
Project: openjdk-jdk10   File: MemoryImpl.java   View source code 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 6
Project: openjdk-jdk10   File: MemoryNotifInfoCompositeData.java   View source code 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 7
Project: openjdk9   File: PoolsIndependenceTest.java   View source code 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 8
Project: openjdk9   File: MemoryImpl.java   View source code 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 9
Project: openjdk9   File: MemoryNotifInfoCompositeData.java   View source code 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 10
Project: jdk8u_jdk   File: MemoryImpl.java   View source code 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 11
Project: jdk8u_jdk   File: MemoryNotifInfoCompositeData.java   View source code 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 12
Project: lookaside_java-1.8.0-openjdk   File: MemoryImpl.java   View source code 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 13
Project: lookaside_java-1.8.0-openjdk   File: MemoryNotifInfoCompositeData.java   View source code 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 14
Project: kc-rice   File: MemoryMonitor.java   View source code 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 15
Project: mobac   File: MemoryTileCache.java   View source code 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 16
Project: chai   File: MemoryNotifier.java   View source code 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 17
Project: infobip-open-jdk-8   File: MemoryImpl.java   View source code 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 18
Project: infobip-open-jdk-8   File: MemoryNotifInfoCompositeData.java   View source code 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 19
Project: jdk8u-dev-jdk   File: MemoryImpl.java   View source code 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 20
Project: jdk8u-dev-jdk   File: MemoryNotifInfoCompositeData.java   View source code 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 21
Project: galagosearch   File: Sorter.java   View source code 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 22
Project: jdk7-jdk   File: MemoryImpl.java   View source code 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 23
Project: jdk7-jdk   File: MemoryNotifInfoCompositeData.java   View source code 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 24
Project: openjdk-source-code-learn   File: MemoryImpl.java   View source code 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 25
Project: openjdk-source-code-learn   File: MemoryNotifInfoCompositeData.java   View source code 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 26
Project: OLE-INST   File: MemoryMonitor.java   View source code 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 27
Project: OLD-OpenJDK8   File: MemoryImpl.java   View source code 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 28
Project: OLD-OpenJDK8   File: MemoryNotifInfoCompositeData.java   View source code 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 29
Project: cn1   File: ManagementUtils.java   View source code 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 30
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 31
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 32
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 33
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 34
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 35
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 36
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 37
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 38
Project: cn1   File: MemoryNotificationInfoTest.java   View source code 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 39
Project: cn1   File: MemoryMXBeanImplTest.java   View source code 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 40
Project: kfs   File: MemoryMonitor.java   View source code 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);
}