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