jdk/test/javax/management/remote/mandatory/notif/UnexpectedNotifTest.java
author ykantser
Thu, 07 May 2015 09:11:49 +0200
changeset 30376 2ccf2cf7ea48
parent 5506 202f599c92aa
child 43503 bc7f8619ab70
permissions -rw-r--r--
8078896: Add @modules as needed to the jdk_svc tests Reviewed-by: alanb, mchung
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
     2
 * Copyright (c) 2003, 2015, 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
30376
2ccf2cf7ea48 8078896: Add @modules as needed to the jdk_svc tests
ykantser
parents: 5506
diff changeset
    30
 * @modules java.management
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run clean UnexpectedNotifTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * @run build UnexpectedNotifTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * @run main UnexpectedNotifTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    36
import java.util.ArrayList;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    37
import java.util.Collections;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    38
import java.util.List;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    39
import java.util.Map;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    40
import javax.management.MBeanNotificationInfo;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    41
import javax.management.MBeanServer;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    42
import javax.management.MBeanServerConnection;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    43
import javax.management.MBeanServerFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    44
import javax.management.Notification;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    45
import javax.management.NotificationBroadcasterSupport;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    46
import javax.management.NotificationListener;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    47
import javax.management.ObjectName;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    48
import javax.management.remote.JMXConnector;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    49
import javax.management.remote.JMXConnectorFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    50
import javax.management.remote.JMXConnectorServer;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    51
import javax.management.remote.JMXConnectorServerFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    52
import javax.management.remote.JMXServiceURL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
//
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    54
import javax.management.remote.rmi.RMIConnectorServer;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
public class UnexpectedNotifTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
    public static void main(String[] args) throws Exception {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    59
        List<String> protos = new ArrayList<String>();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    60
        protos.add("rmi");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
            Class.forName("javax.management.remote.jmxmp.JMXMPConnectorServer");
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    63
            protos.add("jmxmp");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        } catch (ClassNotFoundException e) {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    65
            // OK: JMXMP not present so don't test it.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    66
        }
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    67
        for (String proto : protos)
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    68
            test(proto);
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    69
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    71
    private static void test(String proto) throws Exception {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    72
        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
    73
                           proto);
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    74
        MBeanServer mbs = null;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    75
        try {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    76
            // Create a MBeanServer
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    77
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    78
            mbs = MBeanServerFactory.createMBeanServer();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    79
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    80
            // Create a NotificationEmitter MBean
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    81
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    82
            mbean = new ObjectName ("Default:name=NotificationEmitter");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    83
            mbs.registerMBean(new NotificationEmitter(), mbean);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    85
            // Create a connector server
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    86
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    87
            url = new JMXServiceURL("service:jmx:" + proto + "://");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    89
            server = JMXConnectorServerFactory.newJMXConnectorServer(url,
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1247
diff changeset
    90
                                                                     null,
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    91
                                                                     mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    93
            mbs.registerMBean(
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    94
                        server,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    95
                        new ObjectName("Default:name=ConnectorServer"));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    97
            server.start();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    98
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    99
            url = server.getAddress();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   101
            for (int j = 0; j < 2; j++) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   102
                test();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   104
        } finally {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   105
            // Stop server
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   106
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   107
            server.stop();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   108
            // Release the MBeanServer
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   109
            //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   110
            MBeanServerFactory.releaseMBeanServer(mbs);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private static void test() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        // Create client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        JMXConnector connector = JMXConnectorFactory.connect(url);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        MBeanServerConnection client = connector.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        // Add listener at the client side
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
        client.addNotificationListener(mbean, listener, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
        // Cleanup
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
        receivedNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        // Ask to send notifs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        Object[] params = new Object[] {new Integer(nb)};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        String[] signatures = new String[] {"java.lang.Integer"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
        client.invoke(mbean, "sendNotifications", params, signatures);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        // Waiting...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            for (int i = 0; i < 10; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
                if (receivedNotifs < nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
                    lock.wait(1000);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        // Waiting again to ensure no more notifs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        Thread.sleep(3000);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        synchronized (lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            if (receivedNotifs != nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                throw new Exception("The client expected to receive " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                                    nb + " notifs, but got " + receivedNotifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        // Remove listener
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        client.removeNotificationListener(mbean, listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        connector.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    //--------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
    // private classes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    //--------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    private static class Listener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        public void handleNotification(Notification notif, Object handback) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            System.out.println("Received: " + notif + " (" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                               notif.getSequenceNumber() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            synchronized(lock) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
                if(++receivedNotifs == nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                    lock.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                } else if (receivedNotifs > nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
                    System.out.println("The client expected to receive " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
                                       nb + " notifs, but got at least " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                                       receivedNotifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
                    System.exit(1);
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    public static class NotificationEmitter
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        extends NotificationBroadcasterSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        implements NotificationEmitterMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
         * Returns a NotificationInfo object containing the name of the Java
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
         * class of the notification and the notification types sent by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
         * notification broadcaster.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        public MBeanNotificationInfo[] getNotificationInfo() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            MBeanNotificationInfo[] ntfInfoArray = new MBeanNotificationInfo[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            String[] ntfTypes = new String[1];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            ntfTypes[0] = myType;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            ntfInfoArray[0] = new MBeanNotificationInfo(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                              ntfTypes,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                              "javax.management.Notification",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                              "Notifications sent by the NotificationEmitter");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
            return ntfInfoArray;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
         * Send a Notification object with the specified times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
         * The sequence number will be from zero to times-1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
         * @param nb The number of notifications to send
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
        public void sendNotifications(Integer nb) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            System.out.println("NotificationEmitter: asked to send " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                               "notifications: " + nb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            Notification notif;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            for (int i = 1; i <= nb.intValue(); i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                notif = new Notification(myType, this, ++seqno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                sendNotification(notif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        private String myType = "notification.my_notification";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    public interface NotificationEmitterMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        public void sendNotifications(Integer nb);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private static JMXConnectorServer server;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    private static JMXServiceURL url;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
    private static ObjectName mbean;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private static NotificationListener listener = new Listener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private static int nb = 10;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private static int receivedNotifs = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    private static int[] lock = new int[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    private static volatile long seqno;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
}