test/javax/management/monitor/CounterMonitorTest.java
Print this page
@@ -41,13 +41,10 @@
private Number threshold = new Integer(2);
// modulus number
private Number modulus = new Integer(7);
- // offset number
- private int offset = 0;
-
// difference mode flag
private boolean differenceModeFlag = true;
// notify flag
private boolean notifyFlag = true;
@@ -56,13 +53,10 @@
private int granularityperiod = 500;
// counter values
private int[] values = new int[] {4, 6, 9, 11};
- // time to wait for notification (in seconds)
- private int timeout = 5;
-
// flag to notify that a message has been received
private volatile boolean messageReceived = false;
// MBean class
public class StdObservedObject implements StdObservedObjectMBean {
@@ -90,12 +84,13 @@
try {
if (type.equals(MonitorNotification.THRESHOLD_VALUE_EXCEEDED)) {
echo("\t\t" + n.getObservedAttribute() +
" has reached or exceeded the threshold");
echo("\t\tDerived Gauge = " + n.getDerivedGauge());
- messageReceived = true;
+
synchronized (this) {
+ messageReceived = true;
notifyAll();
}
} else {
echo("\t\tSkipping notification of type: " + type);
}
@@ -203,25 +198,20 @@
echo(">>> Bye! Bye!");
}
/*
- * Wait until timeout reached
+ * Wait messageReceived to be true
*/
- void doWait() {
- for (int i = 0; i < timeout; i++) {
- echo("\tdoWait: Waiting for " + timeout + " seconds. " +
- "i = " + i + ", messageReceived = " + messageReceived);
- if (messageReceived) {
- break;
- }
+ synchronized void doWait() {
+ while (!messageReceived) {
try {
- synchronized (this) {
- wait(1000);
- }
+ wait();
} catch (InterruptedException e) {
- // OK: Ignore...
+ System.err.println("Got unexpected exception: " + e);
+ e.printStackTrace();
+ break;
}
}
}
/*