当前位置: 首页>>代码示例>>Java>>正文


Java NotificationEmitter.addNotificationListener方法代码示例

本文整理汇总了Java中javax.management.NotificationEmitter.addNotificationListener方法的典型用法代码示例。如果您正苦于以下问题:Java NotificationEmitter.addNotificationListener方法的具体用法?Java NotificationEmitter.addNotificationListener怎么用?Java NotificationEmitter.addNotificationListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.management.NotificationEmitter的用法示例。


在下文中一共展示了NotificationEmitter.addNotificationListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: installGCMonitoring

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
private static void installGCMonitoring() {
    List<GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
    for (GarbageCollectorMXBean gcbean : gcbeans) {
        NotificationEmitter emitter = (NotificationEmitter) gcbean;
        System.out.println(gcbean.getName());

        NotificationListener listener = (notification, handback) -> {
            if (notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) {
                GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData) notification.getUserData());

                long duration = info.getGcInfo().getDuration();
                String gctype = info.getGcAction();

                System.out.println(gctype + ": - "
                        + info.getGcInfo().getId() + ", "
                        + info.getGcName()
                        + " (from " + info.getGcCause() + ") " + duration + " milliseconds");

            }
        };

        emitter.addNotificationListener(listener, null, null);
    }
}
 
开发者ID:vitaly-chibrikov,项目名称:otus_java_2017_06,代码行数:25,代码来源:Main.java

示例2: startJVMThresholdListener

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
/**
 * Register with the JVM to get threshold events.
 * 
 * Package private for testing.
 */
void startJVMThresholdListener() {
  final MemoryPoolMXBean memoryPoolMXBean = getTenuredMemoryPoolMXBean();

  // Set collection threshold to a low value, so that we can get
  // notifications after every GC run. After each such collection
  // threshold notification we set the usage thresholds to an
  // appropriate value.
  if (!testDisableMemoryUpdates) {
    memoryPoolMXBean.setCollectionUsageThreshold(1);
  }

  final long usageThreshold = memoryPoolMXBean.getUsageThreshold();
  this.cache.getLoggerI18n().info(
      LocalizedStrings.HeapMemoryMonitor_OVERRIDDING_MEMORYPOOLMXBEAN_HEAP_0_NAME_1,
      new Object[] {Long.valueOf(usageThreshold), memoryPoolMXBean.getName()});

  MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
  NotificationEmitter emitter = (NotificationEmitter) mbean;
  emitter.addNotificationListener(this, null, null);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:26,代码来源:HeapMemoryMonitor.java

示例3: MemoryMonitor

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
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);
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:18,代码来源:MemoryMonitor.java

示例4: setUpGCMonitoring

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
public static void setUpGCMonitoring() {
  for (java.lang.management.GarbageCollectorMXBean bean : gcbeans) {
    NotificationEmitter emitter = (NotificationEmitter) bean;
    NotificationListener listener = new NotificationListener() {
      @Override
      public void handleNotification(final Notification notification,
          final Object handback) {
        if (GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION.equals(
            notification.getType())) {
          GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from(
              (CompositeData) notification.getUserData());
          long after = getTotal(info.getGcInfo().getMemoryUsageAfterGc());
          long before = getTotal(info.getGcInfo().getMemoryUsageBeforeGc());
          collectedMemory += before - after;
        }
      }
    };
    emitter.addNotificationListener(listener, null, null);
  }
}
 
开发者ID:smarr,项目名称:SOMns,代码行数:21,代码来源:ActorExecutionTrace.java

示例5: init

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
public synchronized static void init(ConfigServer cs){
      if(init) return;
		// set level
      for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
    	  types.put(pool.getName(), pool.getType());
        // I don't know whether this approach is better, or whether
        // we should rather check for the pool name "Tenured Gen"?
    	  if (pool.getType() == MemoryType.HEAP && pool.isUsageThresholdSupported()) {
    		  long maxMemory = pool.getUsage().getMax();
    		  long warningThreshold = (long) (maxMemory * 0.9);
    		  //long warningThreshold = maxMemory -(10*1024*1024);
    		  pool.setUsageThreshold(warningThreshold);
    	  }
      }
      
      MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
      NotificationEmitter emitter = (NotificationEmitter) mbean;
      MemoryNotificationListener listener = new MemoryNotificationListener(types);
      emitter.addNotificationListener(listener, null, cs);
      init=true;
}
 
开发者ID:lucee,项目名称:Lucee4,代码行数:22,代码来源:MemoryControler.java

示例6: start

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
/**
 * Start collecting data about GC events.
 *
 * @param listener
 *     If not null, the listener will be called with the event objects after metrics and the
 *     log buffer is updated.
 */
