jdk/src/share/classes/javax/management/remote/rmi/RMIServerImpl.java
author xdono
Wed, 02 Jul 2008 12:55:45 -0700
changeset 715 f16baef3a20e
parent 2 90ce3da70b43
child 1510 e747d3193ef2
permissions -rw-r--r--
6719955: Update copyright year Summary: Update copyright year for files that have been modified in 2008 Reviewed-by: ohair, tbell
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.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) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
        this.env = (env == null) ? Collections.EMPTY_MAP : env;
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
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * connector server.</p>
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
        connServer.connectionOpened(connectionId, "Connection opened", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        dropDeadReferences();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        WeakReference<RMIConnection> wr = new WeakReference<RMIConnection>(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
        synchronized (clientList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
            clientList.add(wr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            logger.trace("newClient","new connection done: " + connectionId );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
        return client;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     * <p>Creates a new client connection.  This method is called by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * the public method {@link #newClient(Object)}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
     * @param connectionId the ID of the new connection.  Every
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
     * connection opened by this connector server will have a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
     * different ID.  The behavior is unspecified if this parameter is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @param subject the authenticated subject.  Can be null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * @return the newly-created <code>RMIConnection</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @exception IOException if the new client object cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * created or exported.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    protected abstract RMIConnection makeClient(String connectionId,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
                                                Subject subject)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <p>Closes a client connection made by {@link #makeClient makeClient}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * @param client a connection previously returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * <code>makeClient</code> on which the <code>closeClient</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * method has not previously been called.  The behavior is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * unspecified if these conditions are violated, including the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * case where <code>client</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * @exception IOException if the client connection cannot be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    protected abstract void closeClient(RMIConnection client)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * <p>Returns the protocol string for this object.  The string is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * <code>rmi</code> for RMI/JRMP and <code>iiop</code> for RMI/IIOP.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * @return the protocol string for this object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    protected abstract String getProtocol();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <p>Method called when a client connection created by {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * #makeClient makeClient} is closed.  A subclass that defines
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * <code>makeClient</code> must arrange for this method to be
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * called when the resultant object's {@link RMIConnection#close()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * close} method is called.  This enables it to be removed from
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * the <code>RMIServerImpl</code>'s list of connections.  It is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * not an error for <code>client</code> not to be in that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * list.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * <p>After removing <code>client</code> from the list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * connections, this method calls {@link #closeClient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * closeClient(client)}.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * @param client the client connection that has been closed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * @exception IOException if {@link #closeClient} throws this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * exception.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * @exception NullPointerException if <code>client</code> is null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
    protected void clientClosed(RMIConnection client) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
        final boolean debug = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
        if (debug) logger.trace("clientClosed","client="+client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        if (client == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
            throw new NullPointerException("Null client");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        synchronized (clientList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            dropDeadReferences();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            for (Iterator it = clientList.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                WeakReference wr = (WeakReference) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
                if (wr.get() == client) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
                    it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
            /* It is not a bug for this loop not to find the client.  In
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
               our close() method, we remove a client from the list before
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
               calling its close() method.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
        if (debug) logger.trace("clientClosed", "closing client.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        closeClient(client);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        if (debug) logger.trace("clientClosed", "sending notif");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
        connServer.connectionClosed(client.getConnectionId(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                                    "Client connection closed", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        if (debug) logger.trace("clientClosed","done");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * <p>Closes this connection server.  This method first calls the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * {@link #closeServer()} method so that no new client connections
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * will be accepted.  Then, for each remaining {@link
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * RMIConnection} object returned by {@link #makeClient
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * makeClient}, its {@link RMIConnection#close() close} method is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * called.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * <p>The behavior when this method is called more than once is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     * unspecified.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * <p>If {@link #closeServer()} throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * <code>IOException</code>, the individual connections are
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * nevertheless closed, and then the <code>IOException</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * thrown from this method.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * <p>If {@link #closeServer()} returns normally but one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * of the individual connections throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     * <code>IOException</code>, then, after closing all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * connections, one of those <code>IOException</code>s is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * from this method.  If more than one connection throws an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * <code>IOException</code>, it is unspecified which one is thrown
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     * from this method.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
     * @exception IOException if {@link #closeServer()} or one of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * {@link RMIConnection#close()} calls threw
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * <code>IOException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
    public synchronized void close() throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
        final boolean tracing = logger.traceOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        final boolean debug   = logger.debugOn();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        if (tracing) logger.trace("close","closing");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        IOException ioException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            if (debug)   logger.debug("close","closing Server");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
            closeServer();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
            if (tracing) logger.trace("close","Failed to close server: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            if (debug)   logger.debug("close",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            ioException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
        if (debug)   logger.debug("close","closing Clients");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
        // Loop to close all clients
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        while (true) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
            synchronized (clientList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                if (debug) logger.debug("close","droping dead references");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                dropDeadReferences();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                if (debug) logger.debug("close","client count: "+clientList.size());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                if (clientList.size() == 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
                    break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                /* Loop until we find a non-null client.  Because we called
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                   dropDeadReferences(), this will usually be the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                   element of the list, but a garbage collection could have
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                   happened in between.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                for (Iterator it = clientList.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
                    WeakReference wr = (WeakReference) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
                    RMIConnection client = (RMIConnection) wr.get();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                    it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
                    if (client != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
                        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
                            client.close();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
                        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                            if (tracing)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
                                logger.trace("close","Failed to close client: " + e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
                            if (debug) logger.debug("close",e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
                            if (ioException == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                                ioException = e;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                        break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        if(notifBuffer != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            notifBuffer.dispose();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        if (ioException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            if (tracing) logger.trace("close","close failed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
            throw ioException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        if (tracing) logger.trace("close","closed.");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * <p>Called by {@link #close()} to close the connector server.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * After returning from this method, the connector server must
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * not accept any new connections.</p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * @exception IOException if the attempt to close the connector
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * server failed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    protected abstract void closeServer() throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    private static synchronized String makeConnectionId(String protocol,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
                                                        Subject subject) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        connectionIdNumber++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        String clientHost = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            clientHost = RemoteServer.getClientHost();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
        } catch (ServerNotActiveException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            logger.trace("makeConnectionId", "getClientHost", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        final StringBuilder buf = new StringBuilder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
        buf.append(protocol).append(":");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        if (clientHost.length() > 0)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
            buf.append("//").append(clientHost);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        buf.append(" ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        if (subject != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            Set principals = subject.getPrincipals();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            String sep = "";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            for (Iterator it = principals.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                Principal p = (Principal) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
                String name = p.getName().replace(' ', '_').replace(';', ':');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                buf.append(sep).append(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                sep = ";";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
        buf.append(" ").append(connectionIdNumber);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
        if (logger.traceOn())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            logger.trace("newConnectionId","connectionId="+buf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        return buf.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
    private void dropDeadReferences() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        synchronized (clientList) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
            for (Iterator it = clientList.iterator(); it.hasNext(); ) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                WeakReference wr = (WeakReference) it.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                if (wr.get() == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                    it.remove();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    synchronized NotificationBuffer getNotifBuffer() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        //Notification buffer is lazily created when the first client connects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        if(notifBuffer == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
            notifBuffer =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                ArrayNotificationBuffer.getNotificationBuffer(mbeanServer,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                                              env);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
        return notifBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    private static final ClassLogger logger =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        new ClassLogger("javax.management.remote.rmi", "RMIServerImpl");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    /** List of WeakReference values.  Each one references an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        RMIConnection created by this object, or null if the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        RMIConnection has been garbage-collected.  */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    private final List<WeakReference<RMIConnection>> clientList =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
            new ArrayList<WeakReference<RMIConnection>>();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
    private ClassLoader cl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
    private MBeanServer mbeanServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
    private final Map env;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
    private RMIConnectorServer connServer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
    private static int connectionIdNumber;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
    private NotificationBuffer notifBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
}