javax.management.NotificationEmitter Java Examples

The following examples show how to use javax.management.NotificationEmitter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestUtils.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
Example #2
Source File: TestUtils.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
Example #3
Source File: ThresholdNotificationsTest.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
protected void runTest() {
    int iterationsCount
            = Integer.getInteger("jdk.test.lib.iterations", 1);
    MemoryPoolMXBean bean = btype.getMemoryPool();
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
            addNotificationListener(this, null, null);
    for (int i = 0; i < iterationsCount; i++) {
        CodeCacheUtils.hitUsageThreshold(bean, btype);
    }
    Asserts.assertTrue(
            Utils.waitForCondition(
                    () -> (CodeCacheUtils.isCodeHeapPredictable(btype) ?
                            (counter == iterationsCount) : (counter >= iterationsCount)),
                    WAIT_TIME),
            "Couldn't receive expected notifications count");
    try {
        ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).
                removeNotificationListener(this);
    } catch (ListenerNotFoundException ex) {
        throw new AssertionError("Can't remove notification listener", ex);
    }
    System.out.printf("INFO: Scenario finished successfully for %s%n",
            bean.getName());
}
 
Example #4
Source File: TestUtils.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
Example #5
Source File: TestUtils.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
Example #6
Source File: PrometheusMetrics.java    From Lavalink with MIT License 6 votes vote down vote up
public PrometheusMetrics() {

        InstrumentedAppender prometheusAppender = new InstrumentedAppender();
        //log metrics
        final LoggerContext factory = (LoggerContext) LoggerFactory.getILoggerFactory();
        final ch.qos.logback.classic.Logger root = factory.getLogger(Logger.ROOT_LOGGER_NAME);
        prometheusAppender.setContext(root.getLoggerContext());
        prometheusAppender.start();
        root.addAppender(prometheusAppender);

        //jvm (hotspot) metrics
        DefaultExports.initialize();

        //gc pause buckets
        final GcNotificationListener gcNotificationListener = new GcNotificationListener();
        for (GarbageCollectorMXBean gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
            if (gcBean instanceof NotificationEmitter) {
                ((NotificationEmitter) gcBean).addNotificationListener(gcNotificationListener, null, gcBean);
            }
        }

        log.info("Prometheus metrics set up");
    }
 
Example #7
Source File: HeapMonitorThread.java    From dremio-oss with Apache License 2.0 6 votes vote down vote up
private void registerForNotifications() {
  // Register the listener with MemoryMXBean
  NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
  emitter.addNotificationListener(listener, null, null);

  // set collection usage threshold.
  for (MemoryPoolMXBean pool : ManagementFactory.getMemoryPoolMXBeans()) {
    if (pool.getType() == MemoryType.HEAP &&
      pool.isUsageThresholdSupported() &&
      pool.isCollectionUsageThresholdSupported()) {

      long threshold = (pool.getUsage().getMax() * thresholdPercentage) / 100;
      logger.info("setting collection threshold for " + pool.getName() +
        " with max " + pool.getUsage().getMax() +
        " to " + threshold);

      pool.setCollectionUsageThreshold(threshold);
      monitoredPools.put(pool.getName(), pool.getCollectionUsageThresholdCount());
    } else {
      logger.info("skip monitoring for pool " + pool.getName());
    }
  }
}
 
Example #8
Source File: TestUtils.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
Example #9
Source File: JVMUtils.java    From babar with Apache License 2.0 6 votes vote down vote up
/**
 * Register to all notifications from the GC MXBeans.
 * @param listener          A java NotificationListener
 */
public static void registerGCListener(GCListener listener) {

    // takes the GC listener and makes javax NotificationListener that filters GC notifications
    NotificationListener notificationListener = new NotificationListener() {
        @Override
        public void handleNotification(Notification notification, Object handback) {
            if (!notification.getType().equals(GarbageCollectionNotificationInfo.GARBAGE_COLLECTION_NOTIFICATION)) return;

            // get the GC info object
            GarbageCollectionNotificationInfo info = GarbageCollectionNotificationInfo.from((CompositeData)notification.getUserData());
            String gcAction = info.getGcAction();
            if (MINOR_GC_ACTION.equals(gcAction)) {
                listener.onMinorGc(info.getGcInfo().getDuration());
            }
            else if (MAJOR_GC_ACTION.equals(gcAction)) {
                listener.onMajorGc(info.getGcInfo().getDuration());
            }
        }
    };

    // register to the GC beans
    for (GarbageCollectorMXBean bean: ManagementFactory.getGarbageCollectorMXBeans()) {
        ((NotificationEmitter)bean).addNotificationListener(notificationListener, null, null);
    }
}
 
