jdk/src/java.management/share/classes/javax/management/remote/rmi/RMIConnector.java
author sjiang
Fri, 12 Sep 2014 12:19:27 +0200
changeset 26594 b561a19107c7
parent 25859 3317bb8137f4
child 32034 05676cfd40b5
permissions -rw-r--r--
8049303: Transient network problems cause JMX thread to fail silenty Reviewed-by: dfuchs, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
20808
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
     2
 * Copyright (c) 2002, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4167
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4167
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4167
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4167
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4167
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management.remote.rmi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
    28
import com.sun.jmx.mbeanserver.Util;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.remote.internal.ClientCommunicatorAdmin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jmx.remote.internal.ClientListenerInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jmx.remote.internal.ClientNotifForwarder;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import com.sun.jmx.remote.internal.ProxyRef;
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
    33
import com.sun.jmx.remote.internal.IIOPHelper;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import com.sun.jmx.remote.util.ClassLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import com.sun.jmx.remote.util.EnvHelp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.io.ByteArrayInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.io.InvalidObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.io.NotSerializableException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.io.ObjectInputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.io.ObjectStreamClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.io.Serializable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.io.WriteAbortedException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.lang.reflect.Constructor;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.lang.reflect.InvocationHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.lang.reflect.InvocationTargetException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.lang.reflect.Proxy;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import java.rmi.MarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import java.rmi.MarshalledObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
import java.rmi.NoSuchObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
import java.rmi.ServerException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
import java.rmi.UnmarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
import java.rmi.server.RMIClientSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
import java.rmi.server.RemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
import java.rmi.server.RemoteObjectInvocationHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
import java.rmi.server.RemoteRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
import java.security.PrivilegedExceptionAction;
20808
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
    64
import java.security.PrivilegedActionException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
import java.security.ProtectionDomain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
import java.util.Arrays;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
import java.util.Properties;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
import java.util.WeakHashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
import javax.management.Attribute;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
import javax.management.AttributeList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
import javax.management.AttributeNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
import javax.management.InstanceAlreadyExistsException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
import javax.management.InstanceNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
import javax.management.IntrospectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
import javax.management.InvalidAttributeValueException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
import javax.management.ListenerNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
import javax.management.MBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
import javax.management.MBeanInfo;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
import javax.management.MBeanRegistrationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
import javax.management.MBeanServerConnection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
import javax.management.MBeanServerDelegate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
import javax.management.MBeanServerNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
import javax.management.NotCompliantMBeanException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
import javax.management.Notification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
import javax.management.NotificationBroadcasterSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
import javax.management.NotificationFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
import javax.management.NotificationFilterSupport;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
import javax.management.NotificationListener;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
import javax.management.ObjectInstance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
import javax.management.ObjectName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
import javax.management.QueryExp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
import javax.management.ReflectionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
import javax.management.remote.JMXConnectionNotification;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
import javax.management.remote.JMXConnector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
import javax.management.remote.JMXConnectorFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
import javax.management.remote.JMXServiceURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
import javax.management.remote.NotificationResult;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
import javax.management.remote.JMXAddressable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
import javax.naming.InitialContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
import javax.naming.NamingException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
import javax.rmi.ssl.SslRMIClientSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
import javax.security.auth.Subject;
18206
136373d8d805 8008615: Improve robustness of JMX internal APIs
sjiang
parents: 14917
diff changeset
   107