public synchronized void start(GcEventListener listener) {
  // TODO: this class has a bad mix of static fields used from an instance of the class. For now
  // this has been changed not to throw to make the dependency injection use-cases work. A
  // more general refactor of the GcLogger class is needed.
  if (notifListener != null) {
    LOGGER.warn("logger already started");
    return;
  }
  eventListener = listener;
  notifListener = new GcNotificationListener();
  for (GarbageCollectorMXBean mbean : ManagementFactory.getGarbageCollectorMXBeans()) {
    if (mbean instanceof NotificationEmitter) {
      final NotificationEmitter emitter = (NotificationEmitter) mbean;
      emitter.addNotificationListener(notifListener, null, null);
    }
  }
}
 
开发者ID:Netflix,项目名称:spectator,代码行数:25,代码来源:GcLogger.java

示例7: addWatchDogToAllPools

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
public static void addWatchDogToAllPools(final long threshold,
    final NotificationListener listener) {
  final MemoryMXBean memBean = ManagementFactory.getMemoryMXBean();
  final NotificationEmitter ne = (NotificationEmitter) memBean;

  ne.addNotificationListener(listener, null, null);

  final List<MemoryPoolMXBean> memPools = ManagementFactory
      .getMemoryPoolMXBeans();
  for (final MemoryPoolMXBean mp : memPools) {
    if (mp.isUsageThresholdSupported()) {
      final MemoryUsage mu = mp.getUsage();
      final long max = mu.getMax();
      final long alert = (max * threshold) / 100;
      // LOG.info("Setting a threshold shutdown on pool: " + mp.getName()
      // + " for: " + alert);
      mp.setUsageThreshold(alert);

    }
  }
}
 
开发者ID:hcoles,项目名称:pitest,代码行数:22,代码来源:MemoryWatchdog.java

