emitter.addNotificationListener(listener, null, null);
public void close() { if(notificationListener != null) { MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean(); NotificationEmitter emitter = (NotificationEmitter) mxBean; try { emitter.removeNotificationListener(notificationListener); } catch(ListenerNotFoundException e) { LOG.warn("Failed to remove HeapMemoryMonitor notification listener from MemoryMXBean", e); } } } }
+ notification.getType()); }; emitter.addNotificationListener(gcLogger, null, null); gcLoggers.put(emitter, gcLogger); for (NotificationEmitter emitter : gcLoggers.keySet()) { NotificationListener gcLogger = gcLoggers.get(emitter); emitter.removeNotificationListener(gcLogger);
@Override public MBeanNotificationInfo[] getNotificationInfo() { if (_emitter != null) { return _emitter.getNotificationInfo(); } else { return new MBeanNotificationInfo[] {}; } }
for (MemoryPoolMXBean memoryPoolMXBean : memPools) { try { emitter.removeNotificationListener(this, null, memoryPoolMXBean); } catch (Exception e) { } MemoryUsage memUsage = memoryPoolMXBean.getUsage(); if (memUsage != null) { if (memoryPoolMXBean.isUsageThresholdSupported()) { emitter.addNotificationListener(this, null, memoryPoolMXBean); long memUsageTreshold = new Double(new Long(memUsage.getMax()).doubleValue() *
public MBeanNotificationInfo[] getNotificationInfo(){ return ((NotificationEmitter)handler).getNotificationInfo(); } }
public void start() { // unsupported if null if (tenuredGenPool == null) { return; } MemoryMXBean mxBean = ManagementFactory.getMemoryMXBean(); NotificationEmitter emitter = (NotificationEmitter) mxBean; notificationListener = (n, hb) -> { if (n.getType().equals( MemoryNotificationInfo.MEMORY_COLLECTION_THRESHOLD_EXCEEDED)) { long maxMemory = tenuredGenPool.getUsage().getMax(); long usedMemory = tenuredGenPool.getUsage().getUsed(); for (Listener listener : listeners) { listener.memoryUsageAboveThreshold(usedMemory, maxMemory); } } }; emitter.addNotificationListener(notificationListener, null, null); }
emitter.removeNotificationListener(this, null, null); if (logger.isDebugEnabled()) { logger.debug("Removed Memory MXBean notification listener" + this);
public MBeanNotificationInfo[] getNotificationInfo() { return notificationEmitter.getNotificationInfo(); }
HeapUsageMonitor() { int c = 0; for( MemoryPoolMXBean m : ManagementFactory.getMemoryPoolMXBeans() ) { if( m.getType() != MemoryType.HEAP ) // only interested in HEAP continue; if( m.isCollectionUsageThresholdSupported() && m.isUsageThresholdSupported()) { // should be Old pool, get called when memory is critical _oldGenBean = m; _gc_callback = MEM_MAX; // Really idiotic API: no idea what the usageThreshold is, so I have // to guess. Start high, catch IAE & lower by 1/8th and try again. while( true ) { try { m.setCollectionUsageThreshold(_gc_callback); break; } catch( IllegalArgumentException iae ) { // Do NOT log this exception, it is expected and unavoidable and // entirely handled. _gc_callback -= (_gc_callback>>3); } } NotificationEmitter emitter = (NotificationEmitter) _allMemBean; emitter.addNotificationListener(this, null, m); ++c; } } assert c == 1; }
NotificationEmitter emitter = (NotificationEmitter) memoryMBean; try { emitter.removeNotificationListener(memoryListener); } catch (ListenerNotFoundException lnfe) {}
public MBeanNotificationInfo[] getNotificationInfo() { return mNotify.getNotificationInfo(); }
/** * 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.getLogger().info( String.format("Overridding MemoryPoolMXBean heap threshold bytes %s on pool %s", new Object[] {usageThreshold, memoryPoolMXBean.getName()})); MemoryMXBean mbean = ManagementFactory.getMemoryMXBean(); NotificationEmitter emitter = (NotificationEmitter) mbean; emitter.addNotificationListener(this, null, null); }
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException { notificationEmitter.removeNotificationListener(listener, filter, handback); }
emitter.addNotificationListener(memoryListener, null, null);
@Override public void close() throws IOException { if (emitter != null && listener != null) { try { emitter.removeNotificationListener(listener); } catch (ListenerNotFoundException e) { // } } }
emitter.addNotificationListener(me, null, null); List<MemoryPoolMXBean> pools = ManagementFactory.getMemoryPoolMXBeans(); for (MemoryPoolMXBean p : pools) {
public void removeNotificationListener( NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException { ((NotificationEmitter)handler).removeNotificationListener( listener, filter, handback ); }
public MemoryAllocationExports() { AllocationCountingNotificationListener listener = new AllocationCountingNotificationListener(allocatedCounter); for (GarbageCollectorMXBean garbageCollectorMXBean : ManagementFactory.getGarbageCollectorMXBeans()) { ((NotificationEmitter) garbageCollectorMXBean).addNotificationListener(listener, null, null); } }
@Override public void removeNotificationListener(final NotificationListener listener, final NotificationFilter filter, final Object handback) throws ListenerNotFoundException { if (_emitter != null) { _emitter.removeNotificationListener(listener, filter, handback); } }