jdk/test/javax/management/monitor/CounterMonitorTest.java
author stefank
Fri, 17 Apr 2015 17:10:38 +0000
changeset 30266 ef82cd1f2db3
parent 28054 8b0ef141b964
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
     2
 * Copyright (c) 2004, 2014, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 4981829
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Test that the counter monitor, when running in difference mode,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 *          emits a notification every time the threshold is exceeded.
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    29
 * @author Luis-Miguel Alventosa, Shanliang JIANG
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean CounterMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build CounterMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main CounterMonitorTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import javax.management.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import javax.management.monitor.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
public class CounterMonitorTest implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    // threshold number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
    private Number threshold = new Integer(2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    // modulus number
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
    private Number modulus = new Integer(7);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    // difference mode flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    private boolean differenceModeFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    // notify flag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    private boolean notifyFlag = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    // granularity period
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    53
    private int granularityperiod = 10;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    55
    // derived gauge
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    56
    private volatile int derivedGauge = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    // flag to notify that a message has been received
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
    private volatile boolean messageReceived = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    61
    private volatile Object observedValue = null;
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    62
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    // MBean class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
    public class StdObservedObject implements StdObservedObjectMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
        public Object getNbObjects() {
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    66
            echo(">>> StdObservedObject.getNbObjects: " + count);
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    67
            synchronized(CounterMonitorTest.class) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    68
                observedValue = count;
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    69
                CounterMonitorTest.class.notifyAll();
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    70
            }
28054
8b0ef141b964 8066952: [TEST-BUG] javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 27796
diff changeset
    71
            return observedValue;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
        public void setNbObjects(Object n) {
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    74
            echo(">>> StdObservedObject.setNbObjects: " + n);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            count = n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        }
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
    77
        private volatile Object count= null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    // MBean interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    public interface StdObservedObjectMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        public Object getNbObjects();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        public void setNbObjects(Object n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    // Notification handler
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public void handleNotification(Notification notification,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                                   Object handback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        MonitorNotification n = (MonitorNotification) notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        echo("\tInside handleNotification...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        String type = n.getType();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            if (type.equals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                echo("\t\t" + n.getObservedAttribute() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                     " has reached or exceeded the threshold");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                echo("\t\tDerived Gauge = " + n.getDerivedGauge());
26623
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
    97
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                synchronized (this) {
26623
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
    99
                    messageReceived = true;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                    notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                echo("\t\tSkipping notification of type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            echo("\tError in handleNotification!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     * Update the counter and check for notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    public void thresholdNotification() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        CounterMonitor counterMonitor = new CounterMonitor();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            MBeanServer server = MBeanServerFactory.newMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            String domain = server.getDefaultDomain();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            // Create a new CounterMonitor MBean and add it to the MBeanServer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            echo(">>> CREATE a new CounterMonitor MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            ObjectName counterMonitorName = new ObjectName(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                            domain + ":type=" + CounterMonitor.class.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            server.registerMBean(counterMonitor, counterMonitorName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            echo(">>> ADD a listener to the CounterMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            counterMonitor.addNotificationListener(this, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            // MANAGEMENT OF A STANDARD MBEAN
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            echo(">>> CREATE a new StdObservedObject MBean");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            ObjectName stdObsObjName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                new ObjectName(domain + ":type=StdObservedObject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            StdObservedObject stdObsObj = new StdObservedObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            server.registerMBean(stdObsObj, stdObsObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            echo(">>> SET the attributes of the CounterMonitor:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            counterMonitor.addObservedObject(stdObsObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            echo("\tATTRIBUTE \"ObservedObject\"    = " + stdObsObjName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            counterMonitor.setObservedAttribute("NbObjects");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            echo("\tATTRIBUTE \"ObservedAttribute\" = NbObjects");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            counterMonitor.setNotify(notifyFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            echo("\tATTRIBUTE \"Notify\"            = " + notifyFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            counterMonitor.setInitThreshold(threshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            echo("\tATTRIBUTE \"Threshold\"         = " + threshold);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            counterMonitor.setGranularityPeriod(granularityperiod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            counterMonitor.setModulus(modulus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            echo("\tATTRIBUTE \"Modulus\"           = " + modulus);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            counterMonitor.setDifferenceMode(differenceModeFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            echo("\tATTRIBUTE \"DifferenceMode\"    = " + differenceModeFlag);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            echo(">>> START the CounterMonitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            counterMonitor.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            // Set initial value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            Integer data = new Integer(0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            echo(">>> Set data = " + data.intValue());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            Attribute attrib = new Attribute("NbObjects", data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            server.setAttribute(stdObsObjName, attrib);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   177
            waitObservation(data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            // Loop through the values
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            //
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   181
            while (derivedGauge++ < 10) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   182
                System.out.print(">>> Set data from " + data.intValue());
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   183
                data = new Integer(data.intValue() + derivedGauge);
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   184
                echo(" to " + data.intValue());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                attrib = new Attribute("NbObjects", data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                server.setAttribute(stdObsObjName, attrib);
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   188
                waitObservation(data);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                echo("\tdoWait in Counter Monitor");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                doWait();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                // Check if notification was received
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                if (messageReceived) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                    echo("\tOKAY: Notification received");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
                    echo("\tError: notification missed or not emitted");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                    throw new IllegalStateException("Notification lost");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                messageReceived = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            counterMonitor.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        echo(">>> Bye! Bye!");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /*
26623
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   211
     * Wait messageReceived to be true
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     */
26623
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   213
    synchronized void doWait() {
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   214
        while (!messageReceived) {
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   215
            try {
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   216
                wait();
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   217
            } catch (InterruptedException e) {
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   218
                System.err.println("Got unexpected exception: " + e);
11289cf5c8fc 8042205: javax/management/monitor/*: some tests didn't get all the notifications
sjiang
parents: 5506
diff changeset
   219
                e.printStackTrace();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
27796
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   225
    private void waitObservation(Object value) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   226
        synchronized (CounterMonitorTest.class) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   227
            while (value != observedValue) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   228
                try {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   229
                    CounterMonitorTest.class.wait();
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   230
                } catch (InterruptedException e) {
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   231
                    System.err.println("Got unexpected exception: " + e);
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   232
                    e.printStackTrace();
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   233
                    break;
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   234
                }
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   235
            }
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   236
        }
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   237
    }
5052f749052a 8065764: javax/management/monitor/CounterMonitorTest.java hangs
sjiang
parents: 26623
diff changeset
   238
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Print message
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    void echo(String message) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        System.out.println(message);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * Standalone entry point.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * Run the test and report to stdout.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public static void main (String args[]) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        CounterMonitorTest test = new CounterMonitorTest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        test.thresholdNotification();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
}