jdk/test/javax/management/remote/mandatory/notif/UnexpectedNotifTest.java
author sjiang
Thu, 31 Jul 2008 15:31:13 +0200
changeset 1004 5ba8217eb504
parent 2 90ce3da70b43
child 1247 b4c26443dee5
permissions -rw-r--r--
5108776: Add reliable event handling to the JMX API 6218920: API bug - impossible to delete last MBeanServerForwarder on a connector Reviewed-by: emcmanus
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2003 Sun Microsystems, Inc.  All Rights Reserved.
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
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
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
        }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    66
        for (String proto : protos) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    67
            test(proto, false);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    68
            test(proto, true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        }
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    70
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    72
    private static void test(String proto, boolean eventService)
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    73
            throws Exception {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    74
        System.out.println("Unexpected notifications test for protocol " +
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    75
                           proto + " with" +
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    76
                           (eventService ? "" : "out") + " event service");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    77
        MBeanServer mbs = null;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    78
        try {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    79
            // Create a MBeanServer
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
            mbs = MBeanServerFactory.createMBeanServer();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    82
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    83
            // Create a NotificationEmitter MBean
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    84
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    85
            mbean = new ObjectName ("Default:name=NotificationEmitter");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    86
            mbs.registerMBean(new NotificationEmitter(), mbean);
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
            // Create a connector server
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    89
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    90
            url = new JMXServiceURL("service:jmx:" + proto + "://");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    91
            Map<String, String> env = Collections.singletonMap(
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    92
                    RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    93
                    Boolean.toString(eventService));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    95
            server = JMXConnectorServerFactory.newJMXConnectorServer(url,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    96
                                                                     env,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    97
                                                                     mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    99
            mbs.registerMBean(
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   100
                        server,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   101
                        new ObjectName("Default:name=ConnectorServer"));
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
            server.start();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   104
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   105
            url = server.getAddress();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   107
            for (int j = 0; j < 2; j++) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   108
                test();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            }
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   110
        } finally {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   111
            // Stop server
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   112
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   113
            server.stop();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   114
            // Release the MBeanServer
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   115
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   116
            MBeanServerFactory.releaseMBeanServer(mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    private static void test() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        // Create client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        JMXConnector connector = JMXConnectorFactory.connect(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        MBeanServerConnection client = connector.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        // Add listener at the client side
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        client.addNotificationListener(mbean, listener, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        // Cleanup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        receivedNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        // Ask to send notifs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        Object[] params = new Object[] {new Integer(nb)};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        String[] signatures = new String[] {"java.lang.Integer"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        client.invoke(mbean, "sendNotifications", params, signatures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        // Waiting...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            for (int i = 0; i < 10; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                if (receivedNotifs < nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                    lock.wait(1000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // Waiting again to ensure no more notifs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        Thread.sleep(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            if (receivedNotifs != nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                throw new Exception("The client expected to receive " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                                    nb + " notifs, but got " + receivedNotifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        // Remove listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        client.removeNotificationListener(mbean, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        connector.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
    //--------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    // private classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
    //--------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
    private static class Listener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        public void handleNotification(Notification notif, Object handback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            System.out.println("Received: " + notif + " (" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                               notif.getSequenceNumber() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                if(++receivedNotifs == nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                    lock.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
                } else if (receivedNotifs > nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
                    System.out.println("The client expected to receive " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
                                       nb + " notifs, but got at least " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                                       receivedNotifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                    System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    public static class NotificationEmitter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        extends NotificationBroadcasterSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        implements NotificationEmitterMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
         * Returns a NotificationInfo object containing the name of the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
         * class of the notification and the notification types sent by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
         * notification broadcaster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        public MBeanNotificationInfo[] getNotificationInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
            MBeanNotificationInfo[] ntfInfoArray = new MBeanNotificationInfo[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            String[] ntfTypes = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            ntfTypes[0] = myType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            ntfInfoArray[0] = new MBeanNotificationInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                              ntfTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                              "javax.management.Notification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                              "Notifications sent by the NotificationEmitter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            return ntfInfoArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
         * Send a Notification object with the specified times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
         * The sequence number will be from zero to times-1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         * @param nb The number of notifications to send
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        public void sendNotifications(Integer nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            System.out.println("NotificationEmitter: asked to send " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                               "notifications: " + nb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            Notification notif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            for (int i = 1; i <= nb.intValue(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                notif = new Notification(myType, this, ++seqno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
                sendNotification(notif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            }
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 String myType = "notification.my_notification";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    public interface NotificationEmitterMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        public void sendNotifications(Integer nb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private static JMXConnectorServer server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private static JMXServiceURL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private static ObjectName mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    private static NotificationListener listener = new Listener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    private static int nb = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
    private static int receivedNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    private static int[] lock = new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
    private static volatile long seqno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
}