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