/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 4984057
* @summary Test that monitors can sample a large number of attributes
* @author Eamonn McManus
* @run clean MultiMonitorTest
* @run build MultiMonitorTest
* @run main MultiMonitorTest
*/
import javax.management.*;
/* We create N MBeans and three monitors, one for each different
monitor type. Each monitor monitors a single attribute in each of
the N MBeans. We arrange for the trigger condition to be
satisfied, so the listener we register on each monitor should get N
notifications. */
public class MultiMonitorTest {
static final int N = 100;
"number of attributes");
for (int i = 0; i < N; i++) {
}
final ObjectName counterMonitor =
new ObjectName(":type=CounterMonitor");
final ObjectName gaugeMonitor =
new ObjectName(":type=GaugeMonitor");
final ObjectName stringMonitor =
new ObjectName(":type=StringMonitor");
final ObjectName[] monitorNames =
false);
false);
false);
};
for (int i = 0; i < 3; i++) {
for (int j = 0; j < N; j++)
}
};
for (int i = 0; i < 3; i++) {
}
counterProxy.setNotify(true);
gaugeProxy.setNotifyHigh(true);
stringProxy.setNotifyDiffer(true);
// A couple of granularity periods to detect bad behaviour
}
for (int i = 0; i < 3; i++)
while (!listenersAreAll(N, listeners)
// More time for bad behaviour
if (!listenersAreAll(N, listeners)) {
}
for (int i = 0; i < 3; i++) {
for (int j = 0; j < N; j++)
}
}
}
public static interface MonitoredMBean {
public int getCounterValue();
public double getGaugeValue();
}
/* We give a small random number of normal readings (possibly
zero) before giving a reading that provokes a
notification. */
public synchronized int getCounterValue() {
if (--okCounter >= 0)
return 0;
else
return OVER_COUNTER_THRESHOLD;
}
public synchronized double getGaugeValue() {
if (--okGauge >= 0)
return 0.0;
else
return OVER_GAUGE_THRESHOLD;
}
if (--okString >= 0)
return STRING_TO_COMPARE;
else
return DIFFERENT_STRING;
}
}
private int count;
if (!(n instanceof MonitorNotification)) {
}
}
count++;
}
public synchronized int getCount() {
return count;
}
}
return false;
}
return true;
}
static synchronized int randomInt(int n) {
}
}