Example #10
Source File: MemoryWatcher.java    From tsml with GNU General Public License v3.0 6 votes vote down vote up
/**
 * emitters are used to listen to each memory pool (usually young / old gen). This function sets up the emitters
 * if not already
 */
private synchronized void setupEmitters() {
    if(emitters == null) {
        emitters = new ArrayList<>();
        // garbage collector for old and young gen
        List<GarbageCollectorMXBean> garbageCollectorBeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
        logger.finest("Setting up listeners for garbage collection ");
        for (GarbageCollectorMXBean garbageCollectorBean : garbageCollectorBeans) {
            // to log
            // listen to notification from the emitter
            NotificationEmitter emitter = (NotificationEmitter) garbageCollectorBean;
            emitters.add(emitter);
            emitter.addNotificationListener(listener, null, null);
        }
    }
}
 
Example #11
Source File: TestUtils.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
Example #12
Source File: Init.java    From andesite-node with MIT License 6 votes vote down vote up
public static void preInit(Config config) {
    ((Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME)).setLevel(
            Level.valueOf(config.getString("log-level").toUpperCase())
    );
    if(config.getBoolean("prometheus.enabled")) {
        PrometheusUtils.setup();
        var listener = new GCListener();
        for(var gcBean : ManagementFactory.getGarbageCollectorMXBeans()) {
            if(gcBean instanceof NotificationEmitter) {
                ((NotificationEmitter) gcBean)
                        .addNotificationListener(listener, null, gcBean);
            }
        }
    }
    if(config.getBoolean("sentry.enabled")) {
        SentryUtils.setup(config);
    }
}
 
Example #13
Source File: TestUtils.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Transfroms a proxy implementing T in a proxy implementing T plus
 * NotificationEmitter
 *
 **/
public static <T> T makeNotificationEmitter(T proxy,
                    Class<T> mbeanInterface) {
    if (proxy instanceof NotificationEmitter)
        return proxy;
    if (proxy == null) return null;
    if (!(proxy instanceof Proxy))
        throw new IllegalArgumentException("not a "+Proxy.class.getName());
    final Proxy p = (Proxy) proxy;
    final InvocationHandler handler =
            Proxy.getInvocationHandler(proxy);
    if (!(handler instanceof MBeanServerInvocationHandler))
        throw new IllegalArgumentException("not a JMX Proxy");
    final MBeanServerInvocationHandler h =
            (MBeanServerInvocationHandler)handler;
    final ObjectName name = h.getObjectName();
    final MBeanServerConnection mbs = h.getMBeanServerConnection();
    final boolean isMXBean = h.isMXBean();
    final T newProxy;
    if (isMXBean)
        newProxy = JMX.newMXBeanProxy(mbs,name,mbeanInterface,true);
    else
        newProxy = JMX.newMBeanProxy(mbs,name,mbeanInterface,true);
    return newProxy;
}
 
Example #14
Source File: ScanDirAgent.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize the application by registering a ScanManagerMXBean in
 * the platform MBeanServer
 * @throws java.io.IOException Registration failed for communication-related reasons.
 * @throws javax.management.JMException Registration failed for JMX-related reasons.
 */
public void init() throws IOException, JMException {

    // Registers the ScanManagerMXBean singleton in the
    // platform MBeanServer
    //
    proxy = ScanManager.register();

    // Registers a NotificationListener with the ScanManagerMXBean in
    // order to receive state changed notifications.
    //
    ((NotificationEmitter)proxy).addNotificationListener(listener,null,null);
}
 
Example #15
Source File: ScanDirAgent.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Cleanup after close: unregister the ScanManagerMXBean singleton.
 * @throws java.io.IOException Cleanup failed for communication-related reasons.
 * @throws javax.management.JMException Cleanup failed for JMX-related reasons.
 */
public void cleanup() throws IOException, JMException {
    try {
        ((NotificationEmitter)proxy).
                removeNotificationListener(listener,null,null);
    } finally {
        ManagementFactory.getPlatformMBeanServer().
            unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
    }
}
 
