jdk/src/share/classes/javax/management/remote/rmi/RMIServerImpl.java
author rriggs
Tue, 12 Nov 2013 14:03:28 -0500
changeset 21656 d4c777ccb1db
parent 17425 9259f4bb1c48
child 23010 6dadb192ad81
permissions -rw-r--r--
8028014: Doclint warning/error cleanup in javax.management Summary: Improve generated html by fixing doclint warnings Reviewed-by: sla, jbachorik
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
     2
 * Copyright (c) 2002, 2008, 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: 4156
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: 4156
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: 4156
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4156
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 com.sun.jmx.remote.internal.ArrayNotificationBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import com.sun.jmx.remote.internal.NotificationBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import com.sun.jmx.remote.security.JMXPluggableAuthenticator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import com.sun.jmx.remote.util.ClassLogger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.io.Closeable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.lang.ref.WeakReference;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.rmi.Remote;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.rmi.server.RemoteServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.rmi.server.ServerNotActiveException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.Principal;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import javax.management.MBeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import javax.management.remote.JMXAuthenticator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import javax.management.remote.JMXConnectorServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import javax.security.auth.Subject;
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 RMI object representing a connector server.  Remote clients
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * can make connections using the {@link #newClient(Object)} method.  This
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * method returns an RMI object representing the connection.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>User code does not usually reference this class directly.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * RMI connection servers are usually created with the class {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * RMIConnectorServer}.  Remote clients usually create connections
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * either with {@link javax.management.remote.JMXConnectorFactory}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * or by instantiating {@link RMIConnector}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <p>This is an abstract class.  Concrete subclasses define the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * details of the client connection objects, such as whether they use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * JRMP or IIOP.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * @since 1.5
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
public abstract class RMIServerImpl implements Closeable, RMIServer {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * <p>Constructs a new <code>RMIServerImpl</code>.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     * @param env the environment containing attributes for the new
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <code>RMIServerImpl</code>.  Can be null, which is equivalent
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * to an empty Map.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    public RMIServerImpl(Map<String,?> env) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
    78
        this.env = (env == null) ? Collections.<String,Object>emptyMap() : env;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    void setRMIConnectorServer(RMIConnectorServer connServer)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
        this.connServer = connServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * <p>Exports this RMI object.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * @exception IOException if this RMI object cannot be exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    protected abstract void export() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Returns a remotable stub for this server object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @return a remotable stub.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     * @exception IOException if the stub cannot be obtained - e.g the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *            RMIServerImpl has not been exported yet.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     **/
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
    public abstract Remote toStub() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     * <p>Sets the default <code>ClassLoader</code> for this connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * server. New client connections will use this classloader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Existing client connections are unaffected.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @param cl the new <code>ClassLoader</code> to be used by this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     * connector server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @see #getDefaultClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    public synchronized void setDefaultClassLoader(ClassLoader cl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        this.cl = cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * <p>Gets the default <code>ClassLoader</code> used by this connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * server.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
     * @return the default <code>ClassLoader</code> used by this
21656
d4c777ccb1db 8028014: Doclint warning/error cleanup in javax.management
rriggs
parents: 17425
diff changeset
   120
     * connector server.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * @see #setDefaultClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    public synchronized ClassLoader getDefaultClassLoader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        return cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * <p>Sets the <code>MBeanServer</code> to which this connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     * server is attached. New client connections will interact
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * with this <code>MBeanServer</code>. Existing client connections are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * unaffected.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * @param mbs the new <code>MBeanServer</code>.  Can be null, but
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * new client connections will be refused as long as it is.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * @see #getMBeanServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    public synchronized void setMBeanServer(MBeanServer mbs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
        this.mbeanServer = mbs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * <p>The <code>MBeanServer</code> to which this connector server
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * is attached.  This is the last value passed to {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * #setMBeanServer} on this object, or null if that method has
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * never been called.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * @return the <code>MBeanServer</code> to which this connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * is attached.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see #setMBeanServer
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    public synchronized MBeanServer getMBeanServer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
        return mbeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
    public String getVersion() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        // Expected format is: "protocol-version implementation-name"
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            return "1.0 java_runtime_" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                    System.getProperty("java.runtime.version");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
            return "1.0 ";
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
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
     * <p>Creates a new client connection.  This method calls {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * #makeClient makeClient} and adds the returned client connection
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     * object to an internal list.  When this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * <code>RMIServerImpl</code> is shut down via its {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * #close()} method, the {@link RMIConnection#close() close()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * method of each object remaining in the list is called.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * <p>The fact that a client connection object is in this internal
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * list does not prevent it from being garbage collected.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * @param credentials this object specifies the user-defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * credentials to be passed in to the server in order to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * authenticate the caller before creating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     * <code>RMIConnection</code>.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @return the newly-created <code>RMIConnection</code>.  This is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     * usually the object created by <code>makeClient</code>, though
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * an implementation may choose to wrap that object in another
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * object implementing <code>RMIConnection</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * @exception IOException if the new client object cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * created or exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @exception SecurityException if the given credentials do not allow
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * the server to authenticate the user successfully.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * @exception IllegalStateException if {@link #getMBeanServer()}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
    public RMIConnection newClient(Object credentials) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return doNewClient(credentials);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * This method could be overridden by subclasses defined in this package
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * to perform additional operations specific to the underlying transport
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * before creating the new client connection.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    RMIConnection doNewClient(Object credentials) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
        final boolean tracing = logger.traceOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
        if (tracing) logger.trace("newClient","making new client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (getMBeanServer() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            throw new IllegalStateException("Not attached to an MBean server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        Subject subject = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        JMXAuthenticator authenticator =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            (JMXAuthenticator) env.get(JMXConnectorServer.AUTHENTICATOR);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (authenticator == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
             * Create the JAAS-based authenticator only if authentication
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
             * has been enabled
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
             */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            if (env.get("jmx.remote.x.password.file") != null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                env.get("jmx.remote.x.login.config") != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
                authenticator = new JMXPluggableAuthenticator(env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        if (authenticator != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            if (tracing) logger.trace("newClient","got authenticator: " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                               authenticator.getClass().getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
                subject = authenticator.authenticate(credentials);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            } catch (SecurityException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                logger.trace("newClient", "Authentication failed: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
                throw e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
        if (tracing) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            if (subject != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                logger.trace("newClient","subject is not null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
            else logger.trace("newClient","no subject");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
        final String connectionId = makeConnectionId(getProtocol(), subject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            logger.trace("newClient","making new connection: " + connectionId);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
        RMIConnection client = makeClient(connectionId, subject);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        dropDeadReferences();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        WeakReference<RMIConnection> wr = new WeakReference<RMIConnection>(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        synchronized (clientList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            clientList.add(wr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
1708
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   258
        connServer.connectionOpened(connectionId, "Connection opened", null);
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   259
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   260
        synchronized (clientList) {
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   261
            if (!clientList.contains(wr)) {
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   262
                // can be removed only by a JMXConnectionNotification listener
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   263
                throw new IOException("The connection is refused.");
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   264
            }
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   265
        }
4e1939e6e6b5 6332907: Add ability for connector server to close individual connections
sjiang
parents: 1510
diff changeset
   266
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            logger.trace("newClient","new connection done: " + connectionId );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        return client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * <p>Creates a new client connection.  This method is called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * the public method {@link #newClient(Object)}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @param connectionId the ID of the new connection.  Every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     * connection opened by this connector server will have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * different ID.  The behavior is unspecified if this parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * @param subject the authenticated subject.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * @return the newly-created <code>RMIConnection</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     * @exception IOException if the new client object cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * created or exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    protected abstract RMIConnection makeClient(String connectionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                                                Subject subject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * <p>Closes a client connection made by {@link #makeClient makeClient}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * @param client a connection previously returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * <code>makeClient</code> on which the <code>closeClient</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * method has not previously been called.  The behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * unspecified if these conditions are violated, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     * case where <code>client</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * @exception IOException if the client connection cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    protected abstract void closeClient(RMIConnection client)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * <p>Returns the protocol string for this object.  The string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <code>rmi</code> for RMI/JRMP and <code>iiop</code> for RMI/IIOP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @return the protocol string for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    protected abstract String getProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * <p>Method called when a client connection created by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * #makeClient makeClient} is closed.  A subclass that defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <code>makeClient</code> must arrange for this method to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * called when the resultant object's {@link RMIConnection#close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * close} method is called.  This enables it to be removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * the <code>RMIServerImpl</code>'s list of connections.  It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * not an error for <code>client</code> not to be in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * list.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * <p>After removing <code>client</code> from the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * connections, this method calls {@link #closeClient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * closeClient(client)}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * @param client the client connection that has been closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * @exception IOException if {@link #closeClient} throws this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @exception NullPointerException if <code>client</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
    protected void clientClosed(RMIConnection client) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        if (debug) logger.trace("clientClosed","client="+client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        if (client == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            throw new NullPointerException("Null client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        synchronized (clientList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            dropDeadReferences();
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   347
            for (Iterator<WeakReference<RMIConnection>> it = clientList.iterator();
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   348
                 it.hasNext(); ) {
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   349
                WeakReference<RMIConnection> wr = it.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                if (wr.get() == client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
                    it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            /* It is not a bug for this loop not to find the client.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
               our close() method, we remove a client from the list before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
               calling its close() method.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        if (debug) logger.trace("clientClosed", "closing client.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        closeClient(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
        if (debug) logger.trace("clientClosed", "sending notif");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
        connServer.connectionClosed(client.getConnectionId(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
                                    "Client connection closed", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        if (debug) logger.trace("clientClosed","done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * <p>Closes this connection server.  This method first calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * {@link #closeServer()} method so that no new client connections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * will be accepted.  Then, for each remaining {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * RMIConnection} object returned by {@link #makeClient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * makeClient}, its {@link RMIConnection#close() close} method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * called.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <p>The behavior when this method is called more than once is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * unspecified.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * <p>If {@link #closeServer()} throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * <code>IOException</code>, the individual connections are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * nevertheless closed, and then the <code>IOException</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * thrown from this method.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * <p>If {@link #closeServer()} returns normally but one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * of the individual connections throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <code>IOException</code>, then, after closing all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * connections, one of those <code>IOException</code>s is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * from this method.  If more than one connection throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * <code>IOException</code>, it is unspecified which one is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * from this method.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @exception IOException if {@link #closeServer()} or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * {@link RMIConnection#close()} calls threw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * <code>IOException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public synchronized void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        final boolean tracing = logger.traceOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        final boolean debug   = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        if (tracing) logger.trace("close","closing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        IOException ioException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
            if (debug)   logger.debug("close","closing Server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            closeServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            if (tracing) logger.trace("close","Failed to close server: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
            if (debug)   logger.debug("close",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
            ioException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
        if (debug)   logger.debug("close","closing Clients");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        // Loop to close all clients
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
            synchronized (clientList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                if (debug) logger.debug("close","droping dead references");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                dropDeadReferences();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                if (debug) logger.debug("close","client count: "+clientList.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                if (clientList.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                /* Loop until we find a non-null client.  Because we called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                   dropDeadReferences(), this will usually be the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                   element of the list, but a garbage collection could have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                   happened in between.  */
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   428
                for (Iterator<WeakReference<RMIConnection>> it = clientList.iterator();
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   429
                     it.hasNext(); ) {
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   430
                    WeakReference<RMIConnection> wr = it.next();
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   431
                    RMIConnection client = wr.get();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                    it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                    if (client != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                            client.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
                            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
                                logger.trace("close","Failed to close client: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
                            if (debug) logger.debug("close",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
                            if (ioException == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
                                ioException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
                        break;
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
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        if(notifBuffer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            notifBuffer.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        if (ioException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
            if (tracing) logger.trace("close","close failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            throw ioException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
        if (tracing) logger.trace("close","closed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * <p>Called by {@link #close()} to close the connector server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * After returning from this method, the connector server must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * not accept any new connections.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * @exception IOException if the attempt to close the connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * server failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    protected abstract void closeServer() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    private static synchronized String makeConnectionId(String protocol,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                                                        Subject subject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        connectionIdNumber++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        String clientHost = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
            clientHost = RemoteServer.getClientHost();
17425
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   477
            /*
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   478
             * According to the rules specified in the javax.management.remote
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   479
             * package description, a numeric IPv6 address (detected by the
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   480
             * presence of otherwise forbidden ":" character) forming a part
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   481
             * of the connection id must be enclosed in square brackets.
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   482
             */
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   483
            if (clientHost.contains(":")) {
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   484
                clientHost = "[" + clientHost + "]";
9259f4bb1c48 7199324: Connection ID for IPv6 addresses is not generated accordingly to the specification
jbachorik
parents: 5506
diff changeset
   485
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        } catch (ServerNotActiveException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            logger.trace("makeConnectionId", "getClientHost", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        final StringBuilder buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        buf.append(protocol).append(":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (clientHost.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            buf.append("//").append(clientHost);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        buf.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        if (subject != null) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   496
            Set<Principal> principals = subject.getPrincipals();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            String sep = "";
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   498
            for (Iterator<Principal> it = principals.iterator(); it.hasNext(); ) {
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   499
                Principal p = it.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                String name = p.getName().replace(' ', '_').replace(';', ':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                buf.append(sep).append(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                sep = ";";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        buf.append(" ").append(connectionIdNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        if (logger.traceOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
            logger.trace("newConnectionId","connectionId="+buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
    private void dropDeadReferences() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        synchronized (clientList) {
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   513
            for (Iterator<WeakReference<RMIConnection>> it = clientList.iterator();
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   514
                 it.hasNext(); ) {
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   515
                WeakReference<RMIConnection> wr = it.next();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                if (wr.get() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                    it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
    synchronized NotificationBuffer getNotifBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        //Notification buffer is lazily created when the first client connects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
        if(notifBuffer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
            notifBuffer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                ArrayNotificationBuffer.getNotificationBuffer(mbeanServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                                                              env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
        return notifBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    private static final ClassLogger logger =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        new ClassLogger("javax.management.remote.rmi", "RMIServerImpl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
    /** List of WeakReference values.  Each one references an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        RMIConnection created by this object, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        RMIConnection has been garbage-collected.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    private final List<WeakReference<RMIConnection>> clientList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            new ArrayList<WeakReference<RMIConnection>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    private ClassLoader cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    private MBeanServer mbeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
1510
e747d3193ef2 6763639: Remove "rawtypes" warnings from JMX code
emcmanus
parents: 2
diff changeset
   544
    private final Map<String, ?> env;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    private RMIConnectorServer connServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    private static int connectionIdNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    private NotificationBuffer notifBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
}