jdk/test/javax/management/remote/mandatory/connectorServer/StandardForwardersTest.java
author emcmanus
Fri, 07 Nov 2008 11:48:07 +0100
changeset 1570 4165709c91e3
parent 1004 5ba8217eb504
permissions -rw-r--r--
5072267: A way to communicate client context such as locale to the JMX server Summary: Support for client contexts and also for localization of descriptions Reviewed-by: dfuchs
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     1
/*
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     4
 *
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     8
 *
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    13
 * accompanied this code).
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    14
 *
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    18
 *
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    21
 * have any questions.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    22
 */
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    23
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    24
import java.lang.management.ManagementFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    25
import java.util.ArrayList;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    26
import java.util.HashMap;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    27
import java.util.List;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    28
import java.util.Map;
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    29
import javax.management.ClientContext;
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    30
import javax.management.MBeanServer;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    31
import javax.management.event.EventClientDelegate;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    32
import javax.management.remote.JMXConnectorServer;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    33
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    34
/*
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    35
 * @test
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    36
 * @bug 6663757
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    37
 * @summary Tests standard MBeanServerForwarders introduced by connector server
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    38
 * options.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    39
 * @author Eamonn McManus
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    40
 */
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    41
import javax.management.remote.JMXConnectorServerFactory;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    42
import javax.management.remote.JMXServiceURL;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    43
import javax.management.remote.MBeanServerForwarder;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    44
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    45
public class StandardForwardersTest {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    46
    private static String failure;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    47
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    48
    private static class Forwarder {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    49
        private final String attribute;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    50
        private final boolean defaultEnabled;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    51
        private final Class<?> expectedClass;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    52
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    53
        public Forwarder(String attribute, boolean defaultEnabled,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    54
                         Class<?> expectedClass) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    55
            this.attribute = attribute;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    56
            this.defaultEnabled = defaultEnabled;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    57
            this.expectedClass = expectedClass;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    58
        }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    59
    }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    60
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    61
    private static enum Status {DISABLED, ENABLED, DEFAULT}
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    62
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    63
    public static void main(String[] args) throws Exception {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    64
        MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    65
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    66
        MBeanServerForwarder ctxFwd = ClientContext.newContextForwarder(mbs, null);
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    67
        Forwarder ctx = new Forwarder(
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    68
                JMXConnectorServer.CONTEXT_FORWARDER, true, ctxFwd.getClass());
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    69
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    70
        MBeanServerForwarder locFwd =
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    71
                ClientContext.newLocalizeMBeanInfoForwarder(mbs);
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    72
        Forwarder loc = new Forwarder(
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    73
                JMXConnectorServer.LOCALIZE_MBEAN_INFO_FORWARDER, false,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    74
                locFwd.getClass());
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    75
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    76
        MBeanServerForwarder ecdFwd =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    77
                EventClientDelegate.newForwarder(mbs, null);
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    78
        Forwarder ecd = new Forwarder(
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    79
                JMXConnectorServer.EVENT_CLIENT_DELEGATE_FORWARDER, true,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    80
                ecdFwd.getClass());
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    81
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
    82
        Forwarder[] forwarders = {ctx, loc, ecd};
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    83
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    84
        // Now go through every combination of forwarders.  Each forwarder
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    85
        // may be explicitly enabled, explicitly disabled, or left to its
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    86
        // default value.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    87
        int nStatus = Status.values().length;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    88
        int limit = (int) Math.pow(nStatus, forwarders.length);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    89
        for (int i = 0; i < limit; i++) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    90
            Status[] status = new Status[forwarders.length];
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    91
            int ii = i;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    92
            for (int j = 0; j < status.length; j++) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    93
                status[j] = Status.values()[ii % nStatus];
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    94
                ii /= nStatus;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    95
            }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    96
            Map<String, String> env = new HashMap<String, String>();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    97
            String test = "";
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    98
            for (int j = 0; j < status.length; j++) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
    99
                if (!test.equals(""))
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   100
                    test += "; ";
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   101
                test += forwarders[j].attribute;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   102
                switch (status[j]) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   103
                case DISABLED:
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   104
                    test += "=false";
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   105
                    env.put(forwarders[j].attribute, "false");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   106
                    break;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   107
                case ENABLED:
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   108
                    test += "=true";
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   109
                    env.put(forwarders[j].attribute, "true");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   110
                    break;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   111
                case DEFAULT:
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   112
                    test += "=default(" + forwarders[j].defaultEnabled + ")";
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   113
                    break;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   114
                }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   115
            }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   116
            boolean consistent = isConsistent(env);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   117
            test += "; (" + (consistent ? "" : "in") + "consistent)";
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   118
            System.out.println(test);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   119
            JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   120
            try {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   121
                JMXConnectorServer cs =
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   122
                    JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   123
                if (!consistent) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   124
                    fail("Inconsistent attributes should have been rejected " +
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   125
                            "but were not");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   126
                }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   127
                checkForwarders(cs, forwarders, status);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   128
            } catch (IllegalArgumentException e) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   129
                if (consistent) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   130
                    fail("Consistent attributes provoked IllegalArgumentException");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   131
                    e.printStackTrace(System.out);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   132
                }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   133
            }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   134
        }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   135
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   136
        if (failure == null)
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   137
            System.out.println("TEST PASSED");
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   138
        else
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   139
            throw new Exception(failure);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   140
    }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   141
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   142
    // Check that the classes of the forwarders in the system chain correspond
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   143
    // to what we expect given the options we have passed.  This check is a bit
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   144
    // superficial in the sense that a forwarder might be for example a
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   145
    // SingleMBeanForwarderHandler but that doesn't prove that it is the
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   146
    // right Single MBean.  Nevertheless the test should expose any severe
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   147
    // wrongness.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   148
    //
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   149
    // The check here makes some assumptions that could become untrue in the
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   150
    // future. First, it assumes that the forwarders that are added have
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   151
    // exactly the classes that are in the Forwarder[] array. So for example
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   152
    // the forwarder for CONTEXT_FORWARDER must be of the same class as an
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   153
    // explicit call to ClientContext.newContextForwarder. The spec doesn't
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   154
    // require that - it only requires that the forwarder have the same
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   155
    // behaviour. The second assumption is that the connector server doesn't
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   156
    // add any forwarders of its own into the system chain, and again the spec
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   157
    // doesn't disallow that.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   158
    private static void checkForwarders(
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   159
            JMXConnectorServer cs, Forwarder[] forwarders, Status[] status) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   160
        List<Class<?>> expectedClasses = new ArrayList<Class<?>>();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   161
        for (int i = 0; i < forwarders.length; i++) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   162
            if (status[i] == Status.ENABLED ||
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   163
                    (status[i] == Status.DEFAULT && forwarders[i].defaultEnabled))
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   164
                expectedClasses.add(forwarders[i].expectedClass);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   165
        }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   166
        MBeanServer stop = cs.getMBeanServer();
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   167
        List<Class<?>> foundClasses = new ArrayList<Class<?>>();
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   168
        for (MBeanServer mbs = cs.getSystemMBeanServerForwarder().getMBeanServer();
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   169
             mbs != stop;
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   170
             mbs = ((MBeanServerForwarder) mbs).getMBeanServer()) {
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   171
            foundClasses.add(mbs.getClass());
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   172
        }
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   173
        if (!expectedClasses.equals(foundClasses)) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   174
            fail("Incorrect forwarder chain: expected " + expectedClasses +
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   175
                    "; found " + foundClasses);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   176
        }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   177
    }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   178
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   179
    // env is consistent if either (a) localizer is not enabled or (b)
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   180
    // localizer is enabled and context is enabled.
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   181
    private static boolean isConsistent(Map<String, String> env) {
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   182
        String ctxS = env.get(JMXConnectorServer.CONTEXT_FORWARDER);
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   183
        boolean ctx = (ctxS == null) ? true : Boolean.parseBoolean(ctxS);
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   184
        String locS = env.get(JMXConnectorServer.LOCALIZE_MBEAN_INFO_FORWARDER);
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   185
        boolean loc = (locS == null) ? false : Boolean.parseBoolean(locS);
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1004
diff changeset
   186
        return !loc || ctx;
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   187
    }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   188
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   189
    private static void fail(String why) {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   190
        System.out.println("FAILED: " + why);
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   191
        failure = why;
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   192
    }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents:
diff changeset
   193
}