Search in sources :

Example 1 with NotificationEmitter

use of javax.management.NotificationEmitter in project gephi by gephi.

the class MemoryStarvationManager method startup.

public void startup() {
    ((NotificationEmitter) ManagementFactory.getMemoryMXBean()).addNotificationListener(this, null, null);
    List<MemoryPoolMXBean> mpbeans = ManagementFactory.getMemoryPoolMXBeans();
    MemoryPoolMXBean biggestHeap = null;
    long biggestSize = 0;
    for (MemoryPoolMXBean b : mpbeans) {
        if (b.getType() == MemoryType.HEAP) {
            /* Here we are making the leap of faith that the biggest
                 * heap is the tenured heap
                 */
            long size = b.getUsage().getMax();
            if (size > biggestSize) {
                biggestSize = size;
                biggestHeap = b;
            }
        }
    }
    if (biggestHeap != null) {
        long usageThreshold = (long) (biggestSize - reservedMemory);
        biggestHeap.setUsageThreshold(usageThreshold);
        biggestHeap.setCollectionUsageThreshold(usageThreshold);
    }
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Example 2 with NotificationEmitter

use of javax.management.NotificationEmitter in project jdk8u_jdk by JetBrains.

the class CounterMonitorInitThresholdTest method runTest.

public static void runTest() throws Exception {
    // Retrieve the platform MBean server
    //
    System.out.println("\nRetrieve the platform MBean server");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String domain = mbs.getDefaultDomain();
    // Create and register TestMBeans
    //
    ObjectName name1 = new ObjectName(domain + ":type=" + Test.class.getName() + ",name=1");
    mbs.createMBean(Test.class.getName(), name1);
    TestMBean mbean1 = (TestMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name1, TestMBean.class, false);
    ObjectName name2 = new ObjectName(domain + ":type=" + Test.class.getName() + ",name=2");
    mbs.createMBean(Test.class.getName(), name2);
    TestMBean mbean2 = (TestMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name2, TestMBean.class, false);
    // Create and register CounterMonitorMBean
    //
    ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName());
    CounterMonitor m = new CounterMonitor();
    mbs.registerMBean(m, cmn);
    CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, cmn, CounterMonitorMBean.class, true);
    ((NotificationEmitter) cm).addNotificationListener(new Listener(), null, null);
    cm.setObservedAttribute("Counter");
    cm.setGranularityPeriod(100);
    cm.setInitThreshold(3);
    cm.setNotify(true);
    // Add observed object name1
    //
    System.out.println("\nObservedObject \"" + name1 + "\" registered before starting the monitor");
    cm.addObservedObject(name1);
    // Start the monitor
    //
    System.out.println("\nStart monitoring...");
    cm.start();
    // Play with counter for name1
    //
    System.out.println("\nTest ObservedObject \"" + name1 + "\"");
    for (int i = 0; i < 4; i++) {
        mbean1.setCounter(i);
        System.out.println("\nCounter = " + mbean1.getCounter());
        Thread.sleep(300);
        Number thresholdValue = cm.getThreshold(name1);
        System.out.println("Threshold = " + thresholdValue);
        if (thresholdValue.intValue() != 3) {
            System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = 3");
            System.out.println("\nStop monitoring...");
            cm.stop();
            throw new IllegalArgumentException("wrong threshold");
        }
        Thread.sleep(300);
    }
    // Add observed object name2
    //
    System.out.println("\nObservedObject \"" + name2 + "\" registered after starting the monitor");
    cm.addObservedObject(name2);
    // Play with counter for name2
    //
    System.out.println("\nTest ObservedObject \"" + name2 + "\"");
    for (int i = 0; i < 4; i++) {
        mbean2.setCounter(i);
        System.out.println("\nCounter = " + mbean2.getCounter());
        Thread.sleep(300);
        Number thresholdValue = cm.getThreshold(name2);
        System.out.println("Threshold = " + thresholdValue);
        if (thresholdValue.intValue() != 3) {
            System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = 3");
            System.out.println("\nStop monitoring...");
            cm.stop();
            throw new IllegalArgumentException("wrong threshold");
        }
        Thread.sleep(300);
    }
    // Stop the monitor
    //
    System.out.println("\nStop monitoring...");
    cm.stop();
}
Also used : NotificationEmitter(javax.management.NotificationEmitter) NotificationListener(javax.management.NotificationListener) CounterMonitorMBean(javax.management.monitor.CounterMonitorMBean) CounterMonitor(javax.management.monitor.CounterMonitor) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 3 with NotificationEmitter

use of javax.management.NotificationEmitter in project jdk8u_jdk by JetBrains.

the class CounterMonitorThresholdTest method runTest.

