类javax.management.monitor.GaugeMonitor源码实例Demo

下面列出了怎么用javax.management.monitor.GaugeMonitor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dragonwell8_jdk   文件: ThreadPoolAccTest.java
public static void main (String args[]) throws Exception {

        ObjectName[] mbeanNames = new ObjectName[6];
        ObservedObject[] monitored = new ObservedObject[6];
        ObjectName[] monitorNames = new ObjectName[6];
        Monitor[] monitor = new Monitor[6];
        String[] principals = { "role1", "role2" };
        String[] attributes = { "Integer", "Double", "String" };

        try {
            echo(">>> CREATE MBeanServer");
            MBeanServer server = MBeanServerFactory.newMBeanServer();

            for (int i = 0; i < 6; i++) {
                mbeanNames[i] =
                    new ObjectName(":type=ObservedObject,instance=" + i);
                monitored[i] = new ObservedObject();
                echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
                server.registerMBean(monitored[i], mbeanNames[i]);

                switch (i) {
                    case 0:
                    case 3:
                        monitorNames[i] =
                            new ObjectName(":type=CounterMonitor,instance=" + i);
                        monitor[i] = new CounterMonitor();
                        break;
                    case 1:
                    case 4:
                        monitorNames[i] =
                            new ObjectName(":type=GaugeMonitor,instance=" + i);
                        monitor[i] = new GaugeMonitor();
                        break;
                    case 2:
                    case 5:
                        monitorNames[i] =
                            new ObjectName(":type=StringMonitor,instance=" + i);
                        monitor[i] = new StringMonitor();
                        break;
                }

                echo(">>> CREATE Monitor = " + monitorNames[i].toString());
                server.registerMBean(monitor[i], monitorNames[i]);
                monitor[i].addObservedObject(mbeanNames[i]);
                monitor[i].setObservedAttribute(attributes[i % 3]);
                monitor[i].setGranularityPeriod(500);
                final Monitor m = monitor[i];
                Subject subject = new Subject();
                echo(">>> RUN Principal = " + principals[i / 3]);
                subject.getPrincipals().add(new JMXPrincipal(principals[i / 3]));
                PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
                    public Void run() {
                        m.start();
                        return null;
                    }
                };
                Subject.doAs(subject, action);
            }

            while(!testPrincipals(monitored, monitorNames, monitor, principals));

        } finally {
            for (int i = 0; i < 6; i++)
                if (monitor[i] != null)
                    monitor[i].stop();
        }
    }
 