Example #16
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #17
Source File: OldMBeanServerTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public void removeNotificationListener(
        ObjectName name, NotificationListener listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationEmitter userMBean =
            (NotificationEmitter) getMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.removeNotificationListener(wrappedListener, filter, handback);
}
 
Example #18
Source File: ScanDirAgent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize the application by registering a ScanManagerMXBean in
 * the platform MBeanServer
 * @throws java.io.IOException Registration failed for communication-related reasons.
 * @throws javax.management.JMException Registration failed for JMX-related reasons.
 */
public void init() throws IOException, JMException {

    // Registers the ScanManagerMXBean singleton in the
    // platform MBeanServer
    //
    proxy = ScanManager.register();

    // Registers a NotificationListener with the ScanManagerMXBean in
    // order to receive state changed notifications.
    //
    ((NotificationEmitter)proxy).addNotificationListener(listener,null,null);
}
 
Example #19
Source File: ScanDirAgent.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Cleanup after close: unregister the ScanManagerMXBean singleton.
 * @throws java.io.IOException Cleanup failed for communication-related reasons.
 * @throws javax.management.JMException Cleanup failed for JMX-related reasons.
 */
public void cleanup() throws IOException, JMException {
    try {
        ((NotificationEmitter)proxy).
                removeNotificationListener(listener,null,null);
    } finally {
        ManagementFactory.getPlatformMBeanServer().
            unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
    }
}
 
Example #20
Source File: HeapMemoryMonitor.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
   * Stops all three mechanisms from monitoring heap usage.
   */
 @Override
public void stopMonitoring() {
    synchronized (this) {
      if (!this.started) {
        return;
      }
      
      // Stop the poller
      this.resourceManager.stopExecutor(this.pollerExecutor);

      // Stop the JVM threshold listener
      NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
      try {
        emitter.removeNotificationListener(this, null, null);
        this.cache.getLoggerI18n().fine("Removed Memory MXBean notification listener" + this);
      } catch (ListenerNotFoundException e) {
        this.cache.getLoggerI18n().fine("This instance '" + toString() + "' was not registered as a Memory MXBean listener");
      }

      // Stop the stats listener
      final GemFireStatSampler sampler = this.cache.getDistributedSystem().getStatSampler();
      if (sampler != null) {
        sampler.removeLocalStatListener(this.statListener);
      }

      this.started = false;
    }
  }
 
Example #21
Source File: DefaultMBeanServerInterceptor.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void removeNotificationListener(ObjectName name,
                                        NotificationListener listener,
                                        NotificationFilter filter,
                                        Object handback,
                                        boolean removeAll)
        throws InstanceNotFoundException, ListenerNotFoundException {

    if (MBEANSERVER_LOGGER.isLoggable(Level.TRACE)) {
        MBEANSERVER_LOGGER.log(Level.TRACE, "ObjectName = " + name);
    }

    DynamicMBean instance = getMBean(name);
    checkMBeanPermission(instance, null, name, "removeNotificationListener");

    /* We could simplify the code by assigning broadcaster after
       assigning listenerWrapper, but that would change the error
       behavior when both the broadcaster and the listener are
       erroneous.  */

    Class<? extends NotificationBroadcaster> reqClass =
        removeAll ? NotificationBroadcaster.class : NotificationEmitter.class;
    NotificationBroadcaster broadcaster =
        getNotificationBroadcaster(name, instance, reqClass);

    NotificationListener listenerWrapper =
        getListenerWrapper(listener, name, instance, false);

    if (listenerWrapper == null)
        throw new ListenerNotFoundException("Unknown listener");

    if (removeAll)
        broadcaster.removeNotificationListener(listenerWrapper);
    else {
        NotificationEmitter emitter = (NotificationEmitter) broadcaster;
        emitter.removeNotificationListener(listenerWrapper,
                                           filter,
                                           handback);
    }
}
 
Example #22
Source File: HeapMonitorThread.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void deregisterFromNotifications() {
  try {
    NotificationEmitter emitter = (NotificationEmitter) ManagementFactory.getMemoryMXBean();
    emitter.removeNotificationListener(this.listener);
  } catch (ListenerNotFoundException e) {
    // ignore error.
    logger.info("missing listener");
  }
}
 
Example #23
Source File: ScanDirAgent.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Cleanup after close: unregister the ScanManagerMXBean singleton.
 * @throws java.io.IOException Cleanup failed for communication-related reasons.
 * @throws javax.management.JMException Cleanup failed for JMX-related reasons.
 */
