Package javax.management.monitor

Examples of javax.management.monitor.CounterMonitor


                server.registerMBean(monitored[i], mbeanNames[i]);
                switch (monitorType) {
                case 1:
                    monitorNames[i] = new ObjectName(":type=CounterMonitor," +
                                                     "instance=" + (i + 1));
                    monitor[i] = new CounterMonitor();
                    break;
                case 2:
                    monitorNames[i] = new ObjectName(":type=GaugeMonitor," +
                                                     "instance=" + (i + 1));
                    monitor[i] = new GaugeMonitor();
View Full Code Here


        void run() throws Exception {
            final MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
            final ObjectName observedName = new ObjectName("a:b=c");
            final ObjectName monitorName = new ObjectName("a:type=Monitor");
            mbs.registerMBean(new CounterMonitor(), monitorName);
            final CounterMonitorMBean monitorProxy =
                JMX.newMBeanProxy(mbs, monitorName, CounterMonitorMBean.class);
            final TestMBean observedProxy =
                JMX.newMBeanProxy(mbs, observedName, TestMBean.class);
View Full Code Here

        //
        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(
View Full Code Here

        final MBeanServer server = MBeanServerFactory.createMBeanServer();
        final ObjectName mbean = new ObjectName("ugly:type=cr.p");
        final My my = new My();
        final GaugeMonitor mon2 = new GaugeMonitor();
        final ObjectName mon2n = new ObjectName("mon1:type=GaugeMonitor");
        final CounterMonitor mon1 = new CounterMonitor();
        final ObjectName mon1n = new ObjectName("mon2:type=CounterMonitor");
       
        server.registerMBean(my, mbean);
        server.registerMBean(mon1, mon1n);
        server.registerMBean(mon2, mon2n);
       
        mon1.addObservedObject(mbean);
        mon1.setGranularityPeriod(60000); // 60 sec...
        mon1.setObservedAttribute(attr);
        mon1.setDifferenceMode(true);
        check(attr,server,mon1n,mbean);
       
        mon2.addObservedObject(mbean);
        mon2.setGranularityPeriod(60000); // 60 sec...
        mon2.setObservedAttribute(attr);
        mon2.setDifferenceMode(true);
        check(attr,server,mon2n,mbean);
       
        final long approxStart = System.currentTimeMillis();
        mon1.start();
        mon2.start();
       
        try {
            check(attr,server,mon1n,mbean,approxStart);
            check(attr,server,mon2n,mbean,approxStart);
            check(attr,server,mon1n,mbean,approxStart);
            check(attr,server,mon2n,mbean,approxStart);


            mon1.setGranularityPeriod(5);
            mon2.setGranularityPeriod(5);

            my.cdl.await(1000, TimeUnit.MILLISECONDS);
            if (my.cdl.getCount() > 0)
                throw new Exception(attr+": Count down not reached!");
           
            // just check that we don't get an exception now...
            System.err.println(attr+": [" + mon1n+
                    "] DerivedGauge is now "+
                    server.getAttribute(mon1n, "DerivedGauge"));
            System.err.println(attr+": [" + mon2n+
                    "] DerivedGauge is now "+
                    server.getAttribute(mon2n, "DerivedGauge"));
        } finally {
           try {mon1.stop();} catch (Exception x) {}
           try {mon2.stop();} catch (Exception x) {}
        }
    }
View Full Code Here

    /**
     * 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;
    }
View Full Code Here

TOP

Related Classes of javax.management.monitor.CounterMonitor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.