jdk/src/java.management/share/classes/javax/management/remote/rmi/RMIJRMPServerImpl.java
author sjiang
Fri, 22 Jan 2016 13:27:09 +0100
changeset 37584 0cc00d7a0755
parent 25859 3317bb8137f4
permissions -rw-r--r--
8144430: Improve JMX connections Reviewed-by: dfuchs, jbachorik, skoivu, ahgross
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
     2
 * Copyright (c) 2002, 2016, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1706
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1706
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1706
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1706
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1706
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package javax.management.remote.rmi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.rmi.NoSuchObjectException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.rmi.RemoteException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.rmi.server.RMIClientSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.rmi.server.RMIServerSocketFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.rmi.server.UnicastRemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.rmi.server.RemoteObject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import javax.security.auth.Subject;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import com.sun.jmx.remote.internal.RMIExporter;
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
    41
import com.sun.jmx.remote.util.EnvHelp;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    42
import java.io.ObjectStreamClass;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    43
import java.lang.reflect.Method;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    44
import java.util.ArrayList;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    45
import java.util.Arrays;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    46
import java.util.List;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    47
import sun.reflect.misc.ReflectUtil;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    48
import sun.rmi.server.DeserializationChecker;
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
    49
import sun.rmi.server.UnicastServerRef;
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
    50