public void cleanup() throws IOException, JMException {
    try {
        ((NotificationEmitter)proxy).
                removeNotificationListener(listener,null,null);
    } finally {
        ManagementFactory.getPlatformMBeanServer().
            unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
    }
}
 
Example #24
Source File: ScanDirAgent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Cleanup after close: unregister the ScanManagerMXBean singleton.
 * @throws java.io.IOException Cleanup failed for communication-related reasons.
 * @throws javax.management.JMException Cleanup failed for JMX-related reasons.
 */
public void cleanup() throws IOException, JMException {
    try {
        ((NotificationEmitter)proxy).
                removeNotificationListener(listener,null,null);
    } finally {
        ManagementFactory.getPlatformMBeanServer().
            unregisterMBean(ScanManager.SCAN_MANAGER_NAME);
    }
}
 
Example #25
Source File: ScanDirAgent.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize the application by registering a ScanManagerMXBean in
 * the platform MBeanServer
 * @throws java.io.IOException Registration failed for communication-related reasons.
 * @throws javax.management.JMException Registration failed for JMX-related reasons.
 */
public void init() throws IOException, JMException {

    // Registers the ScanManagerMXBean singleton in the
    // platform MBeanServer
    //
    proxy = ScanManager.register();

    // Registers a NotificationListener with the ScanManagerMXBean in
    // order to receive state changed notifications.
    //
    ((NotificationEmitter)proxy).addNotificationListener(listener,null,null);
}
 
Example #26
Source File: ReferenceManagerImpl.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
protected void uninstallGCMonitoring() {
  while (!gcNotificationListeners.isEmpty()) {
    Map.Entry<NotificationEmitter, NotificationListener> entry = gcNotificationListeners.entrySet().iterator().next();
    try {
      entry.getKey().removeNotificationListener(entry.getValue());
      gcNotificationListeners.remove(entry.getKey());
    } catch (ListenerNotFoundException e) {
      throw new RuntimeException("unable to remove GC monitor", e);
    }
  }
  logger.info("uninstalled GC monitors.");
}
 
Example #27
Source File: ReferenceManagerImpl.java    From tinkergraph-gremlin with Apache License 2.0 5 votes vote down vote up
/** monitor GC, and should the heap grow above 80% usage, clear some strong references */
protected void installGCMonitoring() {
  List<GarbageCollectorMXBean> gcbeans = java.lang.management.ManagementFactory.getGarbageCollectorMXBeans();
  for (GarbageCollectorMXBean gcbean : gcbeans) {
    NotificationListener listener = createNotificationListener();
    NotificationEmitter emitter = (NotificationEmitter) gcbean;
    emitter.addNotificationListener(listener, null, null);
    gcNotificationListeners.put(emitter, listener);
  }
  int heapUsageThresholdPercent = (int) Math.floor(heapUsageThreshold * 100f);
  logger.info("installed GC monitors. will clear references if heap (after GC) is larger than " + heapUsageThresholdPercent + "%");
}
 
Example #28
Source File: OldMBeanServerTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public void removeNotificationListener(
        ObjectName name, NotificationListener listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationEmitter userMBean =
            (NotificationEmitter) getMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.removeNotificationListener(wrappedListener, filter, handback);
}
 
Example #29
Source File: OldMBeanServerTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void removeNotificationListener(
        ObjectName name, NotificationListener listener,
        NotificationFilter filter, Object handback)
        throws InstanceNotFoundException, ListenerNotFoundException {
    NotificationEmitter userMBean =
            (NotificationEmitter) getMBean(name);
    NotificationListener wrappedListener =
          wrappedListener(name, userMBean, listener);
    userMBean.removeNotificationListener(wrappedListener, filter, handback);
}
 
Example #30
Source File: ScanDirAgent.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Initialize the application by registering a ScanManagerMXBean in
 * the platform MBeanServer
 * @throws java.io.IOException Registration failed for communication-related reasons.
 * @throws javax.management.JMException Registration failed for JMX-related reasons.
 */
public void init() throws IOException, JMException {

    // Registers the ScanManagerMXBean singleton in the
    // platform MBeanServer
    //
    proxy = ScanManager.register();

    // Registers a NotificationListener with the ScanManagerMXBean in
    // order to receive state changed notifications.
    //
    ((NotificationEmitter)proxy).addNotificationListener(listener,null,null);
}