jdk/test/javax/management/remote/mandatory/notif/UnexpectedNotifTest.java
author ohair
Tue, 25 May 2010 15:58:33 -0700
changeset 5506 202f599c92aa
parent 4156 acaa49a2768a
child 30376 2ccf2cf7ea48
permissions -rw-r--r--
6943119: Rebrand source copyright notices Reviewed-by: darcy, weijun
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     2
 * Copyright (c) 2003, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    21
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 7654321
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Tests whether a listener receives notifs emitted before the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * listener is registered.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @author Shanliang JIANG
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run clean UnexpectedNotifTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run build UnexpectedNotifTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run main UnexpectedNotifTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    35
import java.util.ArrayList;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    36
import java.util.Collections;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    37
import java.util.List;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    38
import java.util.Map;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    39
import javax.management.MBeanNotificationInfo;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    40
import javax.management.MBeanServer;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    41
import javax.management.MBeanServerConnection;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    42
import javax.management.MBeanServerFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    43
import javax.management.Notification;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    44
import javax.management.NotificationBroadcasterSupport;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    45
import javax.management.NotificationListener;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    46
import javax.management.ObjectName;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    47
import javax.management.remote.JMXConnector;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    48
import javax.management.remote.JMXConnectorFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    49
import javax.management.remote.JMXConnectorServer;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    50
import javax.management.remote.JMXConnectorServerFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    51
import javax.management.remote.JMXServiceURL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
//
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    53
import javax.management.remote.rmi.RMIConnectorServer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
public class UnexpectedNotifTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    public static void main(String[] args) throws Exception {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    58
        List<String> protos = new ArrayList<String>();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    59
        protos.add("rmi");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            Class.forName("javax.management.remote.jmxmp.JMXMPConnectorServer");
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    62
            protos.add("jmxmp");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        } catch (ClassNotFoundException e) {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    64
            // OK: JMXMP not present so don't test it.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    65
        }
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    66
        for (String proto : protos)
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    67
            test(proto);
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    68
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    70
    private static void test(String proto) throws Exception {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    71
        System.out.println("Unexpected notifications test for protocol " +
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    72
                           proto);
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    73
        MBeanServer mbs = null;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    74
        try {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    75
            // Create a MBeanServer
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    76
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    77
            mbs = MBeanServerFactory.createMBeanServer();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    78
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    79
            // Create a NotificationEmitter MBean
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    80
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    81
            mbean = new ObjectName ("Default:name=NotificationEmitter");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    82
            mbs.registerMBean(new NotificationEmitter(), mbean);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    84
            // Create a connector server
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    85
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    86
            url = new JMXServiceURL("service:jmx:" + proto + "://");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    88
            server = JMXConnectorServerFactory.newJMXConnectorServer(url,
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    89
                                                                     null,
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    90
                                                                     mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    92
            mbs.registerMBean(
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    93
                        server,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    94
                        new ObjectName("Default:name=ConnectorServer"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    96
            server.start();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    97
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    98
            url = server.getAddress();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   100
            for (int j = 0; j < 2; j++) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   101
                test();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            }
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   103
        } finally {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   104
            // Stop server
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   105
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   106
            server.stop();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   107
            // Release the MBeanServer
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   108
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   109
            MBeanServerFactory.releaseMBeanServer(mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    private static void test() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        // Create client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        JMXConnector connector = JMXConnectorFactory.connect(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        MBeanServerConnection client = connector.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        // Add listener at the client side
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        client.addNotificationListener(mbean, listener, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        // Cleanup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        receivedNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        // Ask to send notifs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        Object[] params = new Object[] {new Integer(nb)};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        String[] signatures = new String[] {"java.lang.Integer"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        client.invoke(mbean, "sendNotifications", params, signatures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // Waiting...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            for (int i = 0; i < 10; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
                if (receivedNotifs < nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                    lock.wait(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        // Waiting again to ensure no more notifs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        Thread.sleep(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            if (receivedNotifs != nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                throw new Exception("The client expected to receive " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                                    nb + " notifs, but got " + receivedNotifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        // Remove listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        client.removeNotificationListener(mbean, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        connector.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    //--------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    // private classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    //--------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
    private static class Listener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        public void handleNotification(Notification notif, Object handback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            System.out.println("Received: " + notif + " (" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                               notif.getSequenceNumber() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                if(++receivedNotifs == nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                    lock.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                } else if (receivedNotifs > nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                    System.out.println("The client expected to receive " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                                       nb + " notifs, but got at least " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                       receivedNotifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                    System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    public static class NotificationEmitter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        extends NotificationBroadcasterSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        implements NotificationEmitterMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
         * Returns a NotificationInfo object containing the name of the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * class of the notification and the notification types sent by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * notification broadcaster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        public MBeanNotificationInfo[] getNotificationInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            MBeanNotificationInfo[] ntfInfoArray = new MBeanNotificationInfo[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            String[] ntfTypes = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            ntfTypes[0] = myType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            ntfInfoArray[0] = new MBeanNotificationInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
                              ntfTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                              "javax.management.Notification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                              "Notifications sent by the NotificationEmitter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            return ntfInfoArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
         * Send a Notification object with the specified times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         * The sequence number will be from zero to times-1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         * @param nb The number of notifications to send
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        public void sendNotifications(Integer nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            System.out.println("NotificationEmitter: asked to send " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                               "notifications: " + nb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            Notification notif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            for (int i = 1; i <= nb.intValue(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
                notif = new Notification(myType, this, ++seqno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                sendNotification(notif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        private String myType = "notification.my_notification";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public interface NotificationEmitterMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        public void sendNotifications(Integer nb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
    private static JMXConnectorServer server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private static JMXServiceURL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private static ObjectName mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private static NotificationListener listener = new Listener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private static int nb = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private static int receivedNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private static int[] lock = new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private static volatile long seqno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
}