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