/*
* 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 7654321
* @summary Tests whether a listener receives notifs emitted before the
* listener is registered.
* @author Shanliang JIANG
* @run clean UnexpectedNotifTest
* @run build UnexpectedNotifTest
* @run main UnexpectedNotifTest
*/
//
public class UnexpectedNotifTest {
try {
} catch (ClassNotFoundException e) {
// OK: JMXMP not present so don't test it.
}
}
proto);
try {
// Create a MBeanServer
//
// Create a NotificationEmitter MBean
//
// Create a connector server
//
null,
mbs);
new ObjectName("Default:name=ConnectorServer"));
for (int j = 0; j < 2; j++) {
test();
}
} finally {
// Stop server
//
// Release the MBeanServer
//
}
}
// Create client
//
// Add listener at the client side
//
// Cleanup
//
receivedNotifs = 0;
// Ask to send notifs
//
// Waiting...
//
synchronized (lock) {
for (int i = 0; i < 10; i++) {
if (receivedNotifs < nb) {
}
}
}
// Waiting again to ensure no more notifs
//
synchronized (lock) {
if (receivedNotifs != nb) {
throw new Exception("The client expected to receive " +
}
}
// Remove listener
//
}
//--------------------------
// private classes
//--------------------------
synchronized(lock) {
if(++receivedNotifs == nb) {
} else if (receivedNotifs > nb) {
nb + " notifs, but got at least " +
}
}
}
}
public static class NotificationEmitter
extends NotificationBroadcasterSupport
implements NotificationEmitterMBean {
/**
* Returns a NotificationInfo object containing the name of the Java
* class of the notification and the notification types sent by this
* notification broadcaster.
*/
"javax.management.Notification",
"Notifications sent by the NotificationEmitter");
return ntfInfoArray;
}
/**
* Send a Notification object with the specified times.
* The sequence number will be from zero to times-1.
*
* @param nb The number of notifications to send
*/
"notifications: " + nb);
}
}
}
public interface NotificationEmitterMBean {
}
private static volatile long seqno;
}