Search in sources :

Example 6 with StringMonitor

use of javax.management.monitor.StringMonitor in project jdk8u_jdk by JetBrains.

the class ReflectionExceptionTest method stringMonitorNotification.

/**
     * Update the string and check for notifications
     */
public int stringMonitorNotification() throws Exception {
    StringMonitor stringMonitor = new StringMonitor();
    try {
        // Create a new StringMonitor MBean and add it to the MBeanServer.
        //
        echo(">>> CREATE a new StringMonitor MBean");
        ObjectName stringMonitorName = new ObjectName(domain + ":type=" + StringMonitor.class.getName());
        server.registerMBean(stringMonitor, stringMonitorName);
        echo(">>> ADD a listener to the StringMonitor");
        stringMonitor.addNotificationListener(this, null, null);
        //
        // MANAGEMENT OF A STANDARD MBEAN
        //
        echo(">>> SET the attributes of the StringMonitor:");
        stringMonitor.addObservedObject(obsObjName);
        echo("\tATTRIBUTE \"ObservedObject\"    = " + obsObjName);
        stringMonitor.setObservedAttribute("StringAttribute");
        echo("\tATTRIBUTE \"ObservedAttribute\" = StringAttribute");
        stringMonitor.setNotifyMatch(false);
        echo("\tATTRIBUTE \"NotifyMatch\"       = false");
        stringMonitor.setNotifyDiffer(false);
        echo("\tATTRIBUTE \"NotifyDiffer\"      = false");
        stringMonitor.setStringToCompare("dummy");
        echo("\tATTRIBUTE \"StringToCompare\"   = \"dummy\"");
        int granularityperiod = 500;
        stringMonitor.setGranularityPeriod(granularityperiod);
        echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
        echo(">>> START the StringMonitor");
        stringMonitor.start();
        // Check if notification was received
        //
        doWait();
        if (messageReceived) {
            echo("\tOK: StringMonitor got RUNTIME_ERROR notification!");
        } else {
            echo("\tKO: StringMonitor did not get " + "RUNTIME_ERROR notification!");
            return 1;
        }
    } finally {
        messageReceived = false;
        if (stringMonitor != null)
            stringMonitor.stop();
    }
    return 0;
}
Also used : StringMonitor(javax.management.monitor.StringMonitor) ObjectName(javax.management.ObjectName)

Example 7 with StringMonitor

use of javax.management.monitor.StringMonitor in project jdk8u_jdk by JetBrains.

the class StartStopTest method runTest.

/**
     * 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;
}
Also used : GaugeMonitor(javax.management.monitor.GaugeMonitor) ObjectName(javax.management.ObjectName) StringMonitor(javax.management.monitor.StringMonitor) StringMonitor(javax.management.monitor.StringMonitor) CounterMonitor(javax.management.monitor.CounterMonitor) Monitor(javax.management.monitor.Monitor) GaugeMonitor(javax.management.monitor.GaugeMonitor) CounterMonitor(javax.management.monitor.CounterMonitor) MBeanServer(javax.management.MBeanServer)

Aggregations

ObjectName (javax.management.ObjectName)7 StringMonitor (javax.management.monitor.StringMonitor)7 MBeanServer (javax.management.MBeanServer)4 CounterMonitor (javax.management.monitor.CounterMonitor)4 GaugeMonitor (javax.management.monitor.GaugeMonitor)4 Monitor (javax.management.monitor.Monitor)4 PrivilegedAction (java.security.PrivilegedAction)1 NotificationFilter (javax.management.NotificationFilter)1 JMXPrincipal (javax.management.remote.JMXPrincipal)1 Subject (javax.security.auth.Subject)1