Java Code Examples for javax.management.monitor.Monitor

The following examples show how to use javax.management.monitor.Monitor. These examples are extracted from open source projects. 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 Project: dragonwell8_jdk   Author: alibaba   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #2
Source Project: TencentKona-8   Author: Tencent   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #3
Source Project: jdk8u60   Author: chenghanpeng   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #4
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #5
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #6
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #7
Source Project: jdk8u-jdk   Author: lambdalab-mirror   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #8
Source Project: hottub   Author: dsrg-uoft   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #9
Source Project: openjdk-8-source   Author: keerath   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #10
Source Project: openjdk-8   Author: bpupadhyaya   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #11
Source Project: jdk8u_jdk   Author: JetBrains   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #12
Source Project: jdk8u-jdk   Author: frohoff   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #13
Source Project: jdk8u-dev-jdk   Author: frohoff   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 6 votes vote down vote up
private static boolean testPrincipals(ObservedObject[] monitored, ObjectName[] monitorNames,
        Monitor[] monitor, String[] principals) throws Exception {
    for (int i = 0; i < 6; i++) {
        String principal =  monitored[i].principal;
        String expected = principals[i / 3];
        if (principal == null) {
            echo("Task not submitted " + new Date() + ". RETRY");
            return false;
        }
        echo(">>> Monitor = " + monitorNames[i]);
        echo(">>> ObservedObject = " + monitor[i].getObservedObject());
        echo(">>> ObservedAttribute = " + monitor[i].getObservedAttribute());
        echo(">>> Principal = " + principal);

        if (expected.equals(principal)) {
            echo("\tOK: Got Expected principal");
        } else {
            throw new Exception("Unexpected principal. Got: " + principal + " Expected: " + expected);
        }
    }
    return true;
}
 
Example #14
Source Project: dragonwell8_jdk   Author: alibaba   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
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();
        }
    }
 
Example #15
Source Project: dragonwell8_jdk   Author: alibaba   File: StartStopTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #16
Source Project: dragonwell8_jdk   Author: alibaba   File: ThreadPoolTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #17
Source Project: TencentKona-8   Author: Tencent   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
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();
        }
    }
 
Example #18
Source Project: TencentKona-8   Author: Tencent   File: StartStopTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #19
Source Project: TencentKona-8   Author: Tencent   File: ThreadPoolTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #20
Source Project: jdk8u60   Author: chenghanpeng   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
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();
        }
    }
 
Example #21
Source Project: jdk8u60   Author: chenghanpeng   File: StartStopTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #22
Source Project: jdk8u60   Author: chenghanpeng   File: ThreadPoolTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #23
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
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();
        }
    }
 
Example #24
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: StartStopTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #25
Source Project: openjdk-jdk8u   Author: AdoptOpenJDK   File: ThreadPoolTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #26
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
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();
        }
    }
 
Example #27
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: StartStopTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #28
Source Project: openjdk-jdk8u-backup   Author: AdoptOpenJDK   File: ThreadPoolTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}
 
Example #29
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: ThreadPoolAccTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
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();
        }
    }
 
Example #30
Source Project: openjdk-jdk9   Author: AdoptOpenJDK   File: StartStopTest.java    License: GNU General Public License v2.0 4 votes vote down vote up
/**
 * 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;
}