2362N/A * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved. 0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 0N/A * This code is free software; you can redistribute it and/or modify it 0N/A * under the terms of the GNU General Public License version 2 only, as 0N/A * published by the Free Software Foundation. 0N/A * This code is distributed in the hope that it will be useful, but WITHOUT 0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 0N/A * version 2 for more details (a copy is included in the LICENSE file that 0N/A * accompanied this code). 0N/A * You should have received a copy of the GNU General Public License version 0N/A * 2 along with this work; if not, write to the Free Software Foundation, 0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2362N/A * or visit www.oracle.com if you need additional information or have any 0N/A * @summary Test that the counter monitor, when running in difference mode, 0N/A * emits a notification every time the threshold is exceeded. 0N/A * @author Luis-Miguel Alventosa 0N/A * @run clean CounterMonitorTest 0N/A * @run build CounterMonitorTest 0N/A * @run main CounterMonitorTest 0N/A // difference mode flag 0N/A // granularity period 0N/A private int[]
values =
new int[] {
4,
6,
9,
11};
0N/A // time to wait for notification (in seconds) 0N/A // flag to notify that a message has been received 0N/A // Notification handler 0N/A echo(
"\tInside handleNotification...");
0N/A " has reached or exceeded the threshold");
0N/A synchronized (
this) {
0N/A echo(
"\tError in handleNotification!");
0N/A * Update the counter and check for notifications 0N/A // Create a new CounterMonitor MBean and add it to the MBeanServer. 0N/A echo(
">>> CREATE a new CounterMonitor MBean");
0N/A echo(
">>> ADD a listener to the CounterMonitor");
0N/A // MANAGEMENT OF A STANDARD MBEAN 0N/A echo(
">>> CREATE a new StdObservedObject MBean");
0N/A echo(
">>> SET the attributes of the CounterMonitor:");
0N/A echo(
"\tATTRIBUTE \"ObservedAttribute\" = NbObjects");
0N/A echo(
">>> START the CounterMonitor");
0N/A // Set initial value 0N/A // Wait for granularity period (multiplied by 2 for sure) 0N/A // Loop through the values 0N/A echo(
"\tdoWait in Counter Monitor");
0N/A // Check if notification was received 0N/A echo(
"\tOKAY: Notification received");
0N/A echo(
"\tError: notification missed or not emitted");
0N/A * Wait until timeout reached 0N/A synchronized (
this) {
0N/A * Standalone entry point. 0N/A * Run the test and report to stdout.