test/javax/management/monitor/RuntimeExceptionTest.java
Print this page
*** 84,94 ****
--- 84,98 ----
echo("\tTimeStamp: " + mn.getTimeStamp());
echo("\tObservedObject: " + mn.getObservedObject());
echo("\tObservedAttribute: " + mn.getObservedAttribute());
echo("\tDerivedGauge: " + mn.getDerivedGauge());
echo("\tTrigger: " + mn.getTrigger());
+
+ synchronized (this) {
messageReceived = true;
+ notifyAll();
+ }
}
}
}
/**
*** 132,147 ****
echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
echo(">>> START the CounterMonitor");
counterMonitor.start();
- // Wait for granularity period (multiplied by 2 for sure)
- //
- Thread.sleep(granularityperiod * 2);
-
// Check if notification was received
//
if (messageReceived) {
echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
} else {
echo("\tKO: CounterMonitor did not get " +
"RUNTIME_ERROR notification!");
--- 136,148 ----
echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
echo(">>> START the CounterMonitor");
counterMonitor.start();
// Check if notification was received
//
+ doWait();
if (messageReceived) {
echo("\tOK: CounterMonitor got RUNTIME_ERROR notification!");
} else {
echo("\tKO: CounterMonitor did not get " +
"RUNTIME_ERROR notification!");
*** 200,215 ****
echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
echo(">>> START the GaugeMonitor");
gaugeMonitor.start();
- // Wait for granularity period (multiplied by 2 for sure)
- //
- Thread.sleep(granularityperiod * 2);
-
// Check if notification was received
//
if (messageReceived) {
echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
} else {
echo("\tKO: GaugeMonitor did not get " +
"RUNTIME_ERROR notification!");
--- 201,213 ----
echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
echo(">>> START the GaugeMonitor");
gaugeMonitor.start();
// Check if notification was received
//
+ doWait();
if (messageReceived) {
echo("\tOK: GaugeMonitor got RUNTIME_ERROR notification!");
} else {
echo("\tKO: GaugeMonitor did not get " +
"RUNTIME_ERROR notification!");
*** 267,282 ****
echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
echo(">>> START the StringMonitor");
stringMonitor.start();
- // Wait for granularity period (multiplied by 2 for sure)
- //
- Thread.sleep(granularityperiod * 2);
-
// Check if notification was received
//
if (messageReceived) {
echo("\tOK: StringMonitor got RUNTIME_ERROR notification!");
} else {
echo("\tKO: StringMonitor did not get " +
"RUNTIME_ERROR notification!");
--- 265,277 ----
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!");
*** 345,356 ****
} else {
echo(">>> Happy Bye, Bye!");
}
}
// Flag to notify that a message has been received
! private boolean messageReceived = false;
private MBeanServer server;
private ObjectName obsObjName;
private String domain;
}
--- 340,366 ----
} else {
echo(">>> Happy Bye, Bye!");
}
}
+ /*
+ * Wait messageReceived to be true
+ */
+ synchronized void doWait() {
+ while (!messageReceived) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ System.err.println("Got unexpected exception: " + e);
+ e.printStackTrace();
+ break;
+ }
+ }
+ }
+
// Flag to notify that a message has been received
! private volatile boolean messageReceived = false;
private MBeanServer server;
private ObjectName obsObjName;
private String domain;
}