📄 rmiserverimpl.java
字号:
/* * @(#)RMIServerImpl.java 1.60 07/06/01 * * Copyright 2006 Sun Microsystems, Inc. All rights reserved. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */package javax.management.remote.rmi;import com.sun.jmx.remote.internal.ArrayNotificationBuffer;import com.sun.jmx.remote.internal.NotificationBuffer;import com.sun.jmx.remote.security.JMXPluggableAuthenticator;import com.sun.jmx.remote.util.ClassLogger;import java.io.Closeable;import java.io.IOException;import java.lang.ref.WeakReference;import java.rmi.Remote;import java.rmi.server.RemoteServer;import java.rmi.server.ServerNotActiveException;import java.security.Principal;import java.util.ArrayList;import java.util.Collections;import java.util.Iterator;import java.util.List;import java.util.Map;import java.util.Set;import javax.management.MBeanServer;import javax.management.remote.JMXAuthenticator;import javax.management.remote.JMXConnectorServer;import javax.security.auth.Subject;/** * <p>An RMI object representing a connector server. Remote clients * can make connections using the {@link #newClient(Object)} method. This * method returns an RMI object representing the connection.</p> * * <p>User code does not usually reference this class directly. * RMI connection servers are usually created with the class {@link * RMIConnectorServer}. Remote clients usually create connections * either with {@link javax.management.remote.JMXConnectorFactory} * or by instantiating {@link RMIConnector}.</p> * * <p>This is an abstract class. Concrete subclasses define the * details of the client connection objects, such as whether they use * JRMP or IIOP.</p> * * @since 1.5 * @since.unbundled 1.0 */public abstract class RMIServerImpl implements Closeable, RMIServer { /** * <p>Constructs a new <code>RMIServerImpl</code>.</p> * * @param env the environment containing attributes for the new * <code>RMIServerImpl</code>. Can be null, which is equivalent * to an empty Map. */ public RMIServerImpl(Map<String,?> env) { this.env = (env == null) ? Collections.EMPTY_MAP : env; } void setRMIConnectorServer(RMIConnectorServer connServer) throws IOException { this.connServer = connServer; } /** * <p>Exports this RMI object.</p> * * @exception IOException if this RMI object cannot be exported. */ protected abstract void export() throws IOException; /** * Returns a remotable stub for this server object. * @return a remotable stub. * @exception IOException if the stub cannot be obtained - e.g the * RMIServerImpl has not been exported yet. **/ public abstract Remote toStub() throws IOException; /** * <p>Sets the default <code>ClassLoader</code> for this connector * server. New client connections will use this classloader. * Existing client connections are unaffected.</p> * * @param cl the new <code>ClassLoader</code> to be used by this * connector server. * * @see #getDefaultClassLoader */ public synchronized void setDefaultClassLoader(ClassLoader cl) { this.cl = cl; } /** * <p>Gets the default <code>ClassLoader</code> used by this connector * server.</p> * * @return the default <code>ClassLoader</code> used by this * connector server.</p> * * @see #setDefaultClassLoader */ public synchronized ClassLoader getDefaultClassLoader() { return cl; } /** * <p>Sets the <code>MBeanServer</code> to which this connector * server is attached. New client connections will interact * with this <code>MBeanServer</code>. Existing client connections are * unaffected.</p> * * @param mbs the new <code>MBeanServer</code>. Can be null, but * new client connections will be refused as long as it is. * * @see #getMBeanServer */ public synchronized void setMBeanServer(MBeanServer mbs) { this.mbeanServer = mbs; } /** * <p>The <code>MBeanServer</code> to which this connector server * is attached. This is the last value passed to {@link * #setMBeanServer} on this object, or null if that method has * never been called.</p> * * @return the <code>MBeanServer</code> to which this connector * is attached. * * @see #setMBeanServer */ public synchronized MBeanServer getMBeanServer() { return mbeanServer; } public String getVersion() { // Expected format is: "protocol-version implementation-name" try { return "1.0 java_runtime_" + System.getProperty("java.runtime.version"); } catch (SecurityException e) { return "1.0 "; } } /** * <p>Creates a new client connection. This method calls {@link * #makeClient makeClient} and adds the returned client connection * object to an internal list. When this * <code>RMIServerImpl</code> is shut down via its {@link * #close()} method, the {@link RMIConnection#close() close()} * method of each object remaining in the list is called.</p> * * <p>The fact that a client connection object is in this internal * list does not prevent it from being garbage collected.</p> * * @param credentials this object specifies the user-defined * credentials to be passed in to the server in order to * authenticate the caller before creating the * <code>RMIConnection</code>. Can be null. * * @return the newly-created <code>RMIConnection</code>. This is * usually the object created by <code>makeClient</code>, though * an implementation may choose to wrap that object in another * object implementing <code>RMIConnection</code>. * * @exception IOException if the new client object cannot be * created or exported. * * @exception SecurityException if the given credentials do not allow * the server to authenticate the user successfully. * * @exception IllegalStateException if {@link #getMBeanServer()} * is null. */ public RMIConnection newClient(Object credentials) throws IOException { return doNewClient(credentials); } /** * This method could be overridden by subclasses defined in this package * to perform additional operations specific to the underlying transport * before creating the new client connection. */ RMIConnection doNewClient(Object credentials) throws IOException { final boolean tracing = logger.traceOn(); if (tracing) logger.trace("newClient","making new client"); if (getMBeanServer() == null) throw new IllegalStateException("Not attached to an MBean server"); Subject subject = null; JMXAuthenticator authenticator = (JMXAuthenticator) env.get(JMXConnectorServer.AUTHENTICATOR); if (authenticator == null) { /* * Create the JAAS-based authenticator only if authentication * has been enabled */ if (env.get("jmx.remote.x.password.file") != null || env.get("jmx.remote.x.login.config") != null) { authenticator = new JMXPluggableAuthenticator(env); } } if (authenticator != null) { if (tracing) logger.trace("newClient","got authenticator: " + authenticator.getClass().getName()); try { subject = authenticator.authenticate(credentials); } catch (SecurityException e) { logger.trace("newClient", "Authentication failed: " + e); throw e; } } if (tracing) { if (subject != null) logger.trace("newClient","subject is not null"); else logger.trace("newClient","no subject"); } final String connectionId = makeConnectionId(getProtocol(), subject); if (tracing) logger.trace("newClient","making new connection: " + connectionId); RMIConnection client = makeClient(connectionId, subject); connServer.connectionOpened(connectionId, "Connection opened", null); dropDeadReferences(); WeakReference wr = new WeakReference(client); synchronized (clientList) { clientList.add(wr); } if (tracing) logger.trace("newClient","new connection done: " + connectionId ); return client; } /** * <p>Creates a new client connection. This method is called by * the public method {@link #newClient(Object)}.</p> * * @param connectionId the ID of the new connection. Every * connection opened by this connector server will have a * different ID. The behavior is unspecified if this parameter is * null. * * @param subject the authenticated subject. Can be null. *
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -