jdk/test/javax/management/remote/mandatory/loading/MissingClassTest.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-2004 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 4915825 4921009 4934965 4977469
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Tests behavior when client or server gets object of unknown class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Eamonn McManus
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 * @run clean MissingClassTest SingleClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
 * @run build MissingClassTest SingleClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * @run main MissingClassTest
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  Tests that clients and servers react correctly when they receive
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
  objects of unknown classes.  This can happen easily due to version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  skew or missing jar files on one end or the other.  The default
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  behaviour of causing a connection to die because of the resultant
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  IOException is not acceptable!  We try sending attributes and invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
  parameters to the server of classes it doesn't know, and we try
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  sending attributes, exceptions and notifications to the client of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  classes it doesn't know.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  We also test objects that are of known class but not serializable.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  The test cases are similar.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    47
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    48
import java.io.ByteArrayOutputStream;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    49
import java.io.IOException;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    50
import java.io.NotSerializableException;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    51
import java.io.ObjectOutputStream;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    52
import java.net.MalformedURLException;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    53
import java.util.HashMap;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    54
import java.util.Map;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    55
import java.util.Random;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    56
import java.util.Set;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    57
import javax.management.Attribute;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    58
import javax.management.MBeanServer;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    59
import javax.management.MBeanServerConnection;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    60
import javax.management.MBeanServerFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    61
import javax.management.Notification;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    62
import javax.management.NotificationBroadcasterSupport;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    63
import javax.management.NotificationFilter;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    64
import javax.management.NotificationListener;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    65
import javax.management.ObjectName;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    66
import javax.management.remote.JMXConnectionNotification;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    67
import javax.management.remote.JMXConnector;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    68
import javax.management.remote.JMXConnectorFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    69
import javax.management.remote.JMXConnectorServer;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    70
import javax.management.remote.JMXConnectorServerFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    71
import javax.management.remote.JMXServiceURL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import javax.management.remote.rmi.RMIConnectorServer;
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
    73