源代码2 项目: dragonwell8_jdk   文件: StartStopTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {

    int nTasks = maxPoolSize + 2;
    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
        }

        for (int j = 0; j < 2; j++) {
            echo(">>> Start MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].start();
            echo(">>> MONITORS started");
            doSleep(500);
            echo(">>> Check FLAGS true");
            for (int i = 0; i < nTasks; i++)
                if (!monitored[i].called) {
                    echo("KO: At least one attribute was not called");
                    return 1;
                }
            echo(">>> FLAGS checked true");
            echo(">>> Stop MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].stop();
            echo(">>> MONITORS stopped");
            doSleep(500);
            echo(">>> Set FLAGS to false");
            for (int i = 0; i < nTasks; i++)
                monitored[i].called = false;
            echo(">>> FLAGS set to false");
            echo(">>> Check FLAGS remain false");
            for (int i = 0; i < nTasks; i++)
                if (monitored[i].called) {
                    echo("KO: At least one attribute " +
                         "continued to get called");
                    return 1;
                }
            echo(">>> FLAGS checked false");
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    return 0;
}
 
源代码3 项目: dragonwell8_jdk   文件: RuntimeExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码4 项目: dragonwell8_jdk   文件: ThreadPoolTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {


    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
            monitor[i].start();
        }

        if (!waiter.waiting(MAX_WAITING_TIME)) {
            echo("Error, not all "+nTasks+" monitor tasks are called after "
                 +MAX_WAITING_TIME);
            return 1;
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    echo("All "+nTasks+" monitors are called.");
    return 0;
}
 
源代码5 项目: dragonwell8_jdk   文件: ReflectionExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码6 项目: TencentKona-8   文件: ThreadPoolAccTest.java
public static void main (String args[]) throws Exception {

        ObjectName[] mbeanNames = new ObjectName[6];
        ObservedObject[] monitored = new ObservedObject[6];
        ObjectName[] monitorNames = new ObjectName[6];
        Monitor[] monitor = new Monitor[6];
        String[] principals = { "role1", "role2" };
        String[] attributes = { "Integer", "Double", "String" };

        try {
            echo(">>> CREATE MBeanServer");
            MBeanServer server = MBeanServerFactory.newMBeanServer();

            for (int i = 0; i < 6; i++) {
                mbeanNames[i] =
                    new ObjectName(":type=ObservedObject,instance=" + i);
                monitored[i] = new ObservedObject();
                echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
                server.registerMBean(monitored[i], mbeanNames[i]);

                switch (i) {
                    case 0:
                    case 3:
                        monitorNames[i] =
                            new ObjectName(":type=CounterMonitor,instance=" + i);
                        monitor[i] = new CounterMonitor();
                        break;
                    case 1:
                    case 4:
                        monitorNames[i] =
                            new ObjectName(":type=GaugeMonitor,instance=" + i);
                        monitor[i] = new GaugeMonitor();
                        break;
                    case 2:
                    case 5:
                        monitorNames[i] =
                            new ObjectName(":type=StringMonitor,instance=" + i);
                        monitor[i] = new StringMonitor();
                        break;
                }

                echo(">>> CREATE Monitor = " + monitorNames[i].toString());
                server.registerMBean(monitor[i], monitorNames[i]);
                monitor[i].addObservedObject(mbeanNames[i]);
                monitor[i].setObservedAttribute(attributes[i % 3]);
                monitor[i].setGranularityPeriod(500);
                final Monitor m = monitor[i];
                Subject subject = new Subject();
                echo(">>> RUN Principal = " + principals[i / 3]);
                subject.getPrincipals().add(new JMXPrincipal(principals[i / 3]));
                PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
                    public Void run() {
                        m.start();
                        return null;
                    }
                };
                Subject.doAs(subject, action);
            }

            while(!testPrincipals(monitored, monitorNames, monitor, principals));

        } finally {
            for (int i = 0; i < 6; i++)
                if (monitor[i] != null)
                    monitor[i].stop();
        }
    }
 
源代码7 项目: TencentKona-8   文件: StartStopTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {

    int nTasks = maxPoolSize + 2;
    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
        }

        for (int j = 0; j < 2; j++) {
            echo(">>> Start MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].start();
            echo(">>> MONITORS started");
            doSleep(500);
            echo(">>> Check FLAGS true");
            for (int i = 0; i < nTasks; i++)
                if (!monitored[i].called) {
                    echo("KO: At least one attribute was not called");
                    return 1;
                }
            echo(">>> FLAGS checked true");
            echo(">>> Stop MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].stop();
            echo(">>> MONITORS stopped");
            doSleep(500);
            echo(">>> Set FLAGS to false");
            for (int i = 0; i < nTasks; i++)
                monitored[i].called = false;
            echo(">>> FLAGS set to false");
            echo(">>> Check FLAGS remain false");
            for (int i = 0; i < nTasks; i++)
                if (monitored[i].called) {
                    echo("KO: At least one attribute " +
                         "continued to get called");
                    return 1;
                }
            echo(">>> FLAGS checked false");
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    return 0;
}
 
源代码8 项目: TencentKona-8   文件: RuntimeExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码9 项目: TencentKona-8   文件: ThreadPoolTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {


    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
            monitor[i].start();
        }

        if (!waiter.waiting(MAX_WAITING_TIME)) {
            echo("Error, not all "+nTasks+" monitor tasks are called after "
                 +MAX_WAITING_TIME);
            return 1;
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    echo("All "+nTasks+" monitors are called.");
    return 0;
}
 
源代码10 项目: TencentKona-8   文件: ReflectionExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码11 项目: jdk8u60   文件: ThreadPoolAccTest.java
public static void main (String args[]) throws Exception {

        ObjectName[] mbeanNames = new ObjectName[6];
        ObservedObject[] monitored = new ObservedObject[6];
        ObjectName[] monitorNames = new ObjectName[6];
        Monitor[] monitor = new Monitor[6];
        String[] principals = { "role1", "role2" };
        String[] attributes = { "Integer", "Double", "String" };

        try {
            echo(">>> CREATE MBeanServer");
            MBeanServer server = MBeanServerFactory.newMBeanServer();

            for (int i = 0; i < 6; i++) {
                mbeanNames[i] =
                    new ObjectName(":type=ObservedObject,instance=" + i);
                monitored[i] = new ObservedObject();
                echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
                server.registerMBean(monitored[i], mbeanNames[i]);

                switch (i) {
                    case 0:
                    case 3:
                        monitorNames[i] =
                            new ObjectName(":type=CounterMonitor,instance=" + i);
                        monitor[i] = new CounterMonitor();
                        break;
                    case 1:
                    case 4:
                        monitorNames[i] =
                            new ObjectName(":type=GaugeMonitor,instance=" + i);
                        monitor[i] = new GaugeMonitor();
                        break;
                    case 2:
                    case 5:
                        monitorNames[i] =
                            new ObjectName(":type=StringMonitor,instance=" + i);
                        monitor[i] = new StringMonitor();
                        break;
                }

                echo(">>> CREATE Monitor = " + monitorNames[i].toString());
                server.registerMBean(monitor[i], monitorNames[i]);
                monitor[i].addObservedObject(mbeanNames[i]);
                monitor[i].setObservedAttribute(attributes[i % 3]);
                monitor[i].setGranularityPeriod(500);
                final Monitor m = monitor[i];
                Subject subject = new Subject();
                echo(">>> RUN Principal = " + principals[i / 3]);
                subject.getPrincipals().add(new JMXPrincipal(principals[i / 3]));
                PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
                    public Void run() {
                        m.start();
                        return null;
                    }
                };
                Subject.doAs(subject, action);
            }

            while(!testPrincipals(monitored, monitorNames, monitor, principals));

        } finally {
            for (int i = 0; i < 6; i++)
                if (monitor[i] != null)
                    monitor[i].stop();
        }
    }
 
源代码12 项目: jdk8u60   文件: StartStopTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {

    int nTasks = maxPoolSize + 2;
    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
        }

        for (int j = 0; j < 2; j++) {
            echo(">>> Start MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].start();
            echo(">>> MONITORS started");
            doSleep(500);
            echo(">>> Check FLAGS true");
            for (int i = 0; i < nTasks; i++)
                if (!monitored[i].called) {
                    echo("KO: At least one attribute was not called");
                    return 1;
                }
            echo(">>> FLAGS checked true");
            echo(">>> Stop MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].stop();
            echo(">>> MONITORS stopped");
            doSleep(500);
            echo(">>> Set FLAGS to false");
            for (int i = 0; i < nTasks; i++)
                monitored[i].called = false;
            echo(">>> FLAGS set to false");
            echo(">>> Check FLAGS remain false");
            for (int i = 0; i < nTasks; i++)
                if (monitored[i].called) {
                    echo("KO: At least one attribute " +
                         "continued to get called");
                    return 1;
                }
            echo(">>> FLAGS checked false");
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    return 0;
}
 
源代码13 项目: jdk8u60   文件: RuntimeExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码14 项目: jdk8u60   文件: ThreadPoolTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {


    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
            monitor[i].start();
        }

        if (!waiter.waiting(MAX_WAITING_TIME)) {
            echo("Error, not all "+nTasks+" monitor tasks are called after "
                 +MAX_WAITING_TIME);
            return 1;
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    echo("All "+nTasks+" monitors are called.");
    return 0;
}
 
源代码15 项目: jdk8u60   文件: ReflectionExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码16 项目: openjdk-jdk8u   文件: ThreadPoolAccTest.java
public static void main (String args[]) throws Exception {

        ObjectName[] mbeanNames = new ObjectName[6];
        ObservedObject[] monitored = new ObservedObject[6];
        ObjectName[] monitorNames = new ObjectName[6];
        Monitor[] monitor = new Monitor[6];
        String[] principals = { "role1", "role2" };
        String[] attributes = { "Integer", "Double", "String" };

        try {
            echo(">>> CREATE MBeanServer");
            MBeanServer server = MBeanServerFactory.newMBeanServer();

            for (int i = 0; i < 6; i++) {
                mbeanNames[i] =
                    new ObjectName(":type=ObservedObject,instance=" + i);
                monitored[i] = new ObservedObject();
                echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
                server.registerMBean(monitored[i], mbeanNames[i]);

                switch (i) {
                    case 0:
                    case 3:
                        monitorNames[i] =
                            new ObjectName(":type=CounterMonitor,instance=" + i);
                        monitor[i] = new CounterMonitor();
                        break;
                    case 1:
                    case 4:
                        monitorNames[i] =
                            new ObjectName(":type=GaugeMonitor,instance=" + i);
                        monitor[i] = new GaugeMonitor();
                        break;
                    case 2:
                    case 5:
                        monitorNames[i] =
                            new ObjectName(":type=StringMonitor,instance=" + i);
                        monitor[i] = new StringMonitor();
                        break;
                }

                echo(">>> CREATE Monitor = " + monitorNames[i].toString());
                server.registerMBean(monitor[i], monitorNames[i]);
                monitor[i].addObservedObject(mbeanNames[i]);
                monitor[i].setObservedAttribute(attributes[i % 3]);
                monitor[i].setGranularityPeriod(500);
                final Monitor m = monitor[i];
                Subject subject = new Subject();
                echo(">>> RUN Principal = " + principals[i / 3]);
                subject.getPrincipals().add(new JMXPrincipal(principals[i / 3]));
                PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
                    public Void run() {
                        m.start();
                        return null;
                    }
                };
                Subject.doAs(subject, action);
            }

            while(!testPrincipals(monitored, monitorNames, monitor, principals));

        } finally {
            for (int i = 0; i < 6; i++)
                if (monitor[i] != null)
                    monitor[i].stop();
        }
    }
 
源代码17 项目: openjdk-jdk8u   文件: StartStopTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {

    int nTasks = maxPoolSize + 2;
    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
        }

        for (int j = 0; j < 2; j++) {
            echo(">>> Start MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].start();
            echo(">>> MONITORS started");
            doSleep(500);
            echo(">>> Check FLAGS true");
            for (int i = 0; i < nTasks; i++)
                if (!monitored[i].called) {
                    echo("KO: At least one attribute was not called");
                    return 1;
                }
            echo(">>> FLAGS checked true");
            echo(">>> Stop MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].stop();
            echo(">>> MONITORS stopped");
            doSleep(500);
            echo(">>> Set FLAGS to false");
            for (int i = 0; i < nTasks; i++)
                monitored[i].called = false;
            echo(">>> FLAGS set to false");
            echo(">>> Check FLAGS remain false");
            for (int i = 0; i < nTasks; i++)
                if (monitored[i].called) {
                    echo("KO: At least one attribute " +
                         "continued to get called");
                    return 1;
                }
            echo(">>> FLAGS checked false");
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    return 0;
}
 
源代码18 项目: openjdk-jdk8u   文件: RuntimeExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码19 项目: openjdk-jdk8u   文件: ThreadPoolTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {


    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
            monitor[i].start();
        }

        if (!waiter.waiting(MAX_WAITING_TIME)) {
            echo("Error, not all "+nTasks+" monitor tasks are called after "
                 +MAX_WAITING_TIME);
            return 1;
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    echo("All "+nTasks+" monitors are called.");
    return 0;
}
 
源代码20 项目: openjdk-jdk8u   文件: ReflectionExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码21 项目: openjdk-jdk8u-backup   文件: ThreadPoolAccTest.java
public static void main (String args[]) throws Exception {

        ObjectName[] mbeanNames = new ObjectName[6];
        ObservedObject[] monitored = new ObservedObject[6];
        ObjectName[] monitorNames = new ObjectName[6];
        Monitor[] monitor = new Monitor[6];
        String[] principals = { "role1", "role2" };
        String[] attributes = { "Integer", "Double", "String" };

        try {
            echo(">>> CREATE MBeanServer");
            MBeanServer server = MBeanServerFactory.newMBeanServer();

            for (int i = 0; i < 6; i++) {
                mbeanNames[i] =
                    new ObjectName(":type=ObservedObject,instance=" + i);
                monitored[i] = new ObservedObject();
                echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
                server.registerMBean(monitored[i], mbeanNames[i]);

                switch (i) {
                    case 0:
                    case 3:
                        monitorNames[i] =
                            new ObjectName(":type=CounterMonitor,instance=" + i);
                        monitor[i] = new CounterMonitor();
                        break;
                    case 1:
                    case 4:
                        monitorNames[i] =
                            new ObjectName(":type=GaugeMonitor,instance=" + i);
                        monitor[i] = new GaugeMonitor();
                        break;
                    case 2:
                    case 5:
                        monitorNames[i] =
                            new ObjectName(":type=StringMonitor,instance=" + i);
                        monitor[i] = new StringMonitor();
                        break;
                }

                echo(">>> CREATE Monitor = " + monitorNames[i].toString());
                server.registerMBean(monitor[i], monitorNames[i]);
                monitor[i].addObservedObject(mbeanNames[i]);
                monitor[i].setObservedAttribute(attributes[i % 3]);
                monitor[i].setGranularityPeriod(500);
                final Monitor m = monitor[i];
                Subject subject = new Subject();
                echo(">>> RUN Principal = " + principals[i / 3]);
                subject.getPrincipals().add(new JMXPrincipal(principals[i / 3]));
                PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
                    public Void run() {
                        m.start();
                        return null;
                    }
                };
                Subject.doAs(subject, action);
            }

            while(!testPrincipals(monitored, monitorNames, monitor, principals));

        } finally {
            for (int i = 0; i < 6; i++)
                if (monitor[i] != null)
                    monitor[i].stop();
        }
    }
 
源代码22 项目: openjdk-jdk8u-backup   文件: StartStopTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {

    int nTasks = maxPoolSize + 2;
    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
        }

        for (int j = 0; j < 2; j++) {
            echo(">>> Start MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].start();
            echo(">>> MONITORS started");
            doSleep(500);
            echo(">>> Check FLAGS true");
            for (int i = 0; i < nTasks; i++)
                if (!monitored[i].called) {
                    echo("KO: At least one attribute was not called");
                    return 1;
                }
            echo(">>> FLAGS checked true");
            echo(">>> Stop MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].stop();
            echo(">>> MONITORS stopped");
            doSleep(500);
            echo(">>> Set FLAGS to false");
            for (int i = 0; i < nTasks; i++)
                monitored[i].called = false;
            echo(">>> FLAGS set to false");
            echo(">>> Check FLAGS remain false");
            for (int i = 0; i < nTasks; i++)
                if (monitored[i].called) {
                    echo("KO: At least one attribute " +
                         "continued to get called");
                    return 1;
                }
            echo(">>> FLAGS checked false");
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    return 0;
}
 
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码24 项目: openjdk-jdk8u-backup   文件: ThreadPoolTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {


    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
            monitor[i].start();
        }

        if (!waiter.waiting(MAX_WAITING_TIME)) {
            echo("Error, not all "+nTasks+" monitor tasks are called after "
                 +MAX_WAITING_TIME);
            return 1;
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    echo("All "+nTasks+" monitors are called.");
    return 0;
}
 
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码26 项目: openjdk-jdk9   文件: ThreadPoolAccTest.java
public static void main (String args[]) throws Exception {

        ObjectName[] mbeanNames = new ObjectName[6];
        ObservedObject[] monitored = new ObservedObject[6];
        ObjectName[] monitorNames = new ObjectName[6];
        Monitor[] monitor = new Monitor[6];
        String[] principals = { "role1", "role2" };
        String[] attributes = { "Integer", "Double", "String" };

        try {
            echo(">>> CREATE MBeanServer");
            MBeanServer server = MBeanServerFactory.newMBeanServer();

            for (int i = 0; i < 6; i++) {
                mbeanNames[i] =
                    new ObjectName(":type=ObservedObject,instance=" + i);
                monitored[i] = new ObservedObject();
                echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
                server.registerMBean(monitored[i], mbeanNames[i]);

                switch (i) {
                    case 0:
                    case 3:
                        monitorNames[i] =
                            new ObjectName(":type=CounterMonitor,instance=" + i);
                        monitor[i] = new CounterMonitor();
                        break;
                    case 1:
                    case 4:
                        monitorNames[i] =
                            new ObjectName(":type=GaugeMonitor,instance=" + i);
                        monitor[i] = new GaugeMonitor();
                        break;
                    case 2:
                    case 5:
                        monitorNames[i] =
                            new ObjectName(":type=StringMonitor,instance=" + i);
                        monitor[i] = new StringMonitor();
                        break;
                }

                echo(">>> CREATE Monitor = " + monitorNames[i].toString());
                server.registerMBean(monitor[i], monitorNames[i]);
                monitor[i].addObservedObject(mbeanNames[i]);
                monitor[i].setObservedAttribute(attributes[i % 3]);
                monitor[i].setGranularityPeriod(500);
                final Monitor m = monitor[i];
                Subject subject = new Subject();
                echo(">>> RUN Principal = " + principals[i / 3]);
                subject.getPrincipals().add(new JMXPrincipal(principals[i / 3]));
                PrivilegedAction<Void> action = new PrivilegedAction<Void>() {
                    public Void run() {
                        m.start();
                        return null;
                    }
                };
                Subject.doAs(subject, action);
            }

            while(!testPrincipals(monitored, monitorNames, monitor, principals));

        } finally {
            for (int i = 0; i < 6; i++)
                if (monitor[i] != null)
                    monitor[i].stop();
        }
    }
 
源代码27 项目: openjdk-jdk9   文件: StartStopTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {

    int nTasks = maxPoolSize + 2;
    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
        }

        for (int j = 0; j < 2; j++) {
            echo(">>> Start MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].start();
            echo(">>> MONITORS started");
            doSleep(500);
            echo(">>> Check FLAGS true");
            for (int i = 0; i < nTasks; i++)
                if (!monitored[i].called) {
                    echo("KO: At least one attribute was not called");
                    return 1;
                }
            echo(">>> FLAGS checked true");
            echo(">>> Stop MONITORS");
            for (int i = 0; i < nTasks; i++)
                monitor[i].stop();
            echo(">>> MONITORS stopped");
            doSleep(500);
            echo(">>> Set FLAGS to false");
            for (int i = 0; i < nTasks; i++)
                monitored[i].called = false;
            echo(">>> FLAGS set to false");
            echo(">>> Check FLAGS remain false");
            for (int i = 0; i < nTasks; i++)
                if (monitored[i].called) {
                    echo("KO: At least one attribute " +
                         "continued to get called");
                    return 1;
                }
            echo(">>> FLAGS checked false");
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    return 0;
}
 
源代码28 项目: openjdk-jdk9   文件: RuntimeExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
源代码29 项目: openjdk-jdk9   文件: ThreadPoolTest.java
/**
 * Run test
 */
public int runTest(int monitorType) throws Exception {


    ObjectName[] mbeanNames = new ObjectName[nTasks];
    ObservedObject[] monitored = new ObservedObject[nTasks];
    ObjectName[] monitorNames = new ObjectName[nTasks];
    Monitor[] monitor = new Monitor[nTasks];
    String[] attributes = { "Integer", "Double", "String" };

    try {
        echo(">>> CREATE MBeanServer");
        MBeanServer server = MBeanServerFactory.newMBeanServer();

        String domain = server.getDefaultDomain();

        for (int i = 0; i < nTasks; i++) {
            mbeanNames[i] =
                new ObjectName(":type=ObservedObject,instance=" + (i + 1));
            monitored[i] = new ObservedObject();
            echo(">>> CREATE ObservedObject = " + mbeanNames[i].toString());
            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();
                break;
            case 3:
                monitorNames[i] = new ObjectName(":type=StringMonitor," +
                                                 "instance=" + (i + 1));
                monitor[i] = new StringMonitor();
                break;
            default:
                echo("Unsupported monitor type");
                return 1;
            }
            echo(">>> CREATE Monitor = " + monitorNames[i].toString());
            server.registerMBean(monitor[i], monitorNames[i]);
            monitor[i].addObservedObject(mbeanNames[i]);
            monitor[i].setObservedAttribute(attributes[monitorType-1]);
            monitor[i].setGranularityPeriod(50);
            monitor[i].start();
        }

        if (!waiter.waiting(MAX_WAITING_TIME)) {
            echo("Error, not all "+nTasks+" monitor tasks are called after "
                 +MAX_WAITING_TIME);
            return 1;
        }
    } finally {
        for (int i = 0; i < nTasks; i++)
            if (monitor[i] != null)
                monitor[i].stop();
    }

    echo("All "+nTasks+" monitors are called.");
    return 0;
}
 
源代码30 项目: openjdk-jdk9   文件: ReflectionExceptionTest.java
/**
 * Update the gauge and check for notifications
 */
public int gaugeMonitorNotification() throws Exception {

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

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

        //
        // MANAGEMENT OF A STANDARD MBEAN
        //

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

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

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

        gaugeMonitor.setNotifyLow(false);
        gaugeMonitor.setNotifyHigh(false);
        echo("\tATTRIBUTE \"Notify Low  Flag\"  = false");
        echo("\tATTRIBUTE \"Notify High Flag\"  = false");

        Integer highThreshold = 3, lowThreshold = 2;
        gaugeMonitor.setThresholds(highThreshold, lowThreshold);
        echo("\tATTRIBUTE \"Low  Threshold\"    = " + lowThreshold);
        echo("\tATTRIBUTE \"High Threshold\"    = " + highThreshold);

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

        echo(">>> START the GaugeMonitor");
        gaugeMonitor.start();

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

    return 0;
}
 
 类所在包
 同包方法