import sun.reflect.misc.ReflectUtil;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
import sun.rmi.server.UnicastRef2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
import sun.rmi.transport.LiveRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * <p>A connection to a remote RMI connector.  Usually, such
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * connections are made using {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * javax.management.remote.JMXConnectorFactory JMXConnectorFactory}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * However, specialized applications can use this class directly, for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * example with an {@link RMIServer} stub obtained without going
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * through JNDI.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
public class RMIConnector implements JMXConnector, Serializable, JMXAddressable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
    private static final ClassLogger logger =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   124
            new ClassLogger("javax.management.remote.rmi", "RMIConnector");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    private static final long serialVersionUID = 817323035842634473L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private RMIConnector(RMIServer rmiServer, JMXServiceURL address,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   129
            Map<String, ?> environment) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        if (rmiServer == null && address == null) throw new
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   131
                IllegalArgumentException("rmiServer and jmxServiceURL both null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        initTransients();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        this.rmiServer = rmiServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
        this.jmxServiceURL = address;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        if (environment == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            this.env = Collections.emptyMap();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            EnvHelp.checkAttributes(environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            this.env = Collections.unmodifiableMap(environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <p>Constructs an <code>RMIConnector</code> that will connect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * the RMI connector server with the given address.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * <p>The address can refer directly to the connector server,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * using one of the following syntaxes:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * service:jmx:rmi://<em>[host[:port]]</em>/stub/<em>encoded-stub</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * service:jmx:iiop://<em>[host[:port]]</em>/ior/<em>encoded-IOR</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p>(Here, the square brackets <code>[]</code> are not part of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * address but indicate that the host and port are optional.)</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * <p>The address can instead indicate where to find an RMI stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * through JNDI, using one of the following syntaxes:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * service:jmx:rmi://<em>[host[:port]]</em>/jndi/<em>jndi-name</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * service:jmx:iiop://<em>[host[:port]]</em>/jndi/<em>jndi-name</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
     * <p>An implementation may also recognize additional address
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * syntaxes, for example:</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * service:jmx:iiop://<em>[host[:port]]</em>/stub/<em>encoded-stub</em>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @param url the address of the RMI connector server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * @param environment additional attributes specifying how to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * the connection.  For JNDI-based addresses, these attributes can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * usefully include JNDI attributes recognized by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * InitialContext#InitialContext(Hashtable) InitialContext}.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * parameter can be null, which is equivalent to an empty Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * @exception IllegalArgumentException if <code>url</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public RMIConnector(JMXServiceURL url, Map<String,?> environment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        this(null, url, environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * <p>Constructs an <code>RMIConnector</code> using the given RMI stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param rmiServer an RMI stub representing the RMI connector server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * @param environment additional attributes specifying how to make
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * the connection.  This parameter can be null, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * equivalent to an empty Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * @exception IllegalArgumentException if <code>rmiServer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    public RMIConnector(RMIServer rmiServer, Map<String,?> environment) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        this(rmiServer, null, environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * <p>Returns a string representation of this object.  In general,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * the <code>toString</code> method returns a string that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * "textually represents" this object. The result should be a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * concise but informative representation that is easy for a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * person to read.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * @return a String representation of this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     **/
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1570
diff changeset
   213
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        final StringBuilder b = new StringBuilder(this.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        b.append(":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        if (rmiServer != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            b.append(" rmiServer=").append(rmiServer.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
        if (jmxServiceURL != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            if (rmiServer!=null) b.append(",");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
            b.append(" jmxServiceURL=").append(jmxServiceURL.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return b.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * <p>The address of this connector.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return the address of this connector, or null if it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * does not have one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * @since 1.6
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public JMXServiceURL getAddress() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        return jmxServiceURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
    // implements JMXConnector interface
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
    //--------------------------------------------------------------------
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   242
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   243
    /**
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   244
     * @throws IOException if the connection could not be made because of a
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   245
     *   communication problem, or in the case of the {@code iiop} protocol,
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   246
     *   that RMI/IIOP is not supported
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   247
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
    public void connect() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        connect(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
14917
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   252
    /**
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   253
     * @throws IOException if the connection could not be made because of a
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   254
     *   communication problem, or in the case of the {@code iiop} protocol,
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   255
     *   that RMI/IIOP is not supported
bf08557604f8 8001048: JSR-160: Allow IIOP transport to be optional
alanb
parents: 14342
diff changeset
   256
     */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    public synchronized void connect(Map<String,?> environment)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   258
    throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
        final boolean tracing = logger.traceOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        String        idstr   = (tracing?"["+this.toString()+"]":null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (terminated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            logger.trace("connect",idstr + " already closed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
            throw new IOException("Connector closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
        if (connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
            logger.trace("connect",idstr + " already connected.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
            if (tracing) logger.trace("connect",idstr + " connecting...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            final Map<String, Object> usemap =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   275
                    new HashMap<String, Object>((this.env==null) ?
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   276
                        Collections.<String, Object>emptyMap() : this.env);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            if (environment != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                EnvHelp.checkAttributes(environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
                usemap.putAll(environment);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            // Get RMIServer stub from directory or URL encoding if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            if (tracing) logger.trace("connect",idstr + " finding stub...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            RMIServer stub = (rmiServer!=null)?rmiServer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                findRMIServer(jmxServiceURL, usemap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            // Check for secure RMIServer stub if the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            // client-side environment property is set to "true".
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            //
14210
042f1a001234 7158796: Tighten properties checking in EnvHelp
dsamersoff
parents: 7167
diff changeset
   292
            String stringBoolean =  (String) usemap.get("jmx.remote.x.check.stub");
042f1a001234 7158796: Tighten properties checking in EnvHelp
dsamersoff
parents: 7167
diff changeset
   293
            boolean checkStub = EnvHelp.computeBooleanFromString(stringBoolean);
042f1a001234 7158796: Tighten properties checking in EnvHelp
dsamersoff
parents: 7167
diff changeset
   294
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            if (checkStub) checkStub(stub, rmiServerImplStubClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            // Connect IIOP Stub if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            if (tracing) logger.trace("connect",idstr + " connecting stub...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            stub = connectStub(stub,usemap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            idstr = (tracing?"["+this.toString()+"]":null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            // Calling newClient on the RMIServer stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                logger.trace("connect",idstr + " getting connection...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            Object credentials = usemap.get(CREDENTIALS);
7167
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   306
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   307
            try {
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   308
                connection = getConnection(stub, credentials, checkStub);
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   309
            } catch (java.rmi.RemoteException re) {
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   310
                if (jmxServiceURL != null) {
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   311
                    final String pro = jmxServiceURL.getProtocol();
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   312
                    final String path = jmxServiceURL.getURLPath();
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   313
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   314
                    if ("rmi".equals(pro) &&
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   315
                        path.startsWith("/jndi/iiop:")) {
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   316
                        MalformedURLException mfe = new MalformedURLException(
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   317
                              "Protocol is rmi but JNDI scheme is iiop: " + jmxServiceURL);
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   318
                        mfe.initCause(re);
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   319
                        throw mfe;
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   320
                    }
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   321
                }
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   322
                throw re;
f5a0fca591f8 6696028: JMXServiceURL like service:jmx:rmi:///jndi/iiop:// should be rejected by the RMI conn provider.
coffeys
parents: 5506
diff changeset
   323
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            // Always use one of:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            //   ClassLoader provided in Map at connect time,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            //   or contextClassLoader at connect time.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                logger.trace("connect",idstr + " getting class loader...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            defaultClassLoader = EnvHelp.resolveClientClassLoader(usemap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
            usemap.put(JMXConnectorFactory.DEFAULT_CLASS_LOADER,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   333
                    defaultClassLoader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
            rmiNotifClient = new RMINotifClient(defaultClassLoader, usemap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            env = usemap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            final long checkPeriod = EnvHelp.getConnectionCheckPeriod(usemap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            communicatorAdmin = new RMIClientCommunicatorAdmin(checkPeriod);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            connected = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            // The connectionId variable is used in doStart(), when
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            // reconnecting, to identify the "old" connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            connectionId = getConnectionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
            Notification connectedNotif =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   349
                    new JMXConnectionNotification(JMXConnectionNotification.OPENED,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   350
                    this,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   351
                    connectionId,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   352
                    clientNotifSeqNo++,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   353
                    "Successful connection",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   354
                    null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            sendNotification(connectedNotif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            if (tracing) logger.trace("connect",idstr + " done...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                logger.trace("connect",idstr + " failed to connect: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
        } catch (RuntimeException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
                logger.trace("connect",idstr + " failed to connect: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        } catch (NamingException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
            final String msg = "Failed to retrieve RMIServer stub: " + e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            if (tracing) logger.trace("connect",idstr + " " + msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            throw EnvHelp.initCause(new IOException(msg),e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
    public synchronized String getConnectionId() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        if (terminated || !connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
            if (logger.traceOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                logger.trace("getConnectionId","["+this.toString()+
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   377
                        "] not connected.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            throw new IOException("Not connected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // we do a remote call to have an IOException if the connection is broken.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        // see the bug 4939578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        return connection.getConnectionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    public synchronized MBeanServerConnection getMBeanServerConnection()
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   388
    throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
        return getMBeanServerConnection(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
    public synchronized MBeanServerConnection
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   393
            getMBeanServerConnection(Subject delegationSubject)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        if (terminated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
            if (logger.traceOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                logger.trace("getMBeanServerConnection","[" + this.toString() +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   399
                        "] already closed.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            throw new IOException("Connection closed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        } else if (!connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (logger.traceOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                logger.trace("getMBeanServerConnection","[" + this.toString() +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   404
                        "] is not connected.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            throw new IOException("Not connected");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
19791
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
   408
        return getConnectionWithSubject(delegationSubject);
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   409
    }
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   410
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    public void
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   412
            addConnectionNotificationListener(NotificationListener listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   413
            NotificationFilter filter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   414
            Object handback) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        if (listener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            throw new NullPointerException("listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        connectionBroadcaster.addNotificationListener(listener, filter,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   418
                handback);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    public void
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   422
            removeConnectionNotificationListener(NotificationListener listener)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            throws ListenerNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        if (listener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
            throw new NullPointerException("listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        connectionBroadcaster.removeNotificationListener(listener);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
    public void
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   430
            removeConnectionNotificationListener(NotificationListener listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   431
            NotificationFilter filter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   432
            Object handback)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
            throws ListenerNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
        if (listener == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            throw new NullPointerException("listener");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        connectionBroadcaster.removeNotificationListener(listener, filter,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   437
                handback);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    private void sendNotification(Notification n) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        connectionBroadcaster.sendNotification(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    public synchronized void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        close(false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    // allows to do close after setting the flag "terminated" to true.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    // It is necessary to avoid a deadlock, see 6296324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
    private synchronized void close(boolean intern) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        final boolean tracing = logger.traceOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        final boolean debug   = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        final String  idstr   = (tracing?"["+this.toString()+"]":null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        if (!intern) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
            // Return if already cleanly closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
            if (terminated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                if (closeException == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    if (tracing) logger.trace("close",idstr + " already closed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                    return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                terminated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        if (closeException != null && tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            // Already closed, but not cleanly. Attempt again.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
            if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                logger.trace("close",idstr + " had failed: " + closeException);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                logger.trace("close",idstr + " attempting to close again.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        String savedConnectionId = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        if (connected) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            savedConnectionId = connectionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
        closeException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
        if (tracing) logger.trace("close",idstr + " closing.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        if (communicatorAdmin != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            communicatorAdmin.terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        if (rmiNotifClient != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
                rmiNotifClient.terminate();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
                if (tracing) logger.trace("close",idstr +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   494
                        " RMI Notification client terminated.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            } catch (RuntimeException x) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                closeException = x;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                if (tracing) logger.trace("close",idstr +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   498
                        " Failed to terminate RMI Notification client: " + x);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                if (debug) logger.debug("close",x);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (connection != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                connection.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                if (tracing) logger.trace("close",idstr + " closed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            } catch (NoSuchObjectException nse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                // OK, the server maybe closed itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                closeException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                if (tracing) logger.trace("close",idstr +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   512
                        " Failed to close RMIServer: " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                if (debug) logger.debug("close",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        // Clean up MBeanServerConnection table
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        rmbscMap.clear();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        /* Send notification of closure.  We don't do this if the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
         * never called connect() on the connector, because there's no
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
         * connection id in that case.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        if (savedConnectionId != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
            Notification closedNotif =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   527
                    new JMXConnectionNotification(JMXConnectionNotification.CLOSED,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   528
                    this,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   529
                    savedConnectionId,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   530
                    clientNotifSeqNo++,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   531
                    "Client has been closed",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   532
                    null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            sendNotification(closedNotif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        // throw exception if needed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
        if (closeException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
            if (tracing) logger.trace("close",idstr + " failed to close: " +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   540
                    closeException);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            if (closeException instanceof IOException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                throw (IOException) closeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
            if (closeException instanceof RuntimeException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
                throw (RuntimeException) closeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
            final IOException x =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   546
                    new IOException("Failed to close: " + closeException);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
            throw EnvHelp.initCause(x,closeException);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
    // added for re-connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    private Integer addListenerWithSubject(ObjectName name,
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
   553
                                           MarshalledObject<NotificationFilter> filter,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
                                           Subject delegationSubject,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
                                           boolean reconnect)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
        throws InstanceNotFoundException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
        if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            logger.debug("addListenerWithSubject",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   561
                    "(ObjectName,MarshalledObject,Subject)");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
        final ObjectName[] names = new ObjectName[] {name};
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
   564
        final MarshalledObject<NotificationFilter>[] filters =
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
   565
                Util.cast(new MarshalledObject<?>[] {filter});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
        final Subject[] delegationSubjects = new Subject[] {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
            delegationSubject
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        final Integer[] listenerIDs =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   571
                addListenersWithSubjects(names,filters,delegationSubjects,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   572
                reconnect);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
        if (debug) logger.debug("addListenerWithSubject","listenerID="
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   575
                + listenerIDs[0]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        return listenerIDs[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
90ce3da70b43 Initial load
duke
parents:
diff changeset
   579
    // added for re-connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   580
    private Integer[] addListenersWithSubjects(ObjectName[]       names,
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
   581
                             MarshalledObject<NotificationFilter>[] filters,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                             Subject[]          delegationSubjects,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                             boolean            reconnect)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
        throws InstanceNotFoundException, IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
        final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
        if (debug)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   588
            logger.debug("addListenersWithSubjects",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   589
                    "(ObjectName[],MarshalledObject[],Subject[])");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
        final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
        Integer[] listenerIDs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
            listenerIDs = connection.addNotificationListeners(names,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   596
                    filters,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   597
                    delegationSubjects);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
        } catch (NoSuchObjectException noe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
            // maybe reconnect
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
            if (reconnect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                communicatorAdmin.gotIOException(noe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                listenerIDs = connection.addNotificationListeners(names,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   604
                        filters,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   605
                        delegationSubjects);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                throw noe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
        } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
            // send a failed notif if necessary
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
            communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
        } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
        if (debug) logger.debug("addListenersWithSubjects","registered "
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   617
                + ((listenerIDs==null)?0:listenerIDs.length)
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   618
                + " listener(s)");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
        return listenerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   623
    // Implementation of MBeanServerConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
    //--------------------------------------------------------------------
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   625
    private class RemoteMBeanServerConnection implements MBeanServerConnection {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
   626
        private Subject delegationSubject;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        public RemoteMBeanServerConnection() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
            this(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        public RemoteMBeanServerConnection(Subject delegationSubject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            this.delegationSubject = delegationSubject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
        public ObjectInstance createMBean(String className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   637
                ObjectName name)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   638
                throws ReflectionException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   639
                InstanceAlreadyExistsException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   640
                MBeanRegistrationException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   641
                MBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   642
                NotCompliantMBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   643
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
                logger.debug("createMBean(String,ObjectName)",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   646
                        "className=" + className + ", name=" +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   647
                        name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   648
90ce3da70b43 Initial load
duke
parents:
diff changeset
   649
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                return connection.createMBean(className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   652
                        name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   653
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   654
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   655
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   656
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
                return connection.createMBean(className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   658
                        name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   659
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   660
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   661
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   662
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   663
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   664
90ce3da70b43 Initial load
duke
parents:
diff changeset
   665
        public ObjectInstance createMBean(String className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   666
                ObjectName name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   667
                ObjectName loaderName)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   668
                throws ReflectionException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   669
                InstanceAlreadyExistsException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   670
                MBeanRegistrationException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   671
                MBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   672
                NotCompliantMBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   673
                InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   674
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   675
90ce3da70b43 Initial load
duke
parents:
diff changeset
   676
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   677
                logger.debug("createMBean(String,ObjectName,ObjectName)",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   678
                        "className=" + className + ", name="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   679
                        + name + ", loaderName="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   680
                        + loaderName + ")");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   681
90ce3da70b43 Initial load
duke
parents:
diff changeset
   682
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   683
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
                return connection.createMBean(className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   685
                        name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   686
                        loaderName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   687
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   688
90ce3da70b43 Initial load
duke
parents:
diff changeset
   689
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   690
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   691
90ce3da70b43 Initial load
duke
parents:
diff changeset
   692
                return connection.createMBean(className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   693
                        name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   694
                        loaderName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   695
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   696
90ce3da70b43 Initial load
duke
parents:
diff changeset
   697
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   698
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   699
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   700
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   701
90ce3da70b43 Initial load
duke
parents:
diff changeset
   702
        public ObjectInstance createMBean(String className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   703
                ObjectName name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   704
                Object params[],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   705
                String signature[])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   706
                throws ReflectionException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   707
                InstanceAlreadyExistsException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   708
                MBeanRegistrationException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   709
                MBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   710
                NotCompliantMBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   711
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   712
            if (logger.debugOn())
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   713
                logger.debug("createMBean(String,ObjectName,Object[],String[])",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   714
                        "className=" + className + ", name="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   715
                        + name + ", params="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   716
                        + objects(params) + ", signature="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   717
                        + strings(signature));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   718
90ce3da70b43 Initial load
duke
parents:
diff changeset
   719
            final MarshalledObject<Object[]> sParams =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   720
                    new MarshalledObject<Object[]>(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   721
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   722
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   723
                return connection.createMBean(className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   724
                        name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   725
                        sParams,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   726
                        signature,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   727
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   728
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   729
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   730
90ce3da70b43 Initial load
duke
parents:
diff changeset
   731
                return connection.createMBean(className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   732
                        name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   733
                        sParams,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   734
                        signature,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   735
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   736
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   737
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   738
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   739
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   740
90ce3da70b43 Initial load
duke
parents:
diff changeset
   741
        public ObjectInstance createMBean(String className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   742
                ObjectName name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   743
                ObjectName loaderName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   744
                Object params[],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   745
                String signature[])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   746
                throws ReflectionException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   747
                InstanceAlreadyExistsException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   748
                MBeanRegistrationException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   749
                MBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   750
                NotCompliantMBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   751
                InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   752
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
            if (logger.debugOn()) logger.debug(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   754
                    "createMBean(String,ObjectName,ObjectName,Object[],String[])",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   755
                    "className=" + className + ", name=" + name + ", loaderName="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   756
                    + loaderName + ", params=" + objects(params)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   757
                    + ", signature=" + strings(signature));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
            final MarshalledObject<Object[]> sParams =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
                    new MarshalledObject<Object[]>(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   762
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
                return connection.createMBean(className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   764
                        name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   765
                        loaderName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   766
                        sParams,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   767
                        signature,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   768
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
                return connection.createMBean(className,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   773
                        name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   774
                        loaderName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   775
                        sParams,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   776
                        signature,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   777
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
        public void unregisterMBean(ObjectName name)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   784
        throws InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   785
                MBeanRegistrationException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   786
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   788
                logger.debug("unregisterMBean", "name=" + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   789
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   792
                connection.unregisterMBean(name, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   793
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   794
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   795
90ce3da70b43 Initial load
duke
parents:
diff changeset
   796
                connection.unregisterMBean(name, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   797
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   798
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   799
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   800
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   801
90ce3da70b43 Initial load
duke
parents:
diff changeset
   802
        public ObjectInstance getObjectInstance(ObjectName name)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   803
        throws InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   804
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   805
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   806
                logger.debug("getObjectInstance", "name=" + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   809
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   810
                return connection.getObjectInstance(name, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   811
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
90ce3da70b43 Initial load
duke
parents:
diff changeset
   814
                return connection.getObjectInstance(name, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   815
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   816
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   817
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   818
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   819
90ce3da70b43 Initial load
duke
parents:
diff changeset
   820
        public Set<ObjectInstance> queryMBeans(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   821
                QueryExp query)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   822
                throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            if (logger.debugOn()) logger.debug("queryMBeans",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   824
                    "name=" + name + ", query=" + query);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
90ce3da70b43 Initial load
duke
parents:
diff changeset
   826
            final MarshalledObject<QueryExp> sQuery =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   827
                    new MarshalledObject<QueryExp>(query);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   828
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   830
                return connection.queryMBeans(name, sQuery, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   831
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   832
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   833
90ce3da70b43 Initial load
duke
parents:
diff changeset
   834
                return connection.queryMBeans(name, sQuery, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   835
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   838
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   839
90ce3da70b43 Initial load
duke
parents:
diff changeset
   840
        public Set<ObjectName> queryNames(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   841
                QueryExp query)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   842
                throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   843
            if (logger.debugOn()) logger.debug("queryNames",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   844
                    "name=" + name + ", query=" + query);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   845
90ce3da70b43 Initial load
duke
parents:
diff changeset
   846
            final MarshalledObject<QueryExp> sQuery =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   847
                    new MarshalledObject<QueryExp>(query);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   848
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   849
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   850
                return connection.queryNames(name, sQuery, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   851
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   852
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   853
90ce3da70b43 Initial load
duke
parents:
diff changeset
   854
                return connection.queryNames(name, sQuery, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   855
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   856
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   857
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   858
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   859
90ce3da70b43 Initial load
duke
parents:
diff changeset
   860
        public boolean isRegistered(ObjectName name)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   861
        throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   862
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   863
                logger.debug("isRegistered", "name=" + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   864
90ce3da70b43 Initial load
duke
parents:
diff changeset
   865
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   866
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   867
                return connection.isRegistered(name, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   868
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   869
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   870
90ce3da70b43 Initial load
duke
parents:
diff changeset
   871
                return connection.isRegistered(name, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   872
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   873
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   874
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   875
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   876
90ce3da70b43 Initial load
duke
parents:
diff changeset
   877
        public Integer getMBeanCount()
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   878
        throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            if (logger.debugOn()) logger.debug("getMBeanCount", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
                return connection.getMBeanCount(delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   885
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   886
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
                return connection.getMBeanCount(delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   890
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   891
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   892
90ce3da70b43 Initial load
duke
parents:
diff changeset
   893
        public Object getAttribute(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   894
                String attribute)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   895
                throws MBeanException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   896
                AttributeNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   897
                InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   898
                ReflectionException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   899
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   900
            if (logger.debugOn()) logger.debug("getAttribute",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   901
                    "name=" + name + ", attribute="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   902
                    + attribute);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   903
90ce3da70b43 Initial load
duke
parents:
diff changeset
   904
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   905
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   906
                return connection.getAttribute(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   907
                        attribute,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   908
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   909
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   910
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   911
90ce3da70b43 Initial load
duke
parents:
diff changeset
   912
                return connection.getAttribute(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   913
                        attribute,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   914
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   915
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   916
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   917
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   918
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   919
90ce3da70b43 Initial load
duke
parents:
diff changeset
   920
        public AttributeList getAttributes(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   921
                String[] attributes)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   922
                throws InstanceNotFoundException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   923
                ReflectionException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   924
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   925
            if (logger.debugOn()) logger.debug("getAttributes",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   926
                    "name=" + name + ", attributes="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   927
                    + strings(attributes));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   928
90ce3da70b43 Initial load
duke
parents:
diff changeset
   929
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
                return connection.getAttributes(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   932
                        attributes,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   933
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   934
90ce3da70b43 Initial load
duke
parents:
diff changeset
   935
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   936
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   937
90ce3da70b43 Initial load
duke
parents:
diff changeset
   938
                return connection.getAttributes(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   939
                        attributes,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   940
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   941
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   945
90ce3da70b43 Initial load
duke
parents:
diff changeset
   946
90ce3da70b43 Initial load
duke
parents:
diff changeset
   947
        public void setAttribute(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   948
                Attribute attribute)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   949
                throws InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   950
                AttributeNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   951
                InvalidAttributeValueException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   952
                MBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   953
                ReflectionException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   954
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
            if (logger.debugOn()) logger.debug("setAttribute",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   957
                    "name=" + name + ", attribute="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   958
                    + attribute);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   959
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            final MarshalledObject<Attribute> sAttribute =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   961
                    new MarshalledObject<Attribute>(attribute);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   963
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   964
                connection.setAttribute(name, sAttribute, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   965
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   966
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   967
90ce3da70b43 Initial load
duke
parents:
diff changeset
   968
                connection.setAttribute(name, sAttribute, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   970
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   972
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
90ce3da70b43 Initial load
duke
parents:
diff changeset
   974
        public AttributeList setAttributes(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   975
                AttributeList attributes)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   976
                throws InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   977
                ReflectionException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   978
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
            if (logger.debugOn()) logger.debug("setAttributes",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   981
                    "name=" + name + ", attributes="
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   982
                    + attributes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   983
90ce3da70b43 Initial load
duke
parents:
diff changeset
   984
            final MarshalledObject<AttributeList> sAttributes =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   985
                    new MarshalledObject<AttributeList>(attributes);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   986
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   987
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   988
                return connection.setAttributes(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   989
                        sAttributes,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   990
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   991
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   992
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   993
90ce3da70b43 Initial load
duke
parents:
diff changeset
   994
                return connection.setAttributes(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   995
                        sAttributes,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
   996
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   997
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   998
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   999
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1000
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1002
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1003
        public Object invoke(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1004
                String operationName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1005
                Object params[],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1006
                String signature[])
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1007
                throws InstanceNotFoundException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1008
                MBeanException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1009
                ReflectionException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1010
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1011
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1012
            if (logger.debugOn()) logger.debug("invoke",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1013
                    "name=" + name
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1014
                    + ", operationName=" + operationName
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1015
                    + ", params=" + objects(params)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1016
                    + ", signature=" + strings(signature));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1017
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1018
            final MarshalledObject<Object[]> sParams =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1019
                    new MarshalledObject<Object[]>(params);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1020
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1021
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1022
                return connection.invoke(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1023
                        operationName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1024
                        sParams,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1025
                        signature,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1026
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1027
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1028
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1029
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1030
                return connection.invoke(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1031
                        operationName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1032
                        sParams,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1033
                        signature,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1034
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1035
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1036
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1037
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1038
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1039
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1040
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1041
        public String getDefaultDomain()
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1042
        throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1043
            if (logger.debugOn()) logger.debug("getDefaultDomain", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1044
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1045
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1046
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1047
                return connection.getDefaultDomain(delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1048
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1049
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1050
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1051
                return connection.getDefaultDomain(delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1052
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1053
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1054
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1055
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1056
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1057
        public String[] getDomains() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1058
            if (logger.debugOn()) logger.debug("getDomains", "");
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1059
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1060
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1061
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1062
                return connection.getDomains(delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1063
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1064
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1066
                return connection.getDomains(delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1067
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1068
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1069
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1070
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1071
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1072
        public MBeanInfo getMBeanInfo(ObjectName name)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1073
        throws InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1074
                IntrospectionException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1075
                ReflectionException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1076
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1078
            if (logger.debugOn()) logger.debug("getMBeanInfo", "name=" + name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1079
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1080
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1081
                return connection.getMBeanInfo(name, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1082
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1083
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1085
                return connection.getMBeanInfo(name, delegationSubject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1086
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1087
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1088
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1089
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1091
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1092
        public boolean isInstanceOf(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1093
                String className)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1094
                throws InstanceNotFoundException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1095
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1096
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1097
                logger.debug("isInstanceOf", "name=" + name +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1098
                        ", className=" + className);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1099
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1100
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1101
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1102
                return connection.isInstanceOf(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1103
                        className,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1104
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1105
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1106
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1107
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1108
                return connection.isInstanceOf(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1109
                        className,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1110
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1111
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1112
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1113
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1114
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1115
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1116
        public void addNotificationListener(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1117
                ObjectName listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1118
                NotificationFilter filter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1119
                Object handback)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1120
                throws InstanceNotFoundException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1121
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1122
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1123
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1124
                logger.debug("addNotificationListener" +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1125
                        "(ObjectName,ObjectName,NotificationFilter,Object)",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1126
                        "name=" + name + ", listener=" + listener
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1127
                        + ", filter=" + filter + ", handback=" + handback);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1128
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1129
            final MarshalledObject<NotificationFilter> sFilter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1130
                    new MarshalledObject<NotificationFilter>(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1131
            final MarshalledObject<Object> sHandback =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1132
                    new MarshalledObject<Object>(handback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1133
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1134
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1135
                connection.addNotificationListener(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1136
                        listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1137
                        sFilter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1138
                        sHandback,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1139
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1140
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1141
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1142
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1143
                connection.addNotificationListener(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1144
                        listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1145
                        sFilter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1146
                        sHandback,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1147
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1148
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1149
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1150
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1152
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1153
        public void removeNotificationListener(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1154
                ObjectName listener)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1155
                throws InstanceNotFoundException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1156
                ListenerNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1157
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1158
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1159
            if (logger.debugOn()) logger.debug("removeNotificationListener" +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1160
                    "(ObjectName,ObjectName)",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1161
                    "name=" + name
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1162
                    + ", listener=" + listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1163
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1164
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1165
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1166
                connection.removeNotificationListener(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1167
                        listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1168
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1169
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1170
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1171
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1172
                connection.removeNotificationListener(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1173
                        listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1174
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1175
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1176
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1177
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1178
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1179
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1180
        public void removeNotificationListener(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1181
                ObjectName listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1182
                NotificationFilter filter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1183
                Object handback)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1184
                throws InstanceNotFoundException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1185
                ListenerNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1186
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1187
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1188
                logger.debug("removeNotificationListener" +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1189
                        "(ObjectName,ObjectName,NotificationFilter,Object)",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1190
                        "name=" + name
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1191
                        + ", listener=" + listener
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1192
                        + ", filter=" + filter
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1193
                        + ", handback=" + handback);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1194
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1195
            final MarshalledObject<NotificationFilter> sFilter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1196
                    new MarshalledObject<NotificationFilter>(filter);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1197
            final MarshalledObject<Object> sHandback =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1198
                    new MarshalledObject<Object>(handback);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1199
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1200
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1201
                connection.removeNotificationListener(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1202
                        listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1203
                        sFilter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1204
                        sHandback,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1205
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1206
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1207
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1208
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1209
                connection.removeNotificationListener(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1210
                        listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1211
                        sFilter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1212
                        sHandback,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1213
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1214
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1215
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1216
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1217
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1218
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1219
        // Specific Notification Handle ----------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1221
        public void addNotificationListener(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1222
                NotificationListener listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1223
                NotificationFilter filter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1224
                Object handback)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1225
                throws InstanceNotFoundException,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1226
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1227
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1228
            final boolean debug = logger.debugOn();
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1229
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1230
            if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1231
                logger.debug("addNotificationListener" +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1232
                        "(ObjectName,NotificationListener,"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1233
                        "NotificationFilter,Object)",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1234
                        "name=" + name
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1235
                        + ", listener=" + listener
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1236
                        + ", filter=" + filter
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1237
                        + ", handback=" + handback);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1238
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1239
            final Integer listenerID =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1240
                    addListenerWithSubject(name,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1241
                    new MarshalledObject<NotificationFilter>(filter),
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1242
                    delegationSubject,true);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1243
            rmiNotifClient.addNotificationListener(listenerID, name, listener,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1244
                    filter, handback,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1245
                    delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1246
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1247
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1248
        public void removeNotificationListener(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1249
                NotificationListener listener)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1250
                throws InstanceNotFoundException,
1004
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1251
                ListenerNotFoundException,
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1252
                IOException {
5ba8217eb504 5108776: Add reliable event handling to the JMX API
sjiang
parents: 715
diff changeset
  1253
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1254
            final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1255
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1256
            if (debug) logger.debug("removeNotificationListener"+
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1257
                    "(ObjectName,NotificationListener)",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1258
                    "name=" + name
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1259
                    + ", listener=" + listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1260
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1261
            final Integer[] ret =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1262
                    rmiNotifClient.removeNotificationListener(name, listener);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1264
            if (debug) logger.debug("removeNotificationListener",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1265
                    "listenerIDs=" + objects(ret));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1266
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1267
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1268
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1269
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1270
                connection.removeNotificationListeners(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1271
                        ret,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1272
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1273
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1274
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1275
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1276
                connection.removeNotificationListeners(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1277
                        ret,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1278
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1279
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1280
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1281
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1282
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1283
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1284
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1285
        public void removeNotificationListener(ObjectName name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1286
                NotificationListener listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1287
                NotificationFilter filter,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1288
                Object handback)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1289
                throws InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1290
                ListenerNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1291
                IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1292
            final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1293
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1294
            if (debug)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1295
                logger.debug("removeNotificationListener"+
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1296
                        "(ObjectName,NotificationListener,"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1297
                        "NotificationFilter,Object)",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1298
                        "name=" + name
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1299
                        + ", listener=" + listener
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1300
                        + ", filter=" + filter
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1301
                        + ", handback=" + handback);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1302
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1303
            final Integer ret =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1304
                    rmiNotifClient.removeNotificationListener(name, listener,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1305
                    filter, handback);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1306
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1307
            if (debug) logger.debug("removeNotificationListener",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1308
                    "listenerID=" + ret);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1309
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1310
            final ClassLoader old = pushDefaultClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1311
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1312
                connection.removeNotificationListeners(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1313
                        new Integer[] {ret},
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1314
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1315
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1316
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1317
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1318
                connection.removeNotificationListeners(name,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1319
                        new Integer[] {ret},
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1320
                        delegationSubject);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1321
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1322
                popDefaultClassLoader(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1323
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1324
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1325
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1326
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1327
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1328
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1329
    private class RMINotifClient extends ClientNotifForwarder {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  1330
        public RMINotifClient(ClassLoader cl, Map<String, ?> env) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1331
            super(cl, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1333
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1334
        protected NotificationResult fetchNotifs(long clientSequenceNumber,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1335
                int maxNotifications,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1336
                long timeout)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1337
                throws IOException, ClassNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1338
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1339
            boolean retried = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1340
            while (true) { // used for a successful re-connection
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1341
                           // or a transient network problem
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1342
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1343
                    return connection.fetchNotifications(clientSequenceNumber,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1344
                            maxNotifications,
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1345
                            timeout); // return normally
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1346
                } catch (IOException ioe) {
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1347
                    // Examine the chain of exceptions to determine whether this
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1348
                    // is a deserialization issue. If so - we propagate the
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1349
                    // appropriate exception to the caller, who will then
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1350
                    // proceed with fetching notifications one by one
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1351
                    rethrowDeserializationException(ioe);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1352
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1353
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1354
                        communicatorAdmin.gotIOException(ioe);
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1355
                        // reconnection OK, back to "while" to do again
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1356
                    } catch (IOException ee) {
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1357
                        boolean toClose = false;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1358
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1359
                        synchronized (this) {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1360
                            if (terminated) {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1361
                                // the connection is closed.
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1362
                                throw ioe;
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1363
                            } else if (retried) {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1364
                                toClose = true;
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1365
                            }
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1366
                        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1367
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1368
                        if (toClose) {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1369
                            // JDK-8049303
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1370
                            // We received an IOException - but the communicatorAdmin
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1371
                            // did not close the connection - possibly because
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1372
                            // the original exception was raised by a transient network
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1373
                            // problem?
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1374
                            // We already know that this exception is not due to a deserialization
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1375
                            // issue as we already took care of that before involving the
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1376
                            // communicatorAdmin. Moreover - we already made one retry attempt
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1377
                            // at fetching the same batch of notifications - and the
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1378
                            // problem persisted.
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1379
                            // Since trying again doesn't seem to solve the issue, we will now
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1380
                            // close the connection. Doing otherwise might cause the
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1381
                            // NotifFetcher thread to die silently.
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1382
                            final Notification failedNotif =
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1383
                                    new JMXConnectionNotification(
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1384
                                    JMXConnectionNotification.FAILED,
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1385
                                    this,
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1386
                                    connectionId,
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1387
                                    clientNotifSeqNo++,
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1388
                                    "Failed to communicate with the server: " + ioe.toString(),
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1389
                                    ioe);
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1390
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1391
                            sendNotification(failedNotif);
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1392
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1393
                            try {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1394
                                close(true);
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1395
                            } catch (Exception e) {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1396
                                // OK.
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1397
                                // We are closing
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1398
                            }
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1399
                            throw ioe; // the connection is closed here.
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1400
                        } else {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1401
                            // JDK-8049303 possible transient network problem,
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1402
                            // let's try one more time
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1403
                            retried = true;
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1404
                        }
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1405
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1406
                }
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1407
            }
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1408
        }
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1409
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1410
        private void rethrowDeserializationException(IOException ioe)
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1411
                throws ClassNotFoundException, IOException {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1412
            // specially treating for an UnmarshalException
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1413
            if (ioe instanceof UnmarshalException) {
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1414
                throw ioe; // the fix of 6937053 made ClientNotifForwarder.fetchNotifs
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1415
                           // fetch one by one with UnmarshalException
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1416
            } else if (ioe instanceof MarshalException) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1417
                // IIOP will throw MarshalException wrapping a NotSerializableException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1418
                // when a server fails to serialize a response.
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1419
                MarshalException me = (MarshalException)ioe;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1420
                if (me.detail instanceof NotSerializableException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1421
                    throw (NotSerializableException)me.detail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1422
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1423
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1424
26594
b561a19107c7 8049303: Transient network problems cause JMX thread to fail silenty
sjiang
parents: 25859
diff changeset
  1425
            // Not serialization problem, return.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1426
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1427
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1428
        protected Integer addListenerForMBeanRemovedNotif()
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1429
        throws IOException, InstanceNotFoundException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1430
            NotificationFilterSupport clientFilter =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1431
                    new NotificationFilterSupport();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1432
            clientFilter.enableType(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1433
                    MBeanServerNotification.UNREGISTRATION_NOTIFICATION);
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1434
            MarshalledObject<NotificationFilter> sFilter =
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1435
                new MarshalledObject<NotificationFilter>(clientFilter);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1436
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1437
            Integer[] listenerIDs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1438
            final ObjectName[] names =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1439
                new ObjectName[] {MBeanServerDelegate.DELEGATE_NAME};
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  1440
            final MarshalledObject<NotificationFilter>[] filters =
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  1441
                Util.cast(new MarshalledObject<?>[] {sFilter});
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1442
            final Subject[] subjects = new Subject[] {null};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1443
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1444
                listenerIDs =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1445
                        connection.addNotificationListeners(names,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1446
                        filters,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1447
                        subjects);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1448
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1449
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1450
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1451
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1452
                listenerIDs =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1453
                        connection.addNotificationListeners(names,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1454
                        filters,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1455
                        subjects);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1456
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1457
            return listenerIDs[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1458
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1459
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1460
        protected void removeListenerForMBeanRemovedNotif(Integer id)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1461
        throws IOException, InstanceNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1462
                ListenerNotFoundException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1463
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1464
                connection.removeNotificationListeners(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1465
                        MBeanServerDelegate.DELEGATE_NAME,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1466
                        new Integer[] {id},
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1467
                        null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1468
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1469
                communicatorAdmin.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1470
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1471
                connection.removeNotificationListeners(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1472
                        MBeanServerDelegate.DELEGATE_NAME,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1473
                        new Integer[] {id},
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1474
                        null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1475
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1476
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1477
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1478
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1479
        protected void lostNotifs(String message, long number) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1480
            final String notifType = JMXConnectionNotification.NOTIFS_LOST;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1481
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1482
            final JMXConnectionNotification n =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1483
                new JMXConnectionNotification(notifType,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1484
                                              RMIConnector.this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1485
                                              connectionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1486
                                              clientNotifCounter++,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1487
                                              message,
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1488
                                              Long.valueOf(number));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1489
            sendNotification(n);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1490
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1492
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1493
    private class RMIClientCommunicatorAdmin extends ClientCommunicatorAdmin {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1494
        public RMIClientCommunicatorAdmin(long period) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1495
            super(period);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1496
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1497
4156
acaa49a2768a 6851617: Remove JSR 255 (JMX API 2.0) from JDK 7
emcmanus
parents: 1570
diff changeset
  1498
        @Override
1446
605e30465515 6757225: MXBean: Incorrect type names for parametrized types, dealing with arrays
emcmanus
parents: 1229
diff changeset
  1499
        public void gotIOException(IOException ioe) throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1500
            if (ioe instanceof NoSuchObjectException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1501
                // need to restart
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1502
                super.gotIOException(ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1503
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1504
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1505
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1506
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1507
            // check if the connection is broken
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1508
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1509
                connection.getDefaultDomain(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1510
            } catch (IOException ioexc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1511
                boolean toClose = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1512
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1513
                synchronized(this) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1514
                    if (!terminated) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1515
                        terminated = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1516
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1517
                        toClose = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1518
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1519
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1521
                if (toClose) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1522
                    // we should close the connection,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1523
                    // but send a failed notif at first
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1524
                    final Notification failedNotif =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1525
                            new JMXConnectionNotification(
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1526
                            JMXConnectionNotification.FAILED,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1527
                            this,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1528
                            connectionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1529
                            clientNotifSeqNo++,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1530
                            "Failed to communicate with the server: "+ioe.toString(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1531
                            ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1532
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1533
                    sendNotification(failedNotif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1534
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1535
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1536
                        close(true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1537
                    } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1538
                        // OK.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1539
                        // We are closing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1540
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1541
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1542
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1543
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1544
            // forward the exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1545
            if (ioe instanceof ServerException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1546
                /* Need to unwrap the exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1547
                   Some user-thrown exception at server side will be wrapped by
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1548
                   rmi into a ServerException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1549
                   For example, a RMIConnnectorServer will wrap a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1550
                   ClassNotFoundException into a UnmarshalException, and rmi
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1551
                   will throw a ServerException at client side which wraps this
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1552
                   UnmarshalException.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1553
                   No failed notif here.
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1554
                 */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1555
                Throwable tt = ((ServerException)ioe).detail;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1556
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1557
                if (tt instanceof IOException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1558
                    throw (IOException)tt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1559
                } else if (tt instanceof RuntimeException) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1560
                    throw (RuntimeException)tt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1561
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1562
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1563
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1564
            throw ioe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1565
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1566
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1567
        public void reconnectNotificationListeners(ClientListenerInfo[] old) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1568
            final int len  = old.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1569
            int i;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1570
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1571
            ClientListenerInfo[] clis = new ClientListenerInfo[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1572
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1573
            final Subject[] subjects = new Subject[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1574
            final ObjectName[] names = new ObjectName[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1575
            final NotificationListener[] listeners = new NotificationListener[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1576
            final NotificationFilter[] filters = new NotificationFilter[len];
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  1577
            final MarshalledObject<NotificationFilter>[] mFilters =
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  1578
                    Util.cast(new MarshalledObject<?>[len]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1579
            final Object[] handbacks = new Object[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1580
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1581
            for (i=0;i<len;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1582
                subjects[i]  = old[i].getDelegationSubject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1583
                names[i]     = old[i].getObjectName();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1584
                listeners[i] = old[i].getListener();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1585
                filters[i]   = old[i].getNotificationFilter();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1586
                mFilters[i]  = new MarshalledObject<NotificationFilter>(filters[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1587
                handbacks[i] = old[i].getHandback();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1588
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1590
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1591
                Integer[] ids = addListenersWithSubjects(names,mFilters,subjects,false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1592
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1593
                for (i=0;i<len;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1594
                    clis[i] = new ClientListenerInfo(ids[i],
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1595
                            names[i],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1596
                            listeners[i],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1597
                            filters[i],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1598
                            handbacks[i],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1599
                            subjects[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1600
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1601
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1602
                rmiNotifClient.postReconnection(clis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1603
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1604
                return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1605
            } catch (InstanceNotFoundException infe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1606
                // OK, we will do one by one
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1607
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1608
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1609
            int j = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1610
            for (i=0;i<len;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1611
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1612
                    Integer id = addListenerWithSubject(names[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1613
                            new MarshalledObject<NotificationFilter>(filters[i]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1614
                            subjects[i],
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1615
                            false);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1617
                    clis[j++] = new ClientListenerInfo(id,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1618
                            names[i],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1619
                            listeners[i],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1620
                            filters[i],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1621
                            handbacks[i],
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1622
                            subjects[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1623
                } catch (InstanceNotFoundException infe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1624
                    logger.warning("reconnectNotificationListeners",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1625
                            "Can't reconnect listener for " +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1626
                            names[i]);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1627
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1628
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1629
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1630
            if (j != len) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1631
                ClientListenerInfo[] tmp = clis;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1632
                clis = new ClientListenerInfo[j];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1633
                System.arraycopy(tmp, 0, clis, 0, j);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1634
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1636
            rmiNotifClient.postReconnection(clis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1637
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1638
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1639
        protected void checkConnection() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1640
            if (logger.debugOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1641
                logger.debug("RMIClientCommunicatorAdmin-checkConnection",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1642
                        "Calling the method getDefaultDomain.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1643
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1644
            connection.getDefaultDomain(null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1645
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1646
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1647
        protected void doStart() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1648
            // Get RMIServer stub from directory or URL encoding if needed.
526
61ba2d5ea9da 6701459: Synchronization bug pattern found in javax.management.relation.RelationService
emcmanus
parents: 2
diff changeset
  1649
            RMIServer stub;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1650
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1651
                stub = (rmiServer!=null)?rmiServer:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1652
                    findRMIServer(jmxServiceURL, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1653
            } catch (NamingException ne) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1654
                throw new IOException("Failed to get a RMI stub: "+ne);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1655
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1656
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1657
            // Connect IIOP Stub if needed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1658
            stub = connectStub(stub,env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1659
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1660
            // Calling newClient on the RMIServer stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1661
            Object credentials = env.get(CREDENTIALS);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1662
            connection = stub.newClient(credentials);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1663
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1664
            // notif issues
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1665
            final ClientListenerInfo[] old = rmiNotifClient.preReconnection();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1666
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1667
            reconnectNotificationListeners(old);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1668
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1669
            connectionId = getConnectionId();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1670
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1671
            Notification reconnectedNotif =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1672
                    new JMXConnectionNotification(JMXConnectionNotification.OPENED,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1673
                    this,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1674
                    connectionId,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1675
                    clientNotifSeqNo++,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1676
                    "Reconnected to server",
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1677
                    null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1678
            sendNotification(reconnectedNotif);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1679
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1680
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1681
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1682
        protected void doStop() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1683
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1684
                close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1685
            } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1686
                logger.warning("RMIClientCommunicatorAdmin-doStop",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1687
                        "Failed to call the method close():" + ioe);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1688
                logger.debug("RMIClientCommunicatorAdmin-doStop",ioe);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1689
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1690
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1691
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1692
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1693
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1694
    // Private stuff - Serialization
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1695
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1696
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1697
     * <p>In order to be usable, an IIOP stub must be connected to an ORB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1698
     * The stub is automatically connected to the ORB if:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1699
     * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1700
     *     <li> It was returned by the COS naming</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1701
     *     <li> Its server counterpart has been registered in COS naming
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1702
     *          through JNDI.</li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1703
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1704
     * Otherwise, it is not connected. A stub which is deserialized
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1705
     * from Jini is not connected. A stub which is obtained from a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1706
     * non registered RMIIIOPServerImpl is not a connected.<br>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1707
     * A stub which is not connected can't be serialized, and thus
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1708
     * can't be registered in Jini. A stub which is not connected can't
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1709
     * be used to invoke methods on the server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1710
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1711
     * In order to palliate this, this method will connect the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1712
     * given stub if it is not yet connected. If the given
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1713
     * <var>RMIServer</var> is not an instance of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1714
     * {@link javax.rmi.CORBA.Stub javax.rmi.CORBA.Stub}, then the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1715
     * method do nothing and simply returns that stub. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1716
     * this method will attempt to connect the stub to an ORB as
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1717
     * follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1718
     * <ul>
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 20851
diff changeset
  1719
     * <li>This method looks in the provided <var>environment</var> for
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1720
     * the "java.naming.corba.orb" property. If it is found, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1721
     * referenced object (an {@link org.omg.CORBA.ORB ORB}) is used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1722
     * connect the stub. Otherwise, a new org.omg.CORBA.ORB is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1723
     * by calling {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1724
     * org.omg.CORBA.ORB#init(String[], Properties)
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 20851
diff changeset
  1725
     * org.omg.CORBA.ORB.init((String[])null,(Properties)null)}</li>
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 20851
diff changeset
  1726
     * <li>The new created ORB is kept in a static
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1727
     * {@link WeakReference} and can be reused for connecting other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1728
     * stubs. However, no reference is ever kept on the ORB provided
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 20851
diff changeset
  1729
     * in the <var>environment</var> map, if any.</li>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1730
     * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1731
     * @param rmiServer A RMI Server Stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1732
     * @param environment An environment map, possibly containing an ORB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1733
     * @return the given stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1734
     * @exception IllegalArgumentException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1735
     *      <tt>java.naming.corba.orb</tt> property is specified and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1736
     *      does not point to an {@link org.omg.CORBA.ORB ORB}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1737
     * @exception IOException if the connection to the ORB failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1738
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1739
    static RMIServer connectStub(RMIServer rmiServer,
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  1740
                                 Map<String, ?> environment)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1741
        throws IOException {
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1742
        if (IIOPHelper.isStub(rmiServer)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1743
            try {
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1744
                IIOPHelper.getOrb(rmiServer);
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1745
            } catch (UnsupportedOperationException x) {
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1746
                // BAD_OPERATION
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1747
                IIOPHelper.connect(rmiServer, resolveOrb(environment));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1748
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1749
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1750
        return rmiServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1751
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1752
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1753
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1754
     * Get the ORB specified by <var>environment</var>, or create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1755
     * new one.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1756
     * <p>This method looks in the provided <var>environment</var> for
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1757
     * the "java.naming.corba.orb" property. If it is found, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1758
     * referenced object (an {@link org.omg.CORBA.ORB ORB}) is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1759
     * returned. Otherwise, a new org.omg.CORBA.ORB is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1760
     * by calling {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1761
     * org.omg.CORBA.ORB#init(String[], java.util.Properties)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1762
     * org.omg.CORBA.ORB.init((String[])null,(Properties)null)}
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1763
     * <p>The new created ORB is kept in a static
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1764
     * {@link WeakReference} and can be reused for connecting other
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1765
     * stubs. However, no reference is ever kept on the ORB provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1766
     * in the <var>environment</var> map, if any.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1767
     * @param environment An environment map, possibly containing an ORB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1768
     * @return An ORB.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1769
     * @exception IllegalArgumentException if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1770
     *      <tt>java.naming.corba.orb</tt> property is specified and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1771
     *      does not point to an {@link org.omg.CORBA.ORB ORB}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1772
     * @exception IOException if the ORB initialization failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1773
     **/
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1774
    static Object resolveOrb(Map<String, ?> environment)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1775
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1776
        if (environment != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1777
            final Object orb = environment.get(EnvHelp.DEFAULT_ORB);
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1778
            if (orb != null && !(IIOPHelper.isOrb(orb)))
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1779
                throw new IllegalArgumentException(EnvHelp.DEFAULT_ORB +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1780
                        " must be an instance of org.omg.CORBA.ORB.");
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1781
            if (orb != null) return orb;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1782
        }
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1783
        final Object orb =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1784
                (RMIConnector.orb==null)?null:RMIConnector.orb.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1785
        if (orb != null) return orb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1786
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1787
        final Object newOrb =
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1788
                IIOPHelper.createOrb((String[])null, (Properties)null);
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1789
        RMIConnector.orb = new WeakReference<Object>(newOrb);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1790
        return newOrb;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1791
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1792
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1793
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1794
     * Read RMIConnector fields from an {@link java.io.ObjectInputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1795
     * ObjectInputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1796
     * Calls <code>s.defaultReadObject()</code> and then initializes
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1797
     * all transient variables that need initializing.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1798
     * @param s The ObjectInputStream to read from.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1799
     * @exception InvalidObjectException if none of <var>rmiServer</var> stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1800
     *    or <var>jmxServiceURL</var> are set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1801
     * @see #RMIConnector(JMXServiceURL,Map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1802
     * @see #RMIConnector(RMIServer,Map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1803
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1804
    private void readObject(java.io.ObjectInputStream s)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1805
    throws IOException, ClassNotFoundException  {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1806
        s.defaultReadObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1807
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1808
        if (rmiServer == null && jmxServiceURL == null) throw new
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1809
                InvalidObjectException("rmiServer and jmxServiceURL both null");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1810
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1811
        initTransients();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1812
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1813
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1814
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1815
     * Writes the RMIConnector fields to an {@link java.io.ObjectOutputStream
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1816
     * ObjectOutputStream}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1817
     * <p>Connects the underlying RMIServer stub to an ORB, if needed,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1818
     * before serializing it. This is done using the environment
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1819
     * map that was provided to the constructor, if any, and as documented
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1820
     * in {@link javax.management.remote.rmi}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1821
     * <p>This method then calls <code>s.defaultWriteObject()</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1822
     * Usually, <var>rmiServer</var> is null if this object
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1823
     * was constructed with a JMXServiceURL, and <var>jmxServiceURL</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1824
     * is null if this object is constructed with a RMIServer stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1825
     * <p>Note that the environment Map is not serialized, since the objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1826
     * it contains are assumed to be contextual and relevant only
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1827
     * with respect to the local environment (class loader, ORB, etc...).</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1828
     * <p>After an RMIConnector is deserialized, it is assumed that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1829
     * user will call {@link #connect(Map)}, providing a new Map that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1830
     * can contain values which are contextually relevant to the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1831
     * local environment.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1832
     * <p>Since connection to the ORB is needed prior to serializing, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1833
     * since the ORB to connect to is one of those contextual parameters,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1834
     * it is not recommended to re-serialize a just de-serialized object -
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1835
     * as the de-serialized object has no map. Thus, when an RMIConnector
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1836
     * object is needed for serialization or transmission to a remote
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1837
     * application, it is recommended to obtain a new RMIConnector stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1838
     * by calling {@link RMIConnectorServer#toJMXConnector(Map)}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1839
     * @param s The ObjectOutputStream to write to.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1840
     * @exception InvalidObjectException if none of <var>rmiServer</var> stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1841
     *    or <var>jmxServiceURL</var> are set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1842
     * @see #RMIConnector(JMXServiceURL,Map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1843
     * @see #RMIConnector(RMIServer,Map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1844
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1845
    private void writeObject(java.io.ObjectOutputStream s)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1846
    throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1847
        if (rmiServer == null && jmxServiceURL == null) throw new
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1848
                InvalidObjectException("rmiServer and jmxServiceURL both null.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1849
        connectStub(this.rmiServer,env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1850
        s.defaultWriteObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1851
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1852
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1853
    // Initialization of transient variables.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1854
    private void initTransients() {
19791
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  1855
        rmbscMap = new WeakHashMap<Subject, WeakReference<MBeanServerConnection>>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1856
        connected = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1857
        terminated = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1858
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1859
        connectionBroadcaster = new NotificationBroadcasterSupport();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1860
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1861
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1862
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1863
    // Private stuff - Check if stub can be trusted.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1864
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1865
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1866
    private static void checkStub(Remote stub,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1867
            Class<?> stubClass) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1868
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1869
        // Check remote stub is from the expected class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1870
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1871
        if (stub.getClass() != stubClass) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1872
            if (!Proxy.isProxyClass(stub.getClass())) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1873
                throw new SecurityException(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1874
                        "Expecting a " + stubClass.getName() + " stub!");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1875
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1876
                InvocationHandler handler = Proxy.getInvocationHandler(stub);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1877
                if (handler.getClass() != RemoteObjectInvocationHandler.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1878
                    throw new SecurityException(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1879
                            "Expecting a dynamic proxy instance with a " +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1880
                            RemoteObjectInvocationHandler.class.getName() +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1881
                            " invocation handler!");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1882
                else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1883
                    stub = (Remote) handler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1884
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1885
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1886
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1887
        // Check RemoteRef in stub is from the expected class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1888
        // "sun.rmi.server.UnicastRef2".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1889
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1890
        RemoteRef ref = ((RemoteObject)stub).getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1891
        if (ref.getClass() != UnicastRef2.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1892
            throw new SecurityException(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1893
                    "Expecting a " + UnicastRef2.class.getName() +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1894
                    " remote reference in stub!");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1895
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1896
        // Check RMIClientSocketFactory in stub is from the expected class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1897
        // "javax.rmi.ssl.SslRMIClientSocketFactory".
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1898
        //
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1899
        LiveRef liveRef = ((UnicastRef2)ref).getLiveRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1900
        RMIClientSocketFactory csf = liveRef.getClientSocketFactory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1901
        if (csf == null || csf.getClass() != SslRMIClientSocketFactory.class)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1902
            throw new SecurityException(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1903
                    "Expecting a " + SslRMIClientSocketFactory.class.getName() +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1904
                    " RMI client socket factory in stub!");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1905
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1906
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1907
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1908
    // Private stuff - RMIServer creation
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1909
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1910
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1911
    private RMIServer findRMIServer(JMXServiceURL directoryURL,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1912
            Map<String, Object> environment)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1913
            throws NamingException, IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1914
        final boolean isIiop = RMIConnectorServer.isIiopURL(directoryURL,true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1915
        if (isIiop) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1916
            // Make sure java.naming.corba.orb is in the Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1917
            environment.put(EnvHelp.DEFAULT_ORB,resolveOrb(environment));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1918
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1919
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1920
        String path = directoryURL.getURLPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1921
        int end = path.indexOf(';');
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1922
        if (end < 0) end = path.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1923
        if (path.startsWith("/jndi/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1924
            return findRMIServerJNDI(path.substring(6,end), environment, isIiop);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1925
        else if (path.startsWith("/stub/"))
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1926
            return findRMIServerJRMP(path.substring(6,end), environment, isIiop);
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1927
        else if (path.startsWith("/ior/")) {
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1928
            if (!IIOPHelper.isAvailable())
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1929
                throw new IOException("iiop protocol not available");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1930
            return findRMIServerIIOP(path.substring(5,end), environment, isIiop);
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1931
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1932
            final String msg = "URL path must begin with /jndi/ or /stub/ " +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1933
                    "or /ior/: " + path;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1934
            throw new MalformedURLException(msg);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1935
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1936
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1937
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1938
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1939
     * Lookup the RMIServer stub in a directory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1940
     * @param jndiURL A JNDI URL indicating the location of the Stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1941
     *                (see {@link javax.management.remote.rmi}), e.g.:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1942
     *   <ul><li><tt>rmi://registry-host:port/rmi-stub-name</tt></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1943
     *       <li>or <tt>iiop://cosnaming-host:port/iiop-stub-name</tt></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1944
     *       <li>or <tt>ldap://ldap-host:port/java-container-dn</tt></li>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1945
     *   </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1946
     * @param env the environment Map passed to the connector.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1947
     * @param isIiop true if the stub is expected to be an IIOP stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1948
     * @return The retrieved RMIServer stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1949
     * @exception NamingException if the stub couldn't be found.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1950
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1951
    private RMIServer findRMIServerJNDI(String jndiURL, Map<String, ?> env,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1952
            boolean isIiop)
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1953
            throws NamingException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1954
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1955
        InitialContext ctx = new InitialContext(EnvHelp.mapToHashtable(env));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1956
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1957
        Object objref = ctx.lookup(jndiURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1958
        ctx.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1959
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1960
        if (isIiop)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1961
            return narrowIIOPServer(objref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1962
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1963
            return narrowJRMPServer(objref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1964
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1965
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1966
    private static RMIServer narrowJRMPServer(Object objref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1967
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1968
        return (RMIServer) objref;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1969
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1970
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1971
    private static RMIServer narrowIIOPServer(Object objref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1972
        try {
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1973
            return IIOPHelper.narrow(objref, RMIServer.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1974
        } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1975
            if (logger.traceOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1976
                logger.trace("narrowIIOPServer","Failed to narrow objref=" +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1977
                        objref + ": " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1978
            if (logger.debugOn()) logger.debug("narrowIIOPServer",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1979
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1980
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1981
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1982
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  1983
    private RMIServer findRMIServerIIOP(String ior, Map<String, ?> env, boolean isIiop) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1984
        // could forbid "rmi:" URL here -- but do we need to?
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1985
        final Object orb = env.get(EnvHelp.DEFAULT_ORB);
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1986
        final Object stub = IIOPHelper.stringToObject(orb, ior);
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  1987
        return IIOPHelper.narrow(stub, RMIServer.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1988
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1989
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  1990
    private RMIServer findRMIServerJRMP(String base64, Map<String, ?> env, boolean isIiop)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1991
        throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1992
        // could forbid "iiop:" URL here -- but do we need to?
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1993
        final byte[] serialized;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1994
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1995
            serialized = base64ToByteArray(base64);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1996
        } catch (IllegalArgumentException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1997
            throw new MalformedURLException("Bad BASE64 encoding: " +
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  1998
                    e.getMessage());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1999
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2000
        final ByteArrayInputStream bin = new ByteArrayInputStream(serialized);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2001
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2002
        final ClassLoader loader = EnvHelp.resolveClientClassLoader(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2003
        final ObjectInputStream oin =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2004
                (loader == null) ?
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2005
                    new ObjectInputStream(bin) :
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2006
                    new ObjectInputStreamWithLoader(bin, loader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2007
        final Object stub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2008
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2009
            stub = oin.readObject();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2010
        } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2011
            throw new MalformedURLException("Class not found: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2012
        }
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2013
        return (RMIServer)stub;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2014
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2015
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2016
    private static final class ObjectInputStreamWithLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2017
            extends ObjectInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2018
        ObjectInputStreamWithLoader(InputStream in, ClassLoader cl)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2019
        throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2020
            super(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2021
            this.loader = cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2022
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2023
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2024
        @Override
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2025
        protected Class<?> resolveClass(ObjectStreamClass classDesc)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2026
                throws IOException, ClassNotFoundException {
18206
136373d8d805 8008615: Improve robustness of JMX internal APIs
sjiang
parents: 14917
diff changeset
  2027
            String name = classDesc.getName();
136373d8d805 8008615: Improve robustness of JMX internal APIs
sjiang
parents: 14917
diff changeset
  2028
            ReflectUtil.checkPackageAccess(name);
136373d8d805 8008615: Improve robustness of JMX internal APIs
sjiang
parents: 14917
diff changeset
  2029
            return Class.forName(name, false, loader);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2030
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2031
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2032
        private final ClassLoader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2033
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2034
19791
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2035
    private MBeanServerConnection getConnectionWithSubject(Subject delegationSubject) {
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2036
        MBeanServerConnection conn = null;
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2037
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2038
        if (delegationSubject == null) {
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2039
            if (nullSubjectConnRef == null
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2040
                    || (conn = nullSubjectConnRef.get()) == null) {
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2041
                conn = new RemoteMBeanServerConnection(null);
24871
224e298c3978 8044865: Fix raw and unchecked lint warnings in management-related code
sjiang
parents: 21656
diff changeset
  2042
                nullSubjectConnRef = new WeakReference<MBeanServerConnection>(conn);
19791
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2043
            }
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2044
        } else {
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2045
            WeakReference<MBeanServerConnection> wr = rmbscMap.get(delegationSubject);
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2046
            if (wr == null || (conn = wr.get()) == null) {
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2047
                conn = new RemoteMBeanServerConnection(delegationSubject);
24871
224e298c3978 8044865: Fix raw and unchecked lint warnings in management-related code
sjiang
parents: 21656
diff changeset
  2048
                rmbscMap.put(delegationSubject, new WeakReference<MBeanServerConnection>(conn));
19791
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2049
            }
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2050
        }
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2051
        return conn;
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2052
    }
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2053
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2054
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2055
       The following section of code avoids a class loading problem
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2056
       with RMI.  The problem is that an RMI stub, when deserializing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2057
       a remote method return value or exception, will first of all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2058
       consult the first non-bootstrap class loader it finds in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2059
       call stack.  This can lead to behavior that is not portable
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2060
       between implementations of the JMX Remote API.  Notably, an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2061
       implementation on J2SE 1.4 will find the RMI stub's loader on
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2062
       the stack.  But in J2SE 5, this stub is loaded by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2063
       bootstrap loader, so RMI will find the loader of the user code
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2064
       that called an MBeanServerConnection method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2065
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2066
       To avoid this problem, we take advantage of what the RMI stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2067
       is doing internally.  Each remote call will end up calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2068
       ref.invoke(...), where ref is the RemoteRef parameter given to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2069
       the RMI stub's constructor.  It is within this call that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2070
       deserialization will happen.  So we fabricate our own RemoteRef
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2071
       that delegates everything to the "real" one but that is loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2072
       by a class loader that knows no other classes.  The class
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2073
       loader NoCallStackClassLoader does this: the RemoteRef is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2074
       instance of the class named by proxyRefClassName, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2075
       fabricated by the class loader using byte code that is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2076
       by the string below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2077
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2078
       The call stack when the deserialization happens is thus this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2079
       MBeanServerConnection.getAttribute (or whatever)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2080
       -> RMIConnectionImpl_Stub.getAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2081
          -> ProxyRef.invoke(...getAttribute...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2082
             -> UnicastRef.invoke(...getAttribute...)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2083
                -> internal RMI stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2084
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2085
       Here UnicastRef is the RemoteRef created when the stub was
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2086
       deserialized (which is of some RMI internal class).  It and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2087
       "internal RMI stuff" are loaded by the bootstrap loader, so are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2088
       transparent to the stack search.  The first non-bootstrap
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2089
       loader found is our ProxyRefLoader, as required.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2090
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2091
       In a future version of this code as integrated into J2SE 5,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2092
       this workaround could be replaced by direct access to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2093
       internals of RMI.  For now, we use the same code base for J2SE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2094
       and for the standalone Reference Implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2095
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2096
       The byte code below encodes the following class, compiled using
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2097
       J2SE 1.4.2 with the -g:none option.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2098
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2099
        package com.sun.jmx.remote.internal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2100
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2101
        import java.lang.reflect.Method;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2102
        import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2103
        import java.rmi.server.RemoteRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2104
        import com.sun.jmx.remote.internal.ProxyRef;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2105
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2106
        public class PRef extends ProxyRef {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2107
            public PRef(RemoteRef ref) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2108
                super(ref);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2109
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2110
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2111
            public Object invoke(Remote obj, Method method,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2112
                                 Object[] params, long opnum)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2113
                    throws Exception {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2114
                return ref.invoke(obj, method, params, opnum);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2115
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2116
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2117
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2118
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2119
    private static final String rmiServerImplStubClassName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2120
        RMIServer.class.getName() + "Impl_Stub";
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2121
    private static final Class<?> rmiServerImplStubClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2122
    private static final String rmiConnectionImplStubClassName =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2123
            RMIConnection.class.getName() + "Impl_Stub";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2124
    private static final Class<?> rmiConnectionImplStubClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2125
    private static final String pRefClassName =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2126
        "com.sun.jmx.remote.internal.PRef";
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2127
    private static final Constructor<?> proxyRefConstructor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2128
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2129
        final String pRefByteCodeString =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2130
                "\312\376\272\276\0\0\0.\0\27\12\0\5\0\15\11\0\4\0\16\13\0\17\0"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2131
                "\20\7\0\21\7\0\22\1\0\6<init>\1\0\36(Ljava/rmi/server/RemoteRef;"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2132
                ")V\1\0\4Code\1\0\6invoke\1\0S(Ljava/rmi/Remote;Ljava/lang/reflec"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2133
                "t/Method;[Ljava/lang/Object;J)Ljava/lang/Object;\1\0\12Exception"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2134
                "s\7\0\23\14\0\6\0\7\14\0\24\0\25\7\0\26\14\0\11\0\12\1\0\40com/"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2135
                "sun/jmx/remote/internal/PRef\1\0$com/sun/jmx/remote/internal/Pr"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2136
                "oxyRef\1\0\23java/lang/Exception\1\0\3ref\1\0\33Ljava/rmi/serve"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2137
                "r/RemoteRef;\1\0\31java/rmi/server/RemoteRef\0!\0\4\0\5\0\0\0\0"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2138
                "\0\2\0\1\0\6\0\7\0\1\0\10\0\0\0\22\0\2\0\2\0\0\0\6*+\267\0\1\261"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2139
                "\0\0\0\0\0\1\0\11\0\12\0\2\0\10\0\0\0\33\0\6\0\6\0\0\0\17*\264\0"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2140
                "\2+,-\26\4\271\0\3\6\0\260\0\0\0\0\0\13\0\0\0\4\0\1\0\14\0\0";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2141
        final byte[] pRefByteCode =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2142
                NoCallStackClassLoader.stringToBytes(pRefByteCodeString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2143
        PrivilegedExceptionAction<Constructor<?>> action =
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2144
                new PrivilegedExceptionAction<Constructor<?>>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2145
            public Constructor<?> run() throws Exception {
24871
224e298c3978 8044865: Fix raw and unchecked lint warnings in management-related code
sjiang
parents: 21656
diff changeset
  2146
                Class<RMIConnector> thisClass = RMIConnector.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2147
                ClassLoader thisLoader = thisClass.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2148
                ProtectionDomain thisProtectionDomain =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2149
                        thisClass.getProtectionDomain();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2150
                String[] otherClassNames = {ProxyRef.class.getName()};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2151
                ClassLoader cl =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2152
                        new NoCallStackClassLoader(pRefClassName,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2153
                        pRefByteCode,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2154
                        otherClassNames,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2155
                        thisLoader,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2156
                        thisProtectionDomain);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2157
                Class<?> c = cl.loadClass(pRefClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2158
                return c.getConstructor(RemoteRef.class);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2159
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2160
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2161
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2162
        Class<?> serverStubClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2163
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2164
            serverStubClass = Class.forName(rmiServerImplStubClassName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2165
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2166
            logger.error("<clinit>",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2167
                    "Failed to instantiate " +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2168
                    rmiServerImplStubClassName + ": " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2169
            logger.debug("<clinit>",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2170
            serverStubClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2172
        rmiServerImplStubClass = serverStubClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2173
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2174
        Class<?> stubClass;
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2175
        Constructor<?> constr;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2176
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2177
            stubClass = Class.forName(rmiConnectionImplStubClassName);
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2178
            constr = (Constructor<?>) AccessController.doPrivileged(action);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2179
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2180
            logger.error("<clinit>",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2181
                    "Failed to initialize proxy reference constructor "+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2182
                    "for " + rmiConnectionImplStubClassName + ": " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2183
            logger.debug("<clinit>",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2184
            stubClass = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2185
            constr = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2186
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2187
        rmiConnectionImplStubClass = stubClass;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2188
        proxyRefConstructor = constr;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2189
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2190
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2191
    private static RMIConnection shadowJrmpStub(RemoteObject stub)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2192
    throws InstantiationException, IllegalAccessException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2193
            InvocationTargetException, ClassNotFoundException,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2194
            NoSuchMethodException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2195
        RemoteRef ref = stub.getRef();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2196
        RemoteRef proxyRef = (RemoteRef)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2197
            proxyRefConstructor.newInstance(new Object[] {ref});
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2198
        final Constructor<?> rmiConnectionImplStubConstructor =
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2199
            rmiConnectionImplStubClass.getConstructor(RemoteRef.class);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2200
        Object[] args = {proxyRef};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2201
        RMIConnection proxyStub = (RMIConnection)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2202
        rmiConnectionImplStubConstructor.newInstance(args);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2203
        return proxyStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2204
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2205
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2206
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2207
       The following code performs a similar trick for RMI/IIOP to the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2208
       one described above for RMI/JRMP.  Unlike JRMP, though, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2209
       can't easily insert an object between the RMIConnection stub
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2210
       and the RMI/IIOP deserialization code, as explained below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2211
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2212
       A method in an RMI/IIOP stub does the following.  It makes an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2213
       org.omg.CORBA_2_3.portable.OutputStream for each request, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2214
       writes the parameters to it.  Then it calls
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2215
       _invoke(OutputStream) which it inherits from CORBA's
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2216
       ObjectImpl.  That returns an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2217
       org.omg.CORBA_2_3.portable.InputStream.  The return value is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2218
       read from this InputStream.  So the stack during
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2219
       deserialization looks like this:
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2220
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2221
       MBeanServerConnection.getAttribute (or whatever)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2222
       -> _RMIConnection_Stub.getAttribute
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2223
          -> Util.readAny (a CORBA method)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2224
             -> InputStream.read_any
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2225
                -> internal CORBA stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2226
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2227
       What we would have *liked* to have done would be the same thing
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2228
       as for RMI/JRMP.  We create a "ProxyDelegate" that is an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2229
       org.omg.CORBA.portable.Delegate that simply forwards every
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2230
       operation to the real original Delegate from the RMIConnection
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2231
       stub, except that the InputStream returned by _invoke is
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2232
       wrapped by a "ProxyInputStream" that is loaded by our
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2233
       NoCallStackClassLoader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2234
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2235
       Unfortunately, this doesn't work, at least with Sun's J2SE
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2236
       1.4.2, because the CORBA code is not designed to allow you to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2237
       change Delegates arbitrarily.  You get a ClassCastException
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2238
       from code that expects the Delegate to implement an internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2239
       interface.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2240
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2241
       So instead we do the following.  We create a subclass of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2242
       stub that overrides the _invoke method so as to wrap the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2243
       returned InputStream in a ProxyInputStream.  We create a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2244
       subclass of ProxyInputStream using the NoCallStackClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2245
       and override its read_any and read_value(Class) methods.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2246
       (These are the only methods called during deserialization of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2247
       MBeanServerConnection return values.)  We extract the Delegate
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2248
       from the original stub and insert it into our subclass stub,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2249
       and away we go.  The state of a stub consists solely of its
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2250
       Delegate.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2251
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2252
       We also need to catch ApplicationException, which will encode
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2253
       any exceptions declared in the throws clause of the called
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2254
       method.  Its InputStream needs to be wrapped in a
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2255
       ProxyInputSteam too.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2256
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2257
       We override _releaseReply in the stub subclass so that it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2258
       replaces a ProxyInputStream argument with the original
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2259
       InputStream.  This avoids problems if the implementation of
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2260
       _releaseReply ends up casting this InputStream to an
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2261
       implementation-specific interface (which in Sun's J2SE 5 it
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2262
       does).
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2263
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2264
       It is not strictly necessary for the stub subclass to be loaded
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2265
       by a NoCallStackClassLoader, since the call-stack search stops
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2266
       at the ProxyInputStream subclass.  However, it is convenient
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2267
       for two reasons.  One is that it means that the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2268
       ProxyInputStream subclass can be accessed directly, without
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2269
       using reflection.  The other is that it avoids build problems,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2270
       since usually stubs are created after other classes are
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2271
       compiled, so we can't access them from this class without,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2272
       again, using reflection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2273
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2274
       The strings below encode the following two Java classes,
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2275
       compiled using javac -g:none.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2276
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2277
        package com.sun.jmx.remote.protocol.iiop;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2278
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2279
        import org.omg.stub.javax.management.remote.rmi._RMIConnection_Stub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2280
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2281
        import org.omg.CORBA.portable.ApplicationException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2282
        import org.omg.CORBA.portable.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2283
        import org.omg.CORBA.portable.OutputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2284
        import org.omg.CORBA.portable.RemarshalException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2285
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2286
        public class ProxyStub extends _RMIConnection_Stub {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2287
            public InputStream _invoke(OutputStream out)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2288
                    throws ApplicationException, RemarshalException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2289
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2290
                    return new PInputStream(super._invoke(out));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2291
                } catch (ApplicationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2292
                    InputStream pis = new PInputStream(e.getInputStream());
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2293
                    throw new ApplicationException(e.getId(), pis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2294
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2295
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2296
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2297
            public void _releaseReply(InputStream in) {
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2298
                if (in != null)
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2299
                    in = ((PInputStream)in).getProxiedInputStream();
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2300
                super._releaseReply(in);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2301
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2303
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2304
        package com.sun.jmx.remote.protocol.iiop;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2305
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2306
        public class PInputStream extends ProxyInputStream {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2307
            public PInputStream(org.omg.CORBA.portable.InputStream in) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2308
                super(in);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2309
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2310
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2311
            public org.omg.CORBA.Any read_any() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2312
                return in.read_any();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2313
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2314
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2315
            public java.io.Serializable read_value(Class clz) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2316
                return narrow().read_value(clz);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2317
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2318
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2319
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2320
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2321
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2322
    private static final String iiopConnectionStubClassName =
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2323
        "org.omg.stub.javax.management.remote.rmi._RMIConnection_Stub";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2324
    private static final String proxyStubClassName =
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2325
        "com.sun.jmx.remote.protocol.iiop.ProxyStub";
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2326
    private static final String ProxyInputStreamClassName =
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2327
        "com.sun.jmx.remote.protocol.iiop.ProxyInputStream";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2328
    private static final String pInputStreamClassName =
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2329
        "com.sun.jmx.remote.protocol.iiop.PInputStream";
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 1446
diff changeset
  2330
    private static final Class<?> proxyStubClass;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2331
    static {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2332
        final String proxyStubByteCodeString =
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2333
                "\312\376\272\276\0\0\0\63\0+\12\0\14\0\30\7\0\31\12\0\14\0\32\12"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2334
                "\0\2\0\33\7\0\34\12\0\5\0\35\12\0\5\0\36\12\0\5\0\37\12\0\2\0 "+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2335
                "\12\0\14\0!\7\0\"\7\0#\1\0\6<init>\1\0\3()V\1\0\4Code\1\0\7_in"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2336
                "voke\1\0K(Lorg/omg/CORBA/portable/OutputStream;)Lorg/omg/CORBA"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2337
                "/portable/InputStream;\1\0\15StackMapTable\7\0\34\1\0\12Except"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2338
                "ions\7\0$\1\0\15_releaseReply\1\0'(Lorg/omg/CORBA/portable/Inp"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2339
                "utStream;)V\14\0\15\0\16\1\0-com/sun/jmx/remote/protocol/iiop/"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2340
                "PInputStream\14\0\20\0\21\14\0\15\0\27\1\0+org/omg/CORBA/porta"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2341
                "ble/ApplicationException\14\0%\0&\14\0'\0(\14\0\15\0)\14\0*\0&"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2342
                "\14\0\26\0\27\1\0*com/sun/jmx/remote/protocol/iiop/ProxyStub\1"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2343
                "\0<org/omg/stub/javax/management/remote/rmi/_RMIConnection_Stu"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2344
                "b\1\0)org/omg/CORBA/portable/RemarshalException\1\0\16getInput"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2345
                "Stream\1\0&()Lorg/omg/CORBA/portable/InputStream;\1\0\5getId\1"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2346
                "\0\24()Ljava/lang/String;\1\09(Ljava/lang/String;Lorg/omg/CORB"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2347
                "A/portable/InputStream;)V\1\0\25getProxiedInputStream\0!\0\13\0"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2348
                "\14\0\0\0\0\0\3\0\1\0\15\0\16\0\1\0\17\0\0\0\21\0\1\0\1\0\0\0\5"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2349
                "*\267\0\1\261\0\0\0\0\0\1\0\20\0\21\0\2\0\17\0\0\0G\0\4\0\4\0\0"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2350
                "\0'\273\0\2Y*+\267\0\3\267\0\4\260M\273\0\2Y,\266\0\6\267\0\4N"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2351
                "\273\0\5Y,\266\0\7-\267\0\10\277\0\1\0\0\0\14\0\15\0\5\0\1\0\22"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2352
                "\0\0\0\6\0\1M\7\0\23\0\24\0\0\0\6\0\2\0\5\0\25\0\1\0\26\0\27\0"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2353
                "\1\0\17\0\0\0'\0\2\0\2\0\0\0\22+\306\0\13+\300\0\2\266\0\11L*+"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2354
                "\267\0\12\261\0\0\0\1\0\22\0\0\0\3\0\1\14\0\0";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2355
        final String pInputStreamByteCodeString =
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2356
                "\312\376\272\276\0\0\0\63\0\36\12\0\7\0\17\11\0\6\0\20\12\0\21"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2357
                "\0\22\12\0\6\0\23\12\0\24\0\25\7\0\26\7\0\27\1\0\6<init>\1\0'("+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2358
                "Lorg/omg/CORBA/portable/InputStream;)V\1\0\4Code\1\0\10read_an"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2359
                "y\1\0\25()Lorg/omg/CORBA/Any;\1\0\12read_value\1\0)(Ljava/lang"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2360
                "/Class;)Ljava/io/Serializable;\14\0\10\0\11\14\0\30\0\31\7\0\32"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2361
                "\14\0\13\0\14\14\0\33\0\34\7\0\35\14\0\15\0\16\1\0-com/sun/jmx"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2362
                "/remote/protocol/iiop/PInputStream\1\0\61com/sun/jmx/remote/pr"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2363
                "otocol/iiop/ProxyInputStream\1\0\2in\1\0$Lorg/omg/CORBA/portab"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2364
                "le/InputStream;\1\0\"org/omg/CORBA/portable/InputStream\1\0\6n"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2365
                "arrow\1\0*()Lorg/omg/CORBA_2_3/portable/InputStream;\1\0&org/o"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2366
                "mg/CORBA_2_3/portable/InputStream\0!\0\6\0\7\0\0\0\0\0\3\0\1\0"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2367
                "\10\0\11\0\1\0\12\0\0\0\22\0\2\0\2\0\0\0\6*+\267\0\1\261\0\0\0"+
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2368
                "\0\0\1\0\13\0\14\0\1\0\12\0\0\0\24\0\1\0\1\0\0\0\10*\264\0\2\266"+
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2369
                "\0\3\260\0\0\0\0\0\1\0\15\0\16\0\1\0\12\0\0\0\25\0\2\0\2\0\0\0"+
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2370
                "\11*\266\0\4+\266\0\5\260\0\0\0\0\0\0";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2371
        final byte[] proxyStubByteCode =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2372
                NoCallStackClassLoader.stringToBytes(proxyStubByteCodeString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2373
        final byte[] pInputStreamByteCode =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2374
                NoCallStackClassLoader.stringToBytes(pInputStreamByteCodeString);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2375
        final String[] classNames={proxyStubClassName, pInputStreamClassName};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2376
        final byte[][] byteCodes = {proxyStubByteCode, pInputStreamByteCode};
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2377
        final String[] otherClassNames = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2378
            iiopConnectionStubClassName,
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2379
            ProxyInputStreamClassName,
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2380
        };
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2381
        if (IIOPHelper.isAvailable()) {
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2382
            PrivilegedExceptionAction<Class<?>> action =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2383
                new PrivilegedExceptionAction<Class<?>>() {
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2384
              public Class<?> run() throws Exception {
24871
224e298c3978 8044865: Fix raw and unchecked lint warnings in management-related code
sjiang
parents: 21656
diff changeset
  2385
                Class<RMIConnector> thisClass = RMIConnector.class;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2386
                ClassLoader thisLoader = thisClass.getClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2387
                ProtectionDomain thisProtectionDomain =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2388
                        thisClass.getProtectionDomain();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2389
                ClassLoader cl =
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2390
                        new NoCallStackClassLoader(classNames,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2391
                        byteCodes,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2392
                        otherClassNames,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2393
                        thisLoader,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2394
                        thisProtectionDomain);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2395
                return cl.loadClass(proxyStubClassName);
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2396
              }
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2397
            };
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2398
            Class<?> stubClass;
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2399
            try {
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2400
                stubClass = AccessController.doPrivileged(action);
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2401
            } catch (Exception e) {
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2402
                logger.error("<clinit>",
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2403
                        "Unexpected exception making shadow IIOP stub class: "+e);
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2404
                logger.debug("<clinit>",e);
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2405
                stubClass = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2406
            }
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2407
            proxyStubClass = stubClass;
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2408
        } else {
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2409
            proxyStubClass = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2410
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2412
20808
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2413
  private static RMIConnection shadowIiopStub(Object stub)
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2414
    throws InstantiationException, IllegalAccessException {
20808
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2415
        Object proxyStub = null;
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2416
        try {
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2417
            proxyStub = AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2418
                public Object run() throws Exception {
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2419
                    return proxyStubClass.newInstance();
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2420
                }
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2421
            });
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2422
        } catch (PrivilegedActionException e) {
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2423
            throw new InternalError();
87159c70b5fd 8011157: Improve CORBA portablility
msheppar
parents: 18206
diff changeset
  2424
        }
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2425
        IIOPHelper.setDelegate(proxyStub, IIOPHelper.getDelegate(stub));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2426
        return (RMIConnection) proxyStub;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2427
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2428
    private static RMIConnection getConnection(RMIServer server,
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2429
            Object credentials,
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2430
            boolean checkStub)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2431
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2432
        RMIConnection c = server.newClient(credentials);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2433
        if (checkStub) checkStub(c, rmiConnectionImplStubClass);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2434
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2435
            if (c.getClass() == rmiConnectionImplStubClass)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2436
                return shadowJrmpStub((RemoteObject) c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2437
            if (c.getClass().getName().equals(iiopConnectionStubClassName))
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2438
                return shadowIiopStub(c);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2439
            logger.trace("getConnection",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2440
                    "Did not wrap " + c.getClass() + " to foil " +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2441
                    "stack search for classes: class loading semantics " +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2442
                    "may be incorrect");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2443
        } catch (Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2444
            logger.error("getConnection",
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2445
                    "Could not wrap " + c.getClass() + " to foil " +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2446
                    "stack search for classes: class loading semantics " +
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2447
                    "may be incorrect: " + e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2448
            logger.debug("getConnection",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2449
            // so just return the original stub, which will work for all
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2450
            // but the most exotic class loading situations
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2451
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2452
        return c;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2453
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2454
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2455
    private static byte[] base64ToByteArray(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2456
        int sLen = s.length();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2457
        int numGroups = sLen/4;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2458
        if (4*numGroups != sLen)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2459
            throw new IllegalArgumentException(
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2460
                    "String length must be a multiple of four.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2461
        int missingBytesInLastGroup = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2462
        int numFullGroups = numGroups;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2463
        if (sLen != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2464
            if (s.charAt(sLen-1) == '=') {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2465
                missingBytesInLastGroup++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2466
                numFullGroups--;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2467
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2468
            if (s.charAt(sLen-2) == '=')
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2469
                missingBytesInLastGroup++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2471
        byte[] result = new byte[3*numGroups - missingBytesInLastGroup];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2472
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2473
        // Translate all full groups from base64 to byte array elements
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2474
        int inCursor = 0, outCursor = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2475
        for (int i=0; i<numFullGroups; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2476
            int ch0 = base64toInt(s.charAt(inCursor++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2477
            int ch1 = base64toInt(s.charAt(inCursor++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2478
            int ch2 = base64toInt(s.charAt(inCursor++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2479
            int ch3 = base64toInt(s.charAt(inCursor++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2480
            result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2481
            result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2482
            result[outCursor++] = (byte) ((ch2 << 6) | ch3);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2483
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2484
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2485
        // Translate partial group, if present
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2486
        if (missingBytesInLastGroup != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2487
            int ch0 = base64toInt(s.charAt(inCursor++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2488
            int ch1 = base64toInt(s.charAt(inCursor++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2489
            result[outCursor++] = (byte) ((ch0 << 2) | (ch1 >> 4));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2490
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2491
            if (missingBytesInLastGroup == 1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2492
                int ch2 = base64toInt(s.charAt(inCursor++));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2493
                result[outCursor++] = (byte) ((ch1 << 4) | (ch2 >> 2));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2494
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2495
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2496
        // assert inCursor == s.length()-missingBytesInLastGroup;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2497
        // assert outCursor == result.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2498
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2500
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2501
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2502
     * Translates the specified character, which is assumed to be in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2503
     * "Base 64 Alphabet" into its equivalent 6-bit positive integer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2505
     * @throws IllegalArgumentException if
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2506
     *        c is not in the Base64 Alphabet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2507
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2508
    private static int base64toInt(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2509
        int result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2510
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2511
        if (c >= base64ToInt.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2512
            result = -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2513
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2514
            result = base64ToInt[c];
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2515
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2516
        if (result < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2517
            throw new IllegalArgumentException("Illegal character " + c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2518
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2519
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2520
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2521
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2522
     * This array is a lookup table that translates unicode characters
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2523
     * drawn from the "Base64 Alphabet" (as specified in Table 1 of RFC 2045)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2524
     * into their 6-bit positive integer equivalents.  Characters that
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2525
     * are not in the Base64 alphabet but fall within the bounds of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2526
     * array are translated to -1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2527
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2528
    private static final byte base64ToInt[] = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2529
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2530
        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2531
        -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, -1, -1, -1, 63, 52, 53, 54,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2532
        55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, -1, 0, 1, 2, 3, 4,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2533
        5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2534
        24, 25, -1, -1, -1, -1, -1, -1, 26, 27, 28, 29, 30, 31, 32, 33, 34,
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2535
        35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2536
    };
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2537
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2538
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2539
    // Private stuff - Find / Set default class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2540
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2541
    private ClassLoader pushDefaultClassLoader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2542
        final Thread t = Thread.currentThread();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2543
        final ClassLoader old =  t.getContextClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2544
        if (defaultClassLoader != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2545
            AccessController.doPrivileged(new PrivilegedAction<Void>() {
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2546
                public Void run() {
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2547
                    t.setContextClassLoader(defaultClassLoader);
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2548
                    return null;
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2549
                }
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2550
            });
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2551
            return old;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2553
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2554
    private void popDefaultClassLoader(final ClassLoader old) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2555
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
1570
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2556
            public Void run() {
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2557
                Thread.currentThread().setContextClassLoader(old);
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2558
                return null;
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2559
            }
4165709c91e3 5072267: A way to communicate client context such as locale to the JMX server
emcmanus
parents: 1510
diff changeset
  2560
        });
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2561
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2562
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2563
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2564
    // Private variables
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2565
    //--------------------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2566
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2567
     * @serial The RMIServer stub of the RMI JMX Connector server to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2568
     * which this client connector is (or will be) connected. This
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2569
     * field can be null when <var>jmxServiceURL</var> is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2570
     * null. This includes the case where <var>jmxServiceURL</var>
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2571
     * contains a serialized RMIServer stub. If both
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2572
     * <var>rmiServer</var> and <var>jmxServiceURL</var> are null then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2573
     * serialization will fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2574
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2575
     * @see #RMIConnector(RMIServer,Map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2576
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2577
    private final RMIServer rmiServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2578
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2579
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2580
     * @serial The JMXServiceURL of the RMI JMX Connector server to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2581
     * which this client connector will be connected. This field can
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2582
     * be null when <var>rmiServer</var> is not null. If both
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2583
     * <var>rmiServer</var> and <var>jmxServiceURL</var> are null then
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2584
     * serialization will fail.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2585
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2586
     * @see #RMIConnector(JMXServiceURL,Map)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2587
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2588
    private final JMXServiceURL jmxServiceURL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2589
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2590
    // ---------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2591
    // WARNING - WARNING - WARNING - WARNING - WARNING - WARNING
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2592
    // ---------------------------------------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2593
    // Any transient variable which needs to be initialized should
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2594
    // be initialized in the method initTransient()
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2595
    private transient Map<String, Object> env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2596
    private transient ClassLoader defaultClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2597
    private transient RMIConnection connection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2598
    private transient String connectionId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2599
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2600
    private transient long clientNotifSeqNo = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2601
19791
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2602
    private transient WeakHashMap<Subject, WeakReference<MBeanServerConnection>> rmbscMap;
d0bcc2086175 6566891: RMIConnector: map value referencing map key in WeakHashMap prevents map entry to be removed
sjiang
parents: 18206
diff changeset
  2603
    private transient WeakReference<MBeanServerConnection> nullSubjectConnRef = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2604
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2605
    private transient RMINotifClient rmiNotifClient;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2606
    // = new RMINotifClient(new Integer(0));
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2607
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2608
    private transient long clientNotifCounter = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2609
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2610
    private transient boolean connected;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2611
    // = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2612
    private transient boolean terminated;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2613
    // = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2614
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2615
    private transient Exception closeException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2616
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2617
    private transient NotificationBroadcasterSupport connectionBroadcaster;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2618
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2619
    private transient ClientCommunicatorAdmin communicatorAdmin;
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2620
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2621
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2622
     * A static WeakReference to an {@link org.omg.CORBA.ORB ORB} to
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2623
     * connect unconnected stubs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2624
     **/
4167
76f44f2d5d4d 6888179: Separate out dependency on CORBA
alanb
parents: 4156
diff changeset
  2625
    private static volatile WeakReference<Object> orb = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2626
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2627
    // TRACES & DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2628
    //---------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2629
    private static String objects(final Object[] objs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2630
        if (objs == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2631
            return "null";
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2632
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2633
            return Arrays.asList(objs).toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2634
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2635
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2636
    private static String strings(final String[] strs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2637
        return objects(strs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2638
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
  2639
}