import org.omg.CORBA.MARSHAL;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
public class MissingClassTest {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    private static final int NNOTIFS = 50;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    private static ClassLoader clientLoader, serverLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    private static Object serverUnknown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
    private static Exception clientUnknown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    private static ObjectName on;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
    private static final Object[] NO_OBJECTS = new Object[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    private static final String[] NO_STRINGS = new String[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
    private static final Object unserializableObject = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public static void main(String[] args) throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        System.out.println("Test that the client or server end of a " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                           "connection does not fail if sent an object " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                           "it cannot deserialize");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        on = new ObjectName("test:type=Test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        ClassLoader testLoader = MissingClassTest.class.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        clientLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            new SingleClassLoader("$ServerUnknown$", HashMap.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                                  testLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        serverLoader =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            new SingleClassLoader("$ClientUnknown$", Exception.class,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                                  testLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        serverUnknown =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
            clientLoader.loadClass("$ServerUnknown$").newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
        clientUnknown = (Exception)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            serverLoader.loadClass("$ClientUnknown$").newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        final String[] protos = {"rmi", /*"iiop",*/ "jmxmp"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
        for (int i = 0; i < protos.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
                ok &= test(protos[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
                System.out.println("TEST FAILED WITH EXCEPTION:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            System.out.println("Test passed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            System.out.println("TEST FAILED");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private static boolean test(String proto) throws Exception {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   127
        boolean ok = true;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   128
        for (boolean eventService : new boolean[] {false, true})
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   129
            ok &= test(proto, eventService);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   130
        return ok;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   131
    }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   132
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   133
    private static boolean test(String proto, boolean eventService)
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   134
            throws Exception {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   135
        System.out.println("Testing for proto " + proto + " with" +
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   136
                (eventService ? "" : "out") + " Event Service");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        boolean ok = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        MBeanServer mbs = MBeanServerFactory.newMBeanServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        mbs.createMBean(Test.class.getName(), on);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
        JMXConnectorServer cs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        JMXServiceURL url = new JMXServiceURL(proto, null, 0);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Map serverMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        serverMap.put(JMXConnectorServerFactory.DEFAULT_CLASS_LOADER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
                      serverLoader);
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   148
        serverMap.put(RMIConnectorServer.DELEGATE_TO_EVENT_SERVICE,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   149
                Boolean.toString(eventService));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        // make sure no auto-close at server side
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        serverMap.put("jmx.remote.x.server.connection.timeout", "888888888");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            cs = JMXConnectorServerFactory.newJMXConnectorServer(url,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                                                                 serverMap,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                                                                 mbs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            System.out.println("System does not recognize URL: " + url +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                               "; ignoring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        cs.start();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        JMXServiceURL addr = cs.getAddress();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        Map clientMap = new HashMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        clientMap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                      clientLoader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        System.out.println("Connecting for client-unknown test");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        JMXConnector client = JMXConnectorFactory.connect(addr, clientMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        // add a listener to verify no failed notif
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        CNListener cnListener = new CNListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        client.addConnectionNotificationListener(cnListener, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        MBeanServerConnection mbsc = client.getMBeanServerConnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        System.out.println("Getting attribute with class unknown to client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            Object result = mbsc.getAttribute(on, "ClientUnknown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            System.out.println("TEST FAILS: getAttribute for class " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
                               "unknown to client should fail, returned: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                               result);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            Throwable cause = e.getCause();
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   188
            if (cause instanceof MARSHAL)  // see CR 4935098
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   189
                cause = cause.getCause();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            if (cause instanceof ClassNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                System.out.println("Success: got an IOException wrapping " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
                                   "a ClassNotFoundException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                System.out.println("TEST FAILS: Caught IOException (" + e +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
                                   ") but cause should be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                                   "ClassNotFoundException: " + cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        System.out.println("Doing queryNames to ensure connection alive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        Set names = mbsc.queryNames(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
        System.out.println("queryNames returned " + names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
        System.out.println("Provoke exception of unknown class");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
            mbsc.invoke(on, "throwClientUnknown", NO_OBJECTS, NO_STRINGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            System.out.println("TEST FAILS: did not get exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            Throwable wrapped = e.getCause();
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   212
            if (wrapped instanceof MARSHAL)  // see CR 4935098
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   213
                wrapped = wrapped.getCause();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            if (wrapped instanceof ClassNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                System.out.println("Success: got an IOException wrapping " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
                                   "a ClassNotFoundException: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
                                   wrapped);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                System.out.println("TEST FAILS: Got IOException but cause " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                                   "should be ClassNotFoundException: ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
                if (wrapped == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                    System.out.println("(null)");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                    wrapped.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            System.out.println("TEST FAILS: Got wrong exception: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                               "should be IOException with cause " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                               "ClassNotFoundException:");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            e.printStackTrace(System.out);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
        System.out.println("Doing queryNames to ensure connection alive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        names = mbsc.queryNames(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        System.out.println("queryNames returned " + names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        ok &= notifyTest(client, mbsc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        System.out.println("Doing queryNames to ensure connection alive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        names = mbsc.queryNames(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        System.out.println("queryNames returned " + names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        for (int i = 0; i < 2; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            boolean setAttribute = (i == 0); // else invoke
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            String what = setAttribute ? "setAttribute" : "invoke";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            System.out.println("Trying " + what +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                               " with class unknown to server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                if (setAttribute) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                    mbsc.setAttribute(on, new Attribute("ServerUnknown",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
                                                        serverUnknown));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                    mbsc.invoke(on, "useServerUnknown",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                new Object[] {serverUnknown},
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                                new String[] {"java.lang.Object"});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
                System.out.println("TEST FAILS: " + what + " with " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
                                   "class unknown to server should fail " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
                                   "but did not");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
                ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                Throwable cause = e.getCause();
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   265
                if (cause instanceof MARSHAL)  // see CR 4935098
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   266
                    cause = cause.getCause();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                if (cause instanceof ClassNotFoundException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    System.out.println("Success: got an IOException " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                       "wrapping a ClassNotFoundException");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
                    System.out.println("TEST FAILS: Caught IOException (" + e +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                                       ") but cause should be " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
                                       "ClassNotFoundException: " + cause);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                    e.printStackTrace(System.out); // XXX
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
                    ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        System.out.println("Doing queryNames to ensure connection alive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        names = mbsc.queryNames(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
        System.out.println("queryNames returned " + names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
        System.out.println("Trying to get unserializable attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            mbsc.getAttribute(on, "Unserializable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            System.out.println("TEST FAILS: get unserializable worked " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                               "but should not");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            System.out.println("Success: got an IOException: " + e +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                               " (cause: " + e.getCause() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
        System.out.println("Doing queryNames to ensure connection alive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        names = mbsc.queryNames(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        System.out.println("queryNames returned " + names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        System.out.println("Trying to set unserializable attribute");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            Attribute attr =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
                new Attribute("Unserializable", unserializableObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            mbsc.setAttribute(on, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            System.out.println("TEST FAILS: set unserializable worked " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                               "but should not");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            System.out.println("Success: got an IOException: " + e +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                               " (cause: " + e.getCause() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        System.out.println("Doing queryNames to ensure connection alive");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        names = mbsc.queryNames(null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        System.out.println("queryNames returned " + names);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        System.out.println("Trying to throw unserializable exception");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            mbsc.invoke(on, "throwUnserializable", NO_OBJECTS, NO_STRINGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            System.out.println("TEST FAILS: throw unserializable worked " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                               "but should not");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            ok = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            System.out.println("Success: got an IOException: " + e +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                               " (cause: " + e.getCause() + ")");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        client.removeConnectionNotificationListener(cnListener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        ok = ok && !cnListener.failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
        client.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        cs.stop();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (ok)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            System.out.println("Test passed for protocol " + proto);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        System.out.println();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        return ok;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    private static class TestListener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        TestListener(LostListener ll) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            this.lostListener = ll;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        public void handleNotification(Notification n, Object h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            /* Connectors can handle unserializable notifications in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
               one of two ways.  Either they can arrange for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
               client to get a NotSerializableException from its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
               fetchNotifications call (RMI connector), or they can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
               replace the unserializable notification by a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
               JMXConnectionNotification.NOTIFS_LOST (JMXMP
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
               connector).  The former case is handled by code within
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
               the connector client which will end up sending a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
               NOTIFS_LOST to our LostListener.  The logic here
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
               handles the latter case by converting it into the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
               former.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
            if (n instanceof JMXConnectionNotification
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                && n.getType().equals(JMXConnectionNotification.NOTIFS_LOST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                lostListener.handleNotification(n, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            synchronized (result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                if (!n.getType().equals("interesting")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
                    || !n.getUserData().equals("known")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                    System.out.println("TestListener received strange notif: "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
                                       + notificationString(n));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
                    result.failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
                    result.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
                    result.knownCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                    if (result.knownCount == NNOTIFS)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                        result.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
        private LostListener lostListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    private static class LostListener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        public void handleNotification(Notification n, Object h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
            synchronized (result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
                handle(n, h);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        private void handle(Notification n, Object h) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            if (!(n instanceof JMXConnectionNotification)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                System.out.println("LostListener received strange notif: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
                                   notificationString(n));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                result.failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                result.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            JMXConnectionNotification jn = (JMXConnectionNotification) n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            if (!jn.getType().equals(jn.NOTIFS_LOST)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                System.out.println("Ignoring JMXConnectionNotification: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                   notificationString(jn));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            final String msg = jn.getMessage();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            if ((!msg.startsWith("Dropped ")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                 || !msg.endsWith("classes were missing locally"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                && (!msg.startsWith("Not serializable: "))) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                System.out.println("Surprising NOTIFS_LOST getMessage: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
                                   msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            if (!(jn.getUserData() instanceof Long)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                System.out.println("JMXConnectionNotification userData " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                                   "not a Long: " + jn.getUserData());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                result.failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                int lost = ((Long) jn.getUserData()).intValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                result.lostCount += lost;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                if (result.lostCount == NNOTIFS*2)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                    result.notifyAll();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
    private static class TestFilter implements NotificationFilter {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        public boolean isNotificationEnabled(Notification n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
            return (n.getType().equals("interesting"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
    private static class Result {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
        int knownCount, lostCount;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
        boolean failed;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    private static Result result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
    /* Send a bunch of notifications to exercise the logic to recover
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
       from unknown notification classes.  We have four kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
       notifications: "known" ones are of a class known to the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
       and which match its filters; "unknown" ones are of a class that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
       match the client's filters but that the client can't load;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
       "tricky" ones are unserializable; and "boring" notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
       are of a class that the client knows but that doesn't match its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
       filters.  We emit NNOTIFS notifications of each kind.  We do a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
       random shuffle on these 4*NNOTIFS notifications so it is likely
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
       that we will cover the various different cases in the logic.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
       Specifically, what we are testing here is the logic that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
       recovers from a fetchNotifications request that gets a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
       ClassNotFoundException.  Because the request can contain
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
       several notifications, the client doesn't know which of them
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
       generated the exception.  So it redoes a request that asks for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
       just one notification.  We need to be sure that this works when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
       that one notification is of an unknown class and when it is of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
       a known class, and in both cases when there are filtered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
       notifications that are skipped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
       We are also testing the behaviour in the server when it tries
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
       to include an unserializable notification in the response to a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
       fetchNotifications, and in the client when that happens.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
       If the test succeeds, the listener should receive the NNOTIFS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
       "known" notifications, and the connection listener should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
       receive an indication of NNOTIFS lost notifications
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
       representing the "unknown" notifications.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
       We depend on some implementation-specific features here:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
       1. The buffer size is sufficient to contain the 4*NNOTIFS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
       notifications which are all sent at once, before the client
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
       gets a chance to start receiving them.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
       2. When one or more notifications are dropped because they are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
       of unknown classes, the NOTIFS_LOST notification contains a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
       userData that is a Long with a count of the number dropped.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
       3. If a notification is not serializable on the server, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
       client gets told about it somehow, rather than having it just
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
       dropped on the floor.  The somehow might be through an RMI
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
       exception, or it might be by the server replacing the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
       unserializable notif by a JMXConnectionNotification.NOTIFS_LOST.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    private static boolean notifyTest(JMXConnector client,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                                      MBeanServerConnection mbsc)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
        System.out.println("Send notifications including unknown ones");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        result = new Result();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        LostListener ll = new LostListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        client.addConnectionNotificationListener(ll, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
        TestListener nl = new TestListener(ll);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        mbsc.addNotificationListener(on, nl, new TestFilter(), null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        mbsc.invoke(on, "sendNotifs", NO_OBJECTS, NO_STRINGS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        // wait for the listeners to receive all their notifs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        // or to fail
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        long deadline = System.currentTimeMillis() + 60000;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        long remain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        while ((remain = deadline - System.currentTimeMillis()) >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            synchronized (result) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                if (result.failed
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   500
                    || (result.knownCount >= NNOTIFS
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   501
                        && result.lostCount >= NNOTIFS*2))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                result.wait(remain);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   506
        Thread.sleep(2);  // allow any spurious extra notifs to arrive
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        if (result.failed) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
            System.out.println("TEST FAILS: Notification strangeness");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        } else if (result.knownCount == NNOTIFS
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                   && result.lostCount == NNOTIFS*2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            System.out.println("Success: received known notifications and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                               "got NOTIFS_LOST for unknown and " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                               "unserializable ones");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
            return true;
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   516
        } else if (result.knownCount >= NNOTIFS
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   517
                || result.lostCount >= NNOTIFS*2) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   518
            System.out.println("TEST FAILS: Received too many notifs: " +
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   519
                    "known=" + result.knownCount + "; lost=" + result.lostCount);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 2
diff changeset
   520
            return false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
            System.out.println("TEST FAILS: Timed out without receiving " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                               "all notifs: known=" + result.knownCount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                               "; lost=" + result.lostCount);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    public static interface TestMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        public Object getClientUnknown() throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
        public void throwClientUnknown() throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        public void setServerUnknown(Object o) throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
        public void useServerUnknown(Object o) throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        public Object getUnserializable() throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        public void setUnserializable(Object un) throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        public void throwUnserializable() throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        public void sendNotifs() throws Exception;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    public static class Test extends NotificationBroadcasterSupport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            implements TestMBean {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        public Object getClientUnknown() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            return clientUnknown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
        public void throwClientUnknown() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
            throw clientUnknown;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        public void setServerUnknown(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
            throw new IllegalArgumentException("setServerUnknown succeeded "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
                                               "but should not have");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        public void useServerUnknown(Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
            throw new IllegalArgumentException("useServerUnknown succeeded "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
                                               "but should not have");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
        public Object getUnserializable() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
            return unserializableObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
        public void setUnserializable(Object un) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
            throw new IllegalArgumentException("setUnserializable succeeded " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
                                               "but should not have");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        public void throwUnserializable() throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
            throw new Exception() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
                private Object unserializable = unserializableObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
            };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        public void sendNotifs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            /* We actually send the same four notification objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
               NNOTIFS times each.  This doesn't particularly matter,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
               but note that the MBeanServer will replace "this" by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
               the sender's ObjectName the first time.  Since that's
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
               always the same, no problem.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
            Notification known =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                new Notification("interesting", this, 1L, 1L, "known");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
            known.setUserData("known");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
            Notification unknown =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                new Notification("interesting", this, 1L, 1L, "unknown");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
            unknown.setUserData(clientUnknown);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
            Notification boring =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                new Notification("boring", this, 1L, 1L, "boring");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
            Notification tricky =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                new Notification("interesting", this, 1L, 1L, "tricky");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
            tricky.setUserData(unserializableObject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
            // check that the tricky notif is indeed unserializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                new ObjectOutputStream(new ByteArrayOutputStream())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                    .writeObject(tricky);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                System.out.println("TEST INCORRECT: tricky notif is " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                                   "serializable");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
            } catch (NotSerializableException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                // OK: tricky notif is not serializable
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                System.out.println("TEST INCORRECT: tricky notif " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                                   "serialization check failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
            /* Now shuffle an imaginary deck of cards where K, U, T, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
               B (known, unknown, tricky, boring) each appear NNOTIFS times.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
               We explicitly seed the random number generator so we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
               can reproduce rare test failures if necessary.  We only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
               use a StringBuffer so we can print the shuffled deck --
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
               otherwise we could just emit the notifications as the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
               cards are placed.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
            long seed = System.currentTimeMillis();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
            System.out.println("Random number seed is " + seed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
            Random r = new Random(seed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            int knownCount = NNOTIFS;   // remaining K cards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
            int unknownCount = NNOTIFS; // remaining U cards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
            int trickyCount = NNOTIFS;  // remaining T cards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
            int boringCount = NNOTIFS;  // remaining B cards
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
            StringBuffer notifList = new StringBuffer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
            for (int i = NNOTIFS * 4; i > 0; i--) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
                int rand = r.nextInt(i);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
                // use rand to pick a card from the remaining ones
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
                if ((rand -= knownCount) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
                    notifList.append('k');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
                    knownCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
                } else if ((rand -= unknownCount) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
                    notifList.append('u');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
                    unknownCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
                } else if ((rand -= trickyCount) < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
                    notifList.append('t');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
                    trickyCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   637
                    notifList.append('b');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                    boringCount--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   640
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   641
            if (knownCount != 0 || unknownCount != 0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   642
                || trickyCount != 0 || boringCount != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                System.out.println("TEST INCORRECT: Shuffle failed: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                                   "known=" + knownCount +" unknown=" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                                   unknownCount + " tricky=" + trickyCount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
                                   " boring=" + boringCount +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   647
                                   " deal=" + notifList);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
                System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            String notifs = notifList.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
            System.out.println("Shuffle: " + notifs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            for (int i = 0; i < NNOTIFS * 4; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   653
                Notification n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
                switch (notifs.charAt(i)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                case 'k': n = known; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
                case 'u': n = unknown; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                case 't': n = tricky; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
                case 'b': n = boring; break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
                    System.out.println("TEST INCORRECT: Bad shuffle char: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                                       notifs.charAt(i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
                    System.exit(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
                    throw new Error();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
                sendNotification(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   666
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   667
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   668
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
90ce3da70b43 Initial load
duke
parents:
diff changeset
   670
    private static String notificationString(Notification n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   671
        return n.getClass().getName() + "/" + n.getType() + " \"" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
            n.getMessage() + "\" <" + n.getUserData() + ">";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   674
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
    //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
    private static class CNListener implements NotificationListener {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
        public void handleNotification(Notification n, Object o) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   678
            if (n instanceof JMXConnectionNotification) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   679
                JMXConnectionNotification jn = (JMXConnectionNotification)n;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   680
                if (JMXConnectionNotification.FAILED.equals(jn.getType())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
                    failed = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   685
90ce3da70b43 Initial load
duke
parents:
diff changeset
   686
        public boolean failed = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   687
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
}