test/javax/management/monitor/NonComparableAttributeValueTest.java
Print this page
*** 37,47 ****
import javax.management.monitor.*;
public class NonComparableAttributeValueTest implements NotificationListener {
// Flag to notify that a message has been received
! private boolean messageReceived = false;
// MBean class
public class ObservedObject implements ObservedObjectMBean {
public Object getIntegerAttribute() {
return new Object();
--- 37,47 ----
import javax.management.monitor.*;
public class NonComparableAttributeValueTest implements NotificationListener {
// Flag to notify that a message has been received
! private volatile boolean messageReceived = false;
// MBean class
public class ObservedObject implements ObservedObjectMBean {
public Object getIntegerAttribute() {
return new Object();
*** 67,77 ****
--- 67,81 ----
if (type.equals(
MonitorNotification.OBSERVED_ATTRIBUTE_TYPE_ERROR)) {
echo("\t\t" + n.getObservedAttribute() + " is null");
echo("\t\tDerived Gauge = " + n.getDerivedGauge());
echo("\t\tTrigger = " + n.getTrigger());
+
+ synchronized (this) {
messageReceived = true;
+ notifyAll();
+ }
} else {
echo("\t\tSkipping notification of type: " + type);
}
} catch (Exception e) {
echo("\tError in handleNotification!");
*** 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 notification received");
} else {
echo("\tKO: CounterMonitor notification missed or not emitted");
return 1;
--- 136,148 ----
echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
echo(">>> START the CounterMonitor");
counterMonitor.start();
// Check if notification was received
//
+ doWait();
if (messageReceived) {
echo("\tOK: CounterMonitor notification received");
} else {
echo("\tKO: CounterMonitor notification missed or not emitted");
return 1;
*** 210,225 ****
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 notification received");
} else {
echo("\tKO: GaugeMonitor notification missed or not emitted");
return 1;
--- 211,223 ----
echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
echo(">>> START the GaugeMonitor");
gaugeMonitor.start();
// Check if notification was received
//
+ doWait();
if (messageReceived) {
echo("\tOK: GaugeMonitor notification received");
} else {
echo("\tKO: GaugeMonitor notification missed or not emitted");
return 1;
*** 285,302 ****
int granularityperiod = 500;
stringMonitor.setGranularityPeriod(granularityperiod);
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 notification received");
} else {
echo("\tKO: StringMonitor notification missed or not emitted");
return 1;
--- 283,296 ----
int granularityperiod = 500;
stringMonitor.setGranularityPeriod(granularityperiod);
echo("\tATTRIBUTE \"GranularityPeriod\" = " + granularityperiod);
echo(">>> START the StringMonitor");
// Check if notification was received
//
+ doWait();
if (messageReceived) {
echo("\tOK: StringMonitor notification received");
} else {
echo("\tKO: StringMonitor notification missed or not emitted");
return 1;
*** 332,341 ****
--- 326,350 ----
private static void echo(String message) {
System.out.println(message);
}
/*
+ * 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;
+ }
+ }
+ }
+
+ /*
* Standalone entry point.
*
* Run the test and report to stdout.
*/
public static void main (String args[]) throws Exception {