public static void runTest(int offset, int[] counter, int[] derivedGauge, int[] threshold) throws Exception {
    // Retrieve the platform MBean server
    //
    System.out.println("\nRetrieve the platform MBean server");
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    String domain = mbs.getDefaultDomain();
    // Create and register TestMBean
    //
    ObjectName name = new ObjectName(domain + ":type=" + Test.class.getName() + ",offset=" + offset);
    mbs.createMBean(Test.class.getName(), name);
    TestMBean mbean = (TestMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, name, TestMBean.class, false);
    // Create and register CounterMonitorMBean
    //
    ObjectName cmn = new ObjectName(domain + ":type=" + CounterMonitor.class.getName() + ",offset=" + offset);
    CounterMonitor m = new CounterMonitor();
    mbs.registerMBean(m, cmn);
    CounterMonitorMBean cm = (CounterMonitorMBean) MBeanServerInvocationHandler.newProxyInstance(mbs, cmn, CounterMonitorMBean.class, true);
    ((NotificationEmitter) cm).addNotificationListener(new Listener(), null, null);
    cm.addObservedObject(name);
    cm.setObservedAttribute("Counter");
    cm.setGranularityPeriod(100);
    cm.setInitThreshold(1);
    cm.setOffset(offset);
    cm.setModulus(5);
    cm.setNotify(true);
    // Start the monitor
    //
    System.out.println("\nStart monitoring...");
    cm.start();
    //
    for (int i = 0; i < counter.length; i++) {
        mbean.setCounter(counter[i]);
        System.out.println("\nCounter = " + mbean.getCounter());
        Integer derivedGaugeValue;
        // see 8025207
        do {
            Thread.sleep(150);
            derivedGaugeValue = (Integer) cm.getDerivedGauge(name);
        } while (derivedGaugeValue.intValue() != derivedGauge[i]);
        Number thresholdValue = cm.getThreshold(name);
        System.out.println("Threshold = " + thresholdValue);
        if (thresholdValue.intValue() != threshold[i]) {
            System.out.println("Wrong threshold! Current value = " + thresholdValue + " Expected value = " + threshold[i]);
            System.out.println("\nStop monitoring...");
            cm.stop();
            throw new IllegalArgumentException("wrong threshold");
        }
    }
    // Stop the monitor
    //
    System.out.println("\nStop monitoring...");
    cm.stop();
}
Also used : NotificationListener(javax.management.NotificationListener) ObjectName(javax.management.ObjectName) NotificationEmitter(javax.management.NotificationEmitter) CounterMonitorMBean(javax.management.monitor.CounterMonitorMBean) CounterMonitor(javax.management.monitor.CounterMonitor) MBeanServer(javax.management.MBeanServer)

Example 4 with NotificationEmitter

use of javax.management.NotificationEmitter in project aries by apache.

the class RegistrableStandardEmitterMBean method getMBeanInfo.

/**
     * @see javax.management.StandardMBean#getMBeanInfo()
     */
public MBeanInfo getMBeanInfo() {
    MBeanInfo mbeanInfo = super.getMBeanInfo();
    if (mbeanInfo != null) {
        MBeanNotificationInfo[] notificationInfo;
        Object impl = getImplementation();
        if (impl instanceof NotificationEmitter) {
            notificationInfo = ((NotificationEmitter) (impl)).getNotificationInfo();
        } else {
            notificationInfo = new MBeanNotificationInfo[0];
        }
        mbeanInfo = new MBeanInfo(mbeanInfo.getClassName(), mbeanInfo.getDescription(), mbeanInfo.getAttributes(), mbeanInfo.getConstructors(), mbeanInfo.getOperations(), notificationInfo);
    }
    return mbeanInfo;
}
Also used : MBeanNotificationInfo(javax.management.MBeanNotificationInfo) NotificationEmitter(javax.management.NotificationEmitter) MBeanInfo(javax.management.MBeanInfo)

Example 5 with NotificationEmitter

use of javax.management.NotificationEmitter in project geode by apache.

the class HeapMemoryMonitor method startJVMThresholdListener.

/**
   * Register with the JVM to get threshold events.
   * 
   * Package private for testing.
   */
void startJVMThresholdListener() {
    final MemoryPoolMXBean memoryPoolMXBean = getTenuredMemoryPoolMXBean();
    // 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[] { usageThreshold, memoryPoolMXBean.getName() });
    MemoryMXBean mbean = ManagementFactory.getMemoryMXBean();
    NotificationEmitter emitter = (NotificationEmitter) mbean;
    emitter.addNotificationListener(this, null, null);
}
Also used : MemoryMXBean(java.lang.management.MemoryMXBean) NotificationEmitter(javax.management.NotificationEmitter) MemoryPoolMXBean(java.lang.management.MemoryPoolMXBean)

Aggregations

NotificationEmitter (javax.management.NotificationEmitter)15 NotificationListener (javax.management.NotificationListener)7 ListenerNotFoundException (javax.management.ListenerNotFoundException)5 MemoryPoolMXBean (java.lang.management.MemoryPoolMXBean)4 Notification (javax.management.Notification)3 ObjectName (javax.management.ObjectName)3 ScanState (com.sun.jmx.examples.scandir.ScanManagerMXBean.ScanState)2 GarbageCollectorMXBean (java.lang.management.GarbageCollectorMXBean)2 MemoryMXBean (java.lang.management.MemoryMXBean)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 AttributeChangeNotification (javax.management.AttributeChangeNotification)2 MBeanServer (javax.management.MBeanServer)2 NotificationFilter (javax.management.NotificationFilter)2 CounterMonitor (javax.management.monitor.CounterMonitor)2 CounterMonitorMBean (javax.management.monitor.CounterMonitorMBean)2 Duration (com.github.joschi.jadconfig.util.Duration)1 GcInfo (com.sun.management.GcInfo)1 IOException (java.io.IOException)1 InvocationHandler (java.lang.reflect.InvocationHandler)1 Proxy (java.lang.reflect.Proxy)1