import sun.rmi.server.UnicastServerRef2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>An {@link RMIServer} object that is exported through JRMP and that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * creates client connections as RMI objects exported through JRMP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * User code does not usually reference this class directly.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * @see RMIServerImpl
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
public class RMIJRMPServerImpl extends RMIServerImpl {
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    62
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    63
    private final ExportedWrapper exportedWrapper;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
    64
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * <p>Creates a new {@link RMIServer} object that will be exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     * on the given port using the given socket factories.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * @param port the port on which this object and the {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * RMIConnectionImpl} objects it creates will be exported.  Can be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * zero, to indicate any available port.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param csf the client socket factory for the created RMI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * objects.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * @param ssf the server socket factory for the created RMI
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * objects.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param env the environment map.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * @exception IOException if the {@link RMIServer} object
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * cannot be created.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @exception IllegalArgumentException if <code>port</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * negative.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
    public RMIJRMPServerImpl(int port,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                             RMIClientSocketFactory csf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                             RMIServerSocketFactory ssf,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                             Map<String,?> env)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
        super(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        if (port < 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            throw new IllegalArgumentException("Negative port: " + port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
        this.port = port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        this.csf = csf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        this.ssf = ssf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
        this.env = (env == null) ? Collections.<String, Object>emptyMap() : env;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   102
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   103
        String[] credentialsTypes
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   104
                = (String[]) this.env.get(RMIConnectorServer.CREDENTIAL_TYPES);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   105
        List<String> types = null;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   106
        if (credentialsTypes != null) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   107
            types = new ArrayList<>();
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   108
            for (String type : credentialsTypes) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   109
                if (type == null) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   110
                    throw new IllegalArgumentException("A credential type is null.");
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   111
                }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   112
                ReflectUtil.checkPackageAccess(type);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   113
                types.add(type);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   114
            }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   115
        }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   116
        exportedWrapper = types != null ?
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   117
                new ExportedWrapper(this, types) :
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   118
                null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    protected void export() throws IOException {
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   122
        if (exportedWrapper != null) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   123
            export(exportedWrapper);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   124
        } else {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   125
            export(this);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   126
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private void export(Remote obj) throws RemoteException {
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   130
        final RMIExporter exporter =
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE);
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   132
        final boolean daemon = EnvHelp.isServerDaemon(env);
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   133
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   134
        if (daemon && exporter != null) {
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   135
            throw new IllegalArgumentException("If "+EnvHelp.JMX_SERVER_DAEMON+
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   136
                    " is specified as true, "+RMIExporter.EXPORTER_ATTRIBUTE+
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   137
                    " cannot be used to specify an exporter!");
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   138
        }
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   139
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   140
        if (daemon) {
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   141
            if (csf == null && ssf == null) {
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   142
                new UnicastServerRef(port).exportObject(obj, null, true);
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   143
            } else {
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   144
                new UnicastServerRef2(port, csf, ssf).exportObject(obj, null, true);
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   145
            }
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   146
        } else if (exporter != null) {
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   147
            exporter.exportObject(obj, port, csf, ssf);
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   148
        } else {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            UnicastRemoteObject.exportObject(obj, port, csf, ssf);
1706
4a382455c04d 6760712: Provide a connector server option that causes it not to prevent the VM from exiting
sjiang
parents: 2
diff changeset
   150
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    private void unexport(Remote obj, boolean force)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            throws NoSuchObjectException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        RMIExporter exporter =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            (RMIExporter) env.get(RMIExporter.EXPORTER_ATTRIBUTE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
        if (exporter == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            UnicastRemoteObject.unexportObject(obj, force);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            exporter.unexportObject(obj, force);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    protected String getProtocol() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        return "rmi";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
     * <p>Returns a serializable stub for this {@link RMIServer} object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * @return a serializable stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @exception IOException if the stub cannot be obtained - e.g the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *            RMIJRMPServerImpl has not been exported yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
    public Remote toStub() throws IOException {
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   176
        if (exportedWrapper != null) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   177
            return RemoteObject.toStub(exportedWrapper);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   178
        } else {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   179
            return RemoteObject.toStub(this);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   180
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * <p>Creates a new client connection as an RMI object exported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * through JRMP. The port and socket factories for the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * {@link RMIConnection} object are the ones supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * to the <code>RMIJRMPServerImpl</code> constructor.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @param connectionId the ID of the new connection. Every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * connection opened by this connector server will have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     * different id.  The behavior is unspecified if this parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @param subject the authenticated subject.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @return the newly-created <code>RMIConnection</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * @exception IOException if the new {@link RMIConnection}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * object cannot be created or exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    protected RMIConnection makeClient(String connectionId, Subject subject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
        if (connectionId == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            throw new NullPointerException("Null connectionId");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        RMIConnection client =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            new RMIConnectionImpl(this, connectionId, getDefaultClassLoader(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                                  subject, env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        export(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        return client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    protected void closeClient(RMIConnection client) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        unexport(client, true);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * <p>Called by {@link #close()} to close the connector server by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * unexporting this object.  After returning from this method, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * connector server must not accept any new connections.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * @exception IOException if the attempt to close the connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * server failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    protected void closeServer() throws IOException {
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   227
        if (exportedWrapper != null) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   228
            unexport(exportedWrapper, true);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   229
        } else {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   230
            unexport(this, true);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   231
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    private final int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    private final RMIClientSocketFactory csf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    private final RMIServerSocketFactory ssf;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    private final Map<String, ?> env;
37584
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   238
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   239
    private static class ExportedWrapper implements RMIServer, DeserializationChecker {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   240
        private final RMIServer impl;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   241
        private final List<String> allowedTypes;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   242
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   243
        private ExportedWrapper(RMIServer impl, List<String> credentialsTypes) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   244
            this.impl = impl;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   245
            allowedTypes = credentialsTypes;
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   246
        }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   247
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   248
        @Override
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   249
        public String getVersion() throws RemoteException {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   250
            return impl.getVersion();
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   251
        }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   252
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   253
        @Override
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   254
        public RMIConnection newClient(Object credentials) throws IOException {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   255
            return impl.newClient(credentials);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   256
        }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   257
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   258
        @Override
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   259
        public void check(Method method, ObjectStreamClass descriptor,
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   260
                int paramIndex, int callID) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   261
            String type = descriptor.getName();
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   262
            if (!allowedTypes.contains(type)) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   263
                throw new ClassCastException("Unsupported type: " + type);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   264
            }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   265
        }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   266
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   267
        @Override
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   268
        public void checkProxyClass(Method method, String[] ifaces,
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   269
                int paramIndex, int callID) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   270
            if (ifaces != null && ifaces.length > 0) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   271
                for (String iface : ifaces) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   272
                    if (!allowedTypes.contains(iface)) {
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   273
                        throw new ClassCastException("Unsupported type: " + iface);
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   274
                    }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   275
                }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   276
            }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   277
        }
0cc00d7a0755 8144430: Improve JMX connections
sjiang
parents: 25859
diff changeset
   278
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
}