Java Code Examples for javax.management.monitor.CounterMonitor#addObservedObject()

The following examples show how to use javax.management.monitor.CounterMonitor#addObservedObject() . 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: RuntimeExceptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 2
Source File: ReflectionExceptionTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 3
Source File: RuntimeExceptionTest.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Wait for granularity period (multiplied by 2 for sure)
        //
        Thread.sleep(granularityperiod * 2);

        // Check if notification was received
        //
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 4
Source File: JMXTest.java    From database with GNU General Public License v2.0 4 votes vote down vote up
/**
 * When you run this class it registers an instance of {@link Foo} as an
 * MBean and then waits forever. You can run <code>jconsole</code> and
 * verify that you can see the MBean and its attributes and change attribute
 * values using the setter(s) declared on the {@link IFoo} interface.
 * 
 * @param args
 *            Not used.
 *            
 * @throws InstanceAlreadyExistsException
 * @throws MBeanRegistrationException
 * @throws NotCompliantMBeanException
 * @throws MalformedObjectNameException
 * @throws NullPointerException
 * @throws InterruptedException
 */
public static void main(String[] args)
        throws InstanceAlreadyExistsException, MBeanRegistrationException,
        NotCompliantMBeanException, MalformedObjectNameException,
        NullPointerException, InterruptedException {

    // use this object to register your mbeans.
    final MBeanServer testMBeanServer = ManagementFactory
            .getPlatformMBeanServer();

    // create instance of your object.
    final IFoo foo = new Foo();

    // wrap as a standard mbean exposing the IFoo interface.
    final Object fooMBean = new StandardMBean(foo, IFoo.class);

    /*
     * Sets up a Clock MBean exposing the system time that updates its
     * internal state every 100 milliseconds. Then sets up a CounterMonitor
     * which observes that Clock MBean. Both are MBean and both have to be
     * registered before the notifications can be generated. The
     * CounterMBean is very picky about the data types for its arguments
     * (Threshold, Offset) all of which need to be Long since IClock is
     * returning a [long].
     * 
     * Based on http://javaboutique.internet.com/tutorials/jmx2/index2.html -
     * there are nearly no examples that I could find on the web for counter
     * monitor.
     */
    {

        // create and start clock.
        final Clock clock = new Clock();

        clock.setDaemon(true);

        clock.start();

        // wrap as a standard mbean exposing the IClockinterface.
        final Object clockMBean = new StandardMBean(clock, IClock.class);

        /*
         * Setup monitor for the clock.
         */
        final CounterMonitor cmon = new CounterMonitor();

        // register the mbean.
        testMBeanServer.registerMBean(fooMBean, new ObjectName(
                "com.bigdata", "name", "Foo"));

        cmon.addObservedObject(new ObjectName("com.bigdata:name=Clock"));

        cmon.setObservedAttribute("Time");

        cmon.setGranularityPeriod(1000/* ms */);

        cmon.setInitThreshold((Long) System.currentTimeMillis());

        // offset after event trigger for retrigger.
        cmon.setOffset((Long) 5000L/* ms since clock is also time */);

        // set the difference mode ?!?
        cmon.setDifferenceMode(false);

        // make sure we get notified.
        cmon.setNotify(true);

        // register clock
        testMBeanServer.registerMBean(clockMBean, new ObjectName(
                "com.bigdata:name=Clock"));

        // register the monitor.
        testMBeanServer.registerMBean(cmon, new ObjectName(
                "com.bigdata:name=ClockMonitor"));

        // start the monitor (you can do this via jconsole as well).
        cmon.start();
    
    }
    
    // verify visible using jconsole.
    Thread.sleep(Long.MAX_VALUE);

}
 
Example 5
Source File: RuntimeExceptionTest.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Wait for granularity period (multiplied by 2 for sure)
        //
        Thread.sleep(granularityperiod * 2);

        // Check if notification was received
        //
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 6
Source File: ReflectionExceptionTest.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 7
Source File: RuntimeExceptionTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 8
Source File: ReflectionExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 9
Source File: RuntimeExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 10
Source File: ReflectionExceptionTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 11
Source File: RuntimeExceptionTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 12
Source File: ReflectionExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 13
Source File: RuntimeExceptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 14
Source File: ReflectionExceptionTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 15
Source File: ReflectionExceptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 16
Source File: ReflectionExceptionTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 17
Source File: RuntimeExceptionTest.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 18
Source File: ReflectionExceptionTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 19
Source File: RuntimeExceptionTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}
 
Example 20
Source File: ReflectionExceptionTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Update the counter and check for notifications
 */
public int counterMonitorNotification() throws Exception {

    CounterMonitor counterMonitor = new CounterMonitor();
    try {
        // Create a new CounterMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new CounterMonitor MBean");
        ObjectName counterMonitorName = new ObjectName(
                        domain + ":type=" + CounterMonitor.class.getName());
        server.registerMBean(counterMonitor, counterMonitorName);

        echo(">>> ADD a listener to the CounterMonitor");
        counterMonitor.addNotificationListener(this, null, null);

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

        echo(">>> SET the attributes of the CounterMonitor:");

        counterMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);

        counterMonitor.setObservedAttribute("IntegerAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = IntegerAttribute");

        counterMonitor.setNotify(false);
        echo("\tATTRIBUTE \"NotifyFlag\"        = false");

        Integer threshold = 2;
        counterMonitor.setInitThreshold(threshold);
        echo("\tATTRIBUTE \"Threshold\"         = " + threshold);

        int granularityperiod = 500;
        counterMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);

        echo(">>> START the CounterMonitor");
        counterMonitor.start();

        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: CounterMonitor did not get " +
                 "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (counterMonitor != null)
            counterMonitor.stop();
    }

    return 0;
}