示例8: install

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
void install() {
  Preconditions.checkState(!installed, "RetainedHeapLimiter installed twice");
  installed = true;
  List<GarbageCollectorMXBean> gcbeans = ManagementFactory.getGarbageCollectorMXBeans();
  boolean foundTenured = false;
  // Examine all collectors and register for notifications from those which collect the tenured
  // space. Normally there is one such collector.
  for (GarbageCollectorMXBean gcbean : gcbeans) {
    boolean collectsTenured = false;
    for (String name : gcbean.getMemoryPoolNames()) {
      collectsTenured |= isTenuredSpace(name);
    }
    if (collectsTenured) {
      foundTenured = true;
      NotificationEmitter emitter = (NotificationEmitter) gcbean;
      emitter.addNotificationListener(this, null, null);
    }
  }
  if (!foundTenured) {
    throw new IllegalStateException(
        "Can't find tenured space; update this class for a new collector");
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:24,代码来源:RetainedHeapLimiter.java

示例9: LowMemoryDetector

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
/**
 * Default constructor.
 * 
 * @param memoryThresholdFactor amount of memory to be considered 'enough memory'.
 * @throws IllegalArgumentException If memoryThresholdFactor is not strictly between 0.0 and 1.0.
 */
public LowMemoryDetector(final double memoryThresholdFactor) {
	checkArgument(memoryThresholdFactor > 0.0 && memoryThresholdFactor < 1.0,
			"Expected memoryThresholdFactor to be between 0.0 and 1.0, %s is not.", memoryThresholdFactor);

	isLowMemory = false;

	// Find the tenured heap
	tenuredHeap = findTenuredHeap();
	checkNotNull(tenuredHeap, "Expected tenuredHeap to be not null.");
	tenuredHeapSize = tenuredHeap.getUsage().getMax();
	log.debug("Determined the tenured heap as '{}' (size: {} B).", tenuredHeap.getName(), tenuredHeapSize);

	// Monitor tenured heap
	memoryThreshold = (long) (tenuredHeapSize * memoryThresholdFactor);
	tenuredHeap.setCollectionUsageThreshold(memoryThreshold);
	log.debug("Low memory threshold is {} B.", memoryThreshold);

	// Add notification listener
	final NotificationEmitter notificationEmitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
	notificationEmitter.addNotificationListener(this, null, null);
}
 
开发者ID:whummer,项目名称:scaleDOM,代码行数:28,代码来源:LowMemoryDetector.java

示例10: watchCodeCache

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
private void watchCodeCache(final MemoryPoolMXBean bean) {
  final long threshold = bean.getUsage().getMax() - 5 * 1024 * 1024;
  if (!bean.isUsageThresholdSupported() || threshold <= 0) return;

  bean.setUsageThreshold(threshold);
  final NotificationEmitter emitter = (NotificationEmitter)ManagementFactory.getMemoryMXBean();
  emitter.addNotificationListener(new NotificationListener() {
    @Override
    public void handleNotification(Notification n, Object hb) {
      if (bean.getUsage().getUsed() > threshold) {
        LOG.info("Code Cache is almost full");
        dumpThreads("codeCacheFull", true);
        try {
          emitter.removeNotificationListener(this);
        }
        catch (ListenerNotFoundException e) {
          LOG.error(e);
        }
      }
    }
  }, null, null);
}
 
开发者ID:consulo,项目名称:consulo,代码行数:23,代码来源:PerformanceWatcher.java

示例11: JvmGcMetrics

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
public JvmGcMetrics() {
    histogram = Histogram.build().name("jvm_gc_hist").help("garbage collection metrics as a histogram")
        .labelNames(new String[] { KEY_NAME, KEY_CAUSE, KEY_ACTION }).create();

    for (GarbageCollectorMXBean gcbean : ManagementFactory.getGarbageCollectorMXBeans()) {
        final NotificationEmitter emitter = (NotificationEmitter) gcbean;
        emitter.addNotificationListener(gcListener, null, null);
    }
}
 
开发者ID:Skatteetaten,项目名称:aurora-prometheus,代码行数:10,代码来源:JvmGcMetrics.java

示例12: startJVMThresholdListener

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
/**
 * Register with the JVM to get threshold events.
 * 
 * Package private for testing.
 */
void startJVMThresholdListener() {
  final MemoryPoolMXBean memoryPoolMXBean = getTenuredMemoryPoolMXBean();

  // Set collection threshold to a low value, so that we can get
  // notifications after every GC run. After each such collection
  // threshold notification we set the usage thresholds to an
  // appropriate value.
  if (!testDisableMemoryUpdates) {
    memoryPoolMXBean.setCollectionUsageThreshold(1);
    // also set for notifications from survivor space GC
    final MemoryPoolMXBean survivorPoolMXBean = getSurvivorPoolMXBean();
    if (survivorPoolMXBean != null
        && survivorPoolMXBean.isCollectionUsageThresholdSupported()) {
      survivorPoolMXBean.setCollectionUsageThreshold(1);
    }
  }
  
  final long usageThreshold = memoryPoolMXBean.getUsageThreshold();
  this.cache.getLoggerI18n().info(
      LocalizedStrings.HeapMemoryMonitor_OVERRIDDING_MEMORYPOOLMXBEAN_HEAP_0_NAME_1,
      new Object[] { Long.valueOf(usageThreshold), memoryPoolMXBean.getName() });

  MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
  NotificationEmitter emitter = (NotificationEmitter) mbean;
  emitter.addNotificationListener(this, null, null);
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:32,代码来源:HeapMemoryMonitor.java

示例13: start

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
public synchronized void start() {
    if (started) {
        // already started
        return;
    }
    started = true;

    for (GarbageCollectorMXBean bean : configuration.getGarbageCollectorMXBeans()) {
        NotificationEmitter emitter = (NotificationEmitter) bean;
        emitter.addNotificationListener(this, null, bean.getName());
    }
}
 
开发者ID:vladimir-bukhtoyarov,项目名称:gc-monitor,代码行数:13,代码来源:GcMonitor.java

示例14: requestMemoryWarnings

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
public final void requestMemoryWarnings() {
  List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans();
  long maxPoolSize = 0;
  MemoryPoolMXBean biggestPool = null;

  for (MemoryPoolMXBean pool : pools) {
    if (pool.getType() != MemoryType.HEAP) {
      continue;
    }
    MemoryUsage usage = pool.getUsage();

    if (pool.isUsageThresholdSupported()
            && usage.getMax() > maxPoolSize) {
      maxPoolSize = usage.getMax();
      biggestPool = pool;
    }
  }

  if (biggestPool != null) {
    biggestPool.setUsageThreshold((long) (maxPoolSize * this.memoryFraction));
    MemoryMXBean memoryBean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) memoryBean;
    emitter.addNotificationListener(this, null, null);
  } else {
    throw new RuntimeException("Memory monitoring is not supported.");
  }
}
 
开发者ID:teanalab,项目名称:demidovii,代码行数:28,代码来源:Sorter.java

示例15: getGarbageInfo

import javax.management.NotificationEmitter; //导入方法依赖的package包/类
private static GarbageInfo getGarbageInfo(
		GarbageCollectorMXBean bean, String[] poolNames, String poolContainText)
{
	String					primaryPoolName			= null;
	for (String poolName : poolNames)
	{
		if (poolName.contains(poolContainText))
		{
			primaryPoolName = poolName;
		}
	}
	if (null == primaryPoolName)
	{
		return null;
	}

	GarbageInfo				garbageInfo				= new GarbageInfo(bean, poolContainText);
	garbageInfo.m_primaryPoolName	= primaryPoolName;

	if (garbageInfo.getGarbageBean() instanceof NotificationEmitter)
	{
		NotificationEmitter				notificationEmitter	= (NotificationEmitter) garbageInfo.getGarbageBean();
		GarbageNotificationListener		listener			= new GarbageNotificationListener();
		notificationEmitter.addNotificationListener(listener, null, garbageInfo);
	}

	return garbageInfo;
}
 
开发者ID:ExpediaDotCom,项目名称:EchoX3,代码行数:29,代码来源:GarbageInfo.java


注:本文中的javax.management.NotificationEmitter.addNotificationListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。