jdk/test/javax/management/namespace/JMXNamespaceViewTest.java
author dfuchs
Wed, 10 Sep 2008 16:27:13 +0200
changeset 1227 4546977d0d66
parent 1156 bbc2d15aaf7a
child 1570 4165709c91e3
permissions -rw-r--r--
6746754: jmx namespace: test for leading separator missing 6669137: RFE: InstanceNotFoundException should have a constructor that takes an ObjectName 6746796: jmx namespaces: Several tests are missing an @bug or @run keyword Summary: Note on 6669137: first implementation of 6669137 was actually pushed with 5072476 - here we only have a small update and a test case. Also re-fixes 6737133: Compilation failure of test/javax/management/eventService/LeaseManagerDeadlockTest.java which had failed. Reviewed-by: emcmanus, yjoan
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     1
/*
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     2
 * Copyright 2008 Sun Microsystems, Inc.  All Rights Reserved.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     4
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     7
 * published by the Free Software Foundation.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     8
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    13
 * accompanied this code).
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    14
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    18
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    21
 * have any questions.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    22
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    23
/*
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    24
 *
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    25
 * @test JMXNamespaceViewTest.java
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    26
 * @summary Test the JMXNamespaceView class.
1227
4546977d0d66 6746754: jmx namespace: test for leading separator missing
dfuchs
parents: 1156
diff changeset
    27
 * @bug 5072476
1156
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    28
 * @author Daniel Fuchs
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    29
 * @run clean JMXNamespaceViewTest Wombat WombatMBean
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    30
 * @run build JMXNamespaceViewTest Wombat WombatMBean
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    31
 * @run main JMXNamespaceViewTest
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    32
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    33
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    34
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    35
import java.lang.management.ManagementFactory;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    36
import java.net.ServerSocket;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    37
import java.rmi.registry.LocateRegistry;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    38
import java.util.ArrayList;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    39
import java.util.Arrays;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    40
import java.util.HashMap;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    41
import java.util.HashSet;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    42
import java.util.List;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    43
import java.util.Map;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    44
import java.util.Set;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    45
import javax.management.JMException;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    46
import javax.management.MBeanRegistration;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    47
import javax.management.MBeanServer;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    48
import javax.management.MBeanServerFactory;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    49
import javax.management.ObjectInstance;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    50
import javax.management.ObjectName;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    51
import javax.management.namespace.JMXNamespace;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    52
import javax.management.namespace.JMXNamespaceView;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    53
import javax.management.namespace.JMXNamespaces;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    54
import javax.management.namespace.JMXRemoteNamespace;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    55
import javax.management.remote.JMXConnectorServer;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    56
import javax.management.remote.JMXConnectorServerFactory;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    57
import javax.management.remote.JMXServiceURL;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    58
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    59
/**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    60
 * A simple test to test the JMXNamespaceViewTest...
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    61
 * @author dfuchs
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    62
 */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    63
public class JMXNamespaceViewTest {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    64
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    65
    // TODO: Remove this when contexts are added.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    66
    public static class ClientContext {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    67
        public final static String NAMESPACE = "jmx.context";
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    68
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    69
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    70
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    71
     * Describe the configuration of a namespace
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    72
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    73
    public static class NamespaceConfig {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    74
        /** name of the namespace - no // allowed **/
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    75
        public String name;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    76
        /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    77
         * JMXServiceURL through which the namespace is exported, if it
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    78
         * is a remote namespace. {@code null} if the namespace is local.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    79
         * This is an inpur URL - eg: new JMXServiceURL("rmi",null,0).toString()
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    80
         * is acceptable here.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    81
         */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    82
        public String jmxurl;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    83
        /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    84
         * Values of the name= key for each WombatMBean contained in the
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    85
         * namespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    86
         */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    87
        public String[] wombats;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    88
        /** list of child namespace **/
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    89
        public NamespaceConfig[] children;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    90
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    91
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    92
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    93
     * Creates a NamespaceConfig record for a local namespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    94
     * @param name     name  of the namespace
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    95
     * @param wombats  names of WombatMBean it should contain.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    96
     * @return a NamespaceConfig.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    97
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    98
    public static NamespaceConfig config(String name, String[] wombats) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
    99
        return config(name,null,wombats);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   100
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   101
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   102
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   103
     * Creates a NamespaceConfig record for a remote namespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   104
     * @param name    name  of the namespace
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   105
     * @param jmxurl  input JMXServiceURL for creating the JMXConnectorServer
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   106
     * @param wombats names of WombatMBean it should contain.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   107
     * @return a NamespaceConfig.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   108
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   109
    public static NamespaceConfig config(String name, String jmxurl,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   110
            String[] wombats) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   111
        return config(name,jmxurl,wombats,(NamespaceConfig[])null);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   112
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   113
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   114
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   115
     * Creates a NamespaceConfig record for a local namespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   116
     * @param name     name  of the namespace
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   117
     * @param wombats  names of WombatMBean it should contain.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   118
     * @param children list  of sub namespaces.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   119
     * @return a NamespaceConfig.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   120
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   121
    public static NamespaceConfig config(String name, String[] wombats,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   122
            NamespaceConfig... children) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   123
        return config(name,null,wombats,children);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   124
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   125
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   126
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   127
     * Creates a NamespaceConfig record for a remote namespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   128
     * @param name    name  of the namespace
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   129
     * @param jmxurl  input JMXServiceURL for creating the JMXConnectorServer
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   130
     * @param wombats names of WombatMBean it should contain.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   131
     * @param children list  of sub namespaces.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   132
     * @return a NamespaceConfig.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   133
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   134
    static NamespaceConfig config(String name, String jmxurl, String[] wombats,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   135
            NamespaceConfig... children) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   136
         final NamespaceConfig cfg = new NamespaceConfig();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   137
         cfg.name=name; cfg.jmxurl=jmxurl; cfg.wombats=wombats;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   138
         cfg.children=children;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   139
         return cfg;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   140
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   141
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   142
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   143
     * Returns the given names. This is a utility method to ease code
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   144
     * reading.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   145
     * @param names names of Wombat MBeans.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   146
     * @return the given names.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   147
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   148
    static String[] wombats(String... names) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   149
        return names;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   150
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   151
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   152
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   153
     * Creates a JMXServiceURL string for the given protocol.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   154
     * This is also a utility method to ease code reading.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   155
     * @param protocol The protocol name (e.g. "rmi")
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   156
     * @return A JMXServiceURL string.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   157
     * @throws Exception if creation of the JMXServiceURL fails.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   158
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   159
    static String url(String protocol) throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   160
        return new JMXServiceURL(protocol,null,0).toString();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   161
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   162
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   163
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   164
     * Creates a config for a hierarchy of namespaces, mixing local namespaces
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   165
     * and remote namespaces using the given protocol.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   166
     * @param protocol The protocol that should be used for remote namespaces.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   167
     * @return A namespace config hierarchy.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   168
     * @throws java.lang.Exception
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   169
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   170
    public static NamespaceConfig[] makeConfig(String protocol)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   171
        throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   172
        final NamespaceConfig[] config = {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   173
        // Top level namespace "top1" (local)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   174
        config("top1",wombats("wchief","w1","w2","w3"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   175
                // top1//local1
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   176
                config("local1",wombats("wchief","ww1","ww2")),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   177
                // top1//local2
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   178
                config("local2",wombats("wchief","ww4","ww5","ww6"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   179
                    // top1//local2//local3
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   180
                    config("local3",wombats("wchief","www1","www2")),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   181
                    // top1//local2//rmi1
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   182
                    config("rmi1",url(protocol),wombats("wchief","www3","www4","www5"))),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   183
                // top1//rmi2
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   184
                config("rmi2",url(protocol),wombats("wchief","ww7","ww8","ww9"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   185
                    // top1//rmi2//local4
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   186
                    config("local4",wombats("wchief","www6","www7")),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   187
                    // top1//rmi2//rmi3
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   188
                    config("rmi3",url(protocol),wombats("wchief","www3","www4","www5"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   189
                        // top1//rmi2//rmi3//local5
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   190
                        config("local5",wombats("wchief","wwww1"))))),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   191
        // Top level namespace "top2" (local)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   192
        config("top2",wombats("wchief","w21","w22","w23"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   193
                // top2//local21
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   194
                config("local21",wombats("wchief","ww21","ww22")),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   195
                // top2//rmi22
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   196
                config("rmi22",url(protocol),wombats("wchief","ww27","ww28","ww29"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   197
                    // top2//rmi22//local24
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   198
                    config("local24",wombats("wchief","www26","www27")),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   199
                    // top2//rmi22//rmi23
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   200
                    config("rmi23",url(protocol),wombats("wchief","www23","www24","www25"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   201
                        // top2//rmi22//rmi23//local25
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   202
                        config("local25",wombats("wchief","wwww21"))))),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   203
        // Top level namespace "top3" (remote)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   204
        config("top3",url(protocol),wombats("wchief","w31","w32","w33"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   205
                // top3//local31
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   206
                config("local31",wombats("wchief","ww31","ww32")),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   207
                // top3//rmi32
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   208
                config("rmi32",url(protocol),wombats("wchief","ww37","ww38","ww39"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   209
                    // top3//rmi32//local34
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   210
                    config("local34",wombats("wchief","www36","www37")),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   211
                    // top3//rmi32//rmi33
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   212
                    config("rmi33",url(protocol),wombats("wchief","www33","www34","www35"),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   213
                        // top3//rmi32//local35
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   214
                        config("local35",wombats("wchief","wwww31"))))),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   215
        };
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   216
        return config;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   217
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   218
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   219
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   220
     * Close all connector servers in the list.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   221
     * @param cslist List of connector servers to close.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   222
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   223
    public static void closeAll(List<JMXConnectorServer> cslist) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   224
            for (JMXConnectorServer cs : cslist) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   225
                try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   226
                    cs.stop();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   227
                } catch (Exception xx) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   228
                    System.err.println("Failed to stop connector: " + xx);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   229
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   230
            }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   231
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   232
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   233
    public static class MBeanServerConfigCreator {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   234
        public MBeanServer createMBeanServerFor(NamespaceConfig config) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   235
            return MBeanServerFactory.newMBeanServer();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   236
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   237
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   238
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   239
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   240
     * Load the given namespace configuration inside the given MBeanServer.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   241
     * Return a list of connector servers created in the process.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   242
     * @param server      The MBeanServer in which the namespaces must
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   243
     *                    be created.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   244
     * @param namespaces  The list of namespaces to create.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   245
     * @return a list of started connector servers.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   246
     * @throws java.lang.Exception failed to create the specified namespaces.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   247
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   248
    public static List<JMXConnectorServer> load(MBeanServer server,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   249
           MBeanServerConfigCreator factory,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   250
           NamespaceConfig... namespaces) throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   251
        final List<JMXConnectorServer> cslist =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   252
                new ArrayList<JMXConnectorServer>();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   253
        try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   254
            final ObjectName creator =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   255
                    new ObjectName("jmx.creator:type=JMXNamespaceCreator");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   256
            if (System.getProperty("jmx.wait")!=null
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   257
                    && !server.isRegistered(creator)) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   258
                server.registerMBean(new JMXNamespaceCreator(),creator);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   259
            }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   260
            for (NamespaceConfig cfg : namespaces) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   261
                final MBeanServer srv = factory.createMBeanServerFor(cfg);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   262
                if (System.getProperty("jmx.wait")!=null
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   263
                    && !srv.isRegistered(creator)) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   264
                    srv.registerMBean(new JMXNamespaceCreator(),creator);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   265
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   266
                if (cfg.wombats != null) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   267
                    for (String w : cfg.wombats) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   268
                        final ObjectName n =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   269
                                new ObjectName("wombat:type=Wombat,name=" + w);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   270
                        final WombatMBean ww = new Wombat();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   271
                        srv.registerMBean(ww, n);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   272
                    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   273
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   274
                if (cfg.children != null) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   275
                    cslist.addAll(load(srv, factory, cfg.children));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   276
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   277
                JMXNamespace nm;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   278
                if (cfg.jmxurl == null) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   279
                    nm = new JMXNamespace(srv);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   280
                } else {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   281
                    JMXConnectorServer cs = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(cfg.jmxurl),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   282
                            null, srv);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   283
                    srv.registerMBean(cs,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   284
                            new ObjectName("jmx.remote:type=JMXConnectorServer"));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   285
                    cs.start();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   286
                    cslist.add(cs);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   287
                    nm = JMXRemoteNamespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   288
                            newJMXRemoteNamespace(cs.getAddress(),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   289
                            null);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   290
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   291
                server.registerMBean(nm,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   292
                        JMXNamespaces.getNamespaceObjectName(cfg.name));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   293
                if (nm instanceof JMXRemoteNamespace) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   294
                    server.invoke(
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   295
                            JMXNamespaces.getNamespaceObjectName(cfg.name),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   296
                            "connect", null, null);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   297
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   298
            }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   299
        } catch (Exception x) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   300
            closeAll(cslist);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   301
            throw x;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   302
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   303
        return cslist;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   304
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   305
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   306
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   307
     * Add an entry {@code <path,NamespaceConfig>} in the map for the given
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   308
     * namespace and its subnamespaces.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   309
     * @param map    A {@code Map<path,NamespaceConfig>}.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   310
     * @param parent The path of the parent workspace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   311
     * @param cfg    The NamespaceConfig hierarchy to index in the map.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   312
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   313
    public static void fillMap(Map<String,NamespaceConfig> map, String parent,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   314
            NamespaceConfig cfg) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   315
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   316
        final String where;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   317
        if (parent == null || parent.equals(""))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   318
            where=cfg.name;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   319
        else
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   320
            where=parent+JMXNamespaces.NAMESPACE_SEPARATOR+cfg.name;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   321
        map.put(where,cfg);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   322
        if (cfg.children==null) return;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   323
        for(NamespaceConfig child:cfg.children) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   324
            fillMap(map,where,child);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   325
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   326
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   327
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   328
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   329
     * Compare a list of namespace names obtained from JMXNamespaceView.list()
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   330
     * with the expected clildren list of the corresponding NamespaceConfig.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   331
     * @param list      A list of namespace names
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   332
     * @param children  A list of NamespaceConfig correspondng to expected
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   333
     *                  namespace.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   334
     * @param fail      If true and the comparison yields false, throws an
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   335
     *                  exception instead of simply returning false.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   336
     * @return true if OK, false if NOK.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   337
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   338
    private static boolean compare(String[] list, NamespaceConfig[] children,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   339
            boolean fail) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   340
        final List<String> found = new ArrayList<String>(Arrays.asList(list));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   341
        if (found.contains(ClientContext.NAMESPACE))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   342
            found.remove(ClientContext.NAMESPACE);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   343
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   344
        if (children == null && found.size()==0) return  true;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   345
        if (children == null && fail == false) return false;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   346
        if (children == null) throw new RuntimeException(
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   347
                "No child expected. Found "+Arrays.toString(list));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   348
        final Set<String> names = new HashSet<String>();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   349
        for (NamespaceConfig cfg : children) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   350
            names.add(cfg.name);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   351
            if (found.contains(cfg.name)) continue;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   352
            if (!fail) return false;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   353
            throw new RuntimeException(cfg.name+" not found in "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   354
                    found);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   355
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   356
        found.removeAll(names);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   357
        if (found.size()==0) return true;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   358
        if (fail==false) return false;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   359
        throw new RuntimeException("found additional namespaces: "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   360
                found);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   361
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   362
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   363
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   364
     * Compares the result of queryNames(null,null) with a set of expected
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   365
     * wombats.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   366
     * @param where    The path of the namespace that was queried.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   367
     * @param list     The set of ObjectNames found.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   368
     * @param wombats  The expected list of wombats.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   369
     * @param fail      If true and the comparison yields false, throws an
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   370
     *                  exception instead of simply returning false.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   371
     * @return true if OK, false if NOK.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   372
     * @throws java.lang.Exception something went wrong.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   373
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   374
    private static boolean compare(String where,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   375
            Set<ObjectName>list, String[] wombats,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   376
            boolean fail) throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   377
        final Set<ObjectName> found = new HashSet<ObjectName>();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   378
        final Set<ObjectName> expected = new HashSet<ObjectName>();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   379
        for (ObjectName n : list) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   380
            if ("Wombat".equals(n.getKeyProperty("type")))
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   381
               found.add(n);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   382
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   383
        for(String w : wombats) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   384
            final ObjectName n =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   385
                    new ObjectName("wombat:type=Wombat,name=" + w);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   386
            expected.add(n);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   387
            if (found.contains(n)) continue;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   388
            if (fail == false) return false;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   389
            throw new RuntimeException(where+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   390
                    ": Wombat "+w+" not found in "+found);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   391
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   392
        found.removeAll(expected);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   393
        if (found.size()==0) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   394
            System.out.println(where+": found all expected: "+expected);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   395
            return true;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   396
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   397
        if (fail==false) return false;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   398
        throw new RuntimeException(where+": found additional MBeans: "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   399
                found);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   400
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   401
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   402
    /**
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   403
     * A generic test to test JMXNamespaceView over a namespace configuration.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   404
     * @param server      The MBeanServer in which to load the namespace
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   405
     *                    config.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   406
     * @param namespaces  The namespace config to run the test over...
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   407
     * @throws java.lang.Exception
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   408
     */
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   409
    public static void doTest(MBeanServer server, NamespaceConfig... namespaces)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   410
            throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   411
        List<JMXConnectorServer> cslist = load(server,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   412
                new MBeanServerConfigCreator(), namespaces);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   413
        Map<String,NamespaceConfig> inputMap =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   414
                new HashMap<String,NamespaceConfig>();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   415
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   416
        for (NamespaceConfig cfg : namespaces) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   417
            fillMap(inputMap,"",cfg);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   418
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   419
        try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   420
            final JMXNamespaceView root = new JMXNamespaceView(server);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   421
            List<JMXNamespaceView> vlist = new ArrayList<JMXNamespaceView>();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   422
            vlist.add(root);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   423
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   424
            while (!vlist.isEmpty()) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   425
                JMXNamespaceView v = vlist.remove(0);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   426
                final String where = v.isRoot()?"root":v.where();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   427
                System.out.println(where+": "+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   428
                   v.getMBeanServerConnection().queryNames(null,null));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   429
                for (String ns : v.list()) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   430
                    final JMXNamespaceView down = v.down(ns);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   431
                    vlist.add(down);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   432
                    if (!down.where().equals(v.isRoot()?ns:where+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   433
                            JMXNamespaces.NAMESPACE_SEPARATOR+ns)) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   434
                        throw new RuntimeException("path of "+down.where()+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   435
                            " should be "+(v.isRoot()?ns:where+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   436
                            JMXNamespaces.NAMESPACE_SEPARATOR+ns));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   437
                    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   438
                    if (down.up().equals(v)) continue;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   439
                    throw new RuntimeException("parent of "+down.where()+
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   440
                            " should be "+where);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   441
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   442
                final NamespaceConfig[] children;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   443
                final NamespaceConfig   cfg;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   444
                if (v.isRoot()) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   445
                    children=namespaces;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   446
                    cfg = null;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   447
                } else {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   448
                    cfg = inputMap.get(where);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   449
                    children = cfg==null?null:cfg.children;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   450
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   451
                compare(v.list(),children,true);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   452
                if (!v.isRoot()) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   453
                    if (where.endsWith(ClientContext.NAMESPACE)) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   454
                        System.out.println(where+": skipping queryNames analysis");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   455
                        continue;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   456
                    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   457
                    //System.out.println(where+": cfg is: "+cfg);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   458
                    compare(where,v.getMBeanServerConnection().
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   459
                        queryNames(null, null),cfg.wombats,true);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   460
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   461
            }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   462
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   463
            exportAndWaitIfNeeded(server);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   464
        } finally {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   465
            closeAll(cslist);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   466
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   467
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   468
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   469
    public static interface JMXNamespaceCreatorMBean {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   470
        public ObjectInstance createLocalNamespace(String namespace)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   471
                throws JMException ;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   472
        public void removeLocalNamespace(String namespace)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   473
                throws JMException;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   474
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   475
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   476
    public static class JMXNamespaceCreator
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   477
            implements MBeanRegistration,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   478
                      JMXNamespaceCreatorMBean {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   479
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   480
        private volatile MBeanServer mbeanServer;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   481
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   482
        public ObjectInstance createLocalNamespace(String namespace)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   483
            throws JMException {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   484
            return mbeanServer.registerMBean(
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   485
                    new JMXNamespace(MBeanServerFactory.newMBeanServer()),
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   486
                    JMXNamespaces.getNamespaceObjectName(namespace));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   487
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   488
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   489
        public void removeLocalNamespace(String namespace)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   490
            throws JMException {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   491
            mbeanServer.unregisterMBean(
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   492
                    JMXNamespaces.getNamespaceObjectName(namespace));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   493
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   494
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   495
        public ObjectName preRegister(MBeanServer server, ObjectName name)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   496
                throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   497
            mbeanServer = server;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   498
            return name;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   499
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   500
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   501
        public void postRegister(Boolean registrationDone) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   502
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   503
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   504
        public void preDeregister() throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   505
         }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   506
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   507
        public void postDeregister() {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   508
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   509
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   510
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   511
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   512
    public static void exportAndWaitIfNeeded(MBeanServer server)
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   513
        throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   514
                if (System.getProperty("jmx.wait")!=null) {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   515
                final int port = getPortFor("rmi");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   516
                LocateRegistry.createRegistry(port);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   517
                final JMXServiceURL url =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   518
                        new JMXServiceURL("rmi",null,port,
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   519
                        "/jndi/rmi://localhost:"+port+"/jmxrmi");
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   520
                final JMXConnectorServer cs =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   521
                        JMXConnectorServerFactory.
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   522
                        newJMXConnectorServer(url, null, server);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   523
                cs.start();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   524
                try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   525
                    System.out.println("RMI Server waiting at: "+cs.getAddress());
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   526
                    System.in.read();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   527
                } finally {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   528
                    cs.stop();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   529
                }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   530
            }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   531
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   532
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   533
    public static int getPortFor(String protocol) throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   534
        final int aport =
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   535
              Integer.valueOf(System.getProperty("jmx."+protocol+".port","0"));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   536
        if (aport > 0) return aport;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   537
        final ServerSocket s = new ServerSocket(0);
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   538
        try {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   539
            final int port = s.getLocalPort();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   540
            return port;
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   541
        } finally {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   542
            s.close();
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   543
        }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   544
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   545
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   546
    public static void main(String[] args) throws Exception {
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   547
        doTest(ManagementFactory.getPlatformMBeanServer(),makeConfig("rmi"));
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   548
    }
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   549
bbc2d15aaf7a 5072476: RFE: support cascaded (federated) MBean Servers
dfuchs
parents:
diff changeset
   550
}