⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rmiconnectionimpl.java

📁 java1.6众多例子参考
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/* * @(#)RMIConnectionImpl.java	1.94 06/09/29 * * 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.ServerCommunicatorAdmin;import com.sun.jmx.remote.internal.ServerNotifForwarder;import com.sun.jmx.remote.internal.Unmarshal;import com.sun.jmx.remote.security.JMXSubjectDomainCombiner;import com.sun.jmx.remote.security.SubjectDelegator;import com.sun.jmx.remote.util.ClassLoaderWithRepository;import com.sun.jmx.remote.util.ClassLogger;import com.sun.jmx.remote.util.EnvHelp;import com.sun.jmx.remote.util.OrderClassLoaders;import java.io.IOException;import java.rmi.MarshalledObject;import java.rmi.UnmarshalException;import java.rmi.server.Unreferenced;import java.security.AccessControlContext;import java.security.AccessController;import java.security.PrivilegedAction;import java.security.PrivilegedActionException;import java.security.PrivilegedExceptionAction;import java.security.ProtectionDomain;import java.util.Arrays;import java.util.Collections;import java.util.Map;import java.util.Set;import javax.management.Attribute;import javax.management.AttributeList;import javax.management.AttributeNotFoundException;import javax.management.InstanceAlreadyExistsException;import javax.management.InstanceNotFoundException;import javax.management.IntrospectionException;import javax.management.InvalidAttributeValueException;import javax.management.ListenerNotFoundException;import javax.management.MBeanException;import javax.management.MBeanInfo;import javax.management.MBeanRegistrationException;import javax.management.MBeanServer;import javax.management.NotCompliantMBeanException;import javax.management.NotificationFilter;import javax.management.ObjectInstance;import javax.management.ObjectName;import javax.management.QueryExp;import javax.management.ReflectionException;import javax.management.RuntimeOperationsException;import javax.management.loading.ClassLoaderRepository;import javax.management.remote.JMXServerErrorException;import javax.management.remote.NotificationResult;import javax.management.remote.TargetedNotification;import javax.security.auth.Subject;/** * <p>Implementation of the {@link RMIConnection} interface.  User * code will not usually reference this class.</p> * * @since 1.5 * @since.unbundled 1.0 *//* * Notice that we omit the type parameter from MarshalledObject everywhere, * even though it would add useful information to the documentation.  The * reason is that it was only added in Mustang (Java SE 6), whereas versions * 1.4 and 2.0 of the JMX API must be implementable on Tiger per our * commitments for JSR 255. */public class RMIConnectionImpl implements RMIConnection, Unreferenced {    /**     * Constructs a new {@link RMIConnection}. This connection can be     * used with either the JRMP or IIOP transport. This object does     * not export itself: it is the responsibility of the caller to     * export it appropriately (see {@link     * RMIJRMPServerImpl#makeClient(String,Subject)} and {@link     * RMIIIOPServerImpl#makeClient(String,Subject)}.     *     * @param rmiServer The RMIServerImpl object for which this     * connection is created.  The behavior is unspecified if this     * parameter is null.     * @param connectionId The ID for this connection.  The behavior     * is unspecified if this parameter is null.     * @param defaultClassLoader The default ClassLoader to be used     * when deserializing marshalled objects.  Can be null, to signify     * the bootstrap class loader.     * @param subject the authenticated subject to be used for     * authorization.  Can be null, to signify that no subject has     * been authenticated.     * @param env the environment containing attributes for the new     * <code>RMIServerImpl</code>.  Can be null, equivalent to an     * empty map.     */    public RMIConnectionImpl(RMIServerImpl rmiServer,                             String connectionId,                             ClassLoader defaultClassLoader,                             Subject subject,			     Map<String,?> env) {	if (rmiServer == null || connectionId == null)	    throw new NullPointerException("Illegal null argument");	if (env == null)	    env = Collections.EMPTY_MAP;        this.rmiServer = rmiServer;        this.connectionId = connectionId;        this.defaultClassLoader = defaultClassLoader;        this.subjectDelegator = new SubjectDelegator();        this.subject = subject;        if (subject == null) {            this.acc = null;            this.removeCallerContext = false;        } else {            this.removeCallerContext =                SubjectDelegator.checkRemoveCallerContext(subject);            if (this.removeCallerContext) {                this.acc =                    JMXSubjectDomainCombiner.getDomainCombinerContext(subject);            } else {                this.acc =                    JMXSubjectDomainCombiner.getContext(subject);            }        }        this.mbeanServer = rmiServer.getMBeanServer();        final ClassLoader dcl = defaultClassLoader;        this.classLoaderWithRepository = (ClassLoaderWithRepository)            AccessController.doPrivileged(new PrivilegedAction() {                    public Object run() {                        return new ClassLoaderWithRepository(                                              getClassLoaderRepository(),                                              dcl);                    }                });	serverCommunicatorAdmin = new 	  RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env));	this.env = env;    }    private synchronized ServerNotifForwarder getServerNotifFwd() {        // Lazily created when first use. Mainly when        // addNotificationListener is first called.        if (serverNotifForwarder == null)            serverNotifForwarder =                new ServerNotifForwarder(mbeanServer,                                         env,                                         rmiServer.getNotifBuffer(),                                         connectionId);        return serverNotifForwarder;    }    public String getConnectionId() throws IOException {	// We should call reqIncomming() here... shouldn't we?	return connectionId;    }    public void close() throws IOException {        final boolean debug = logger.debugOn();        final String  idstr = (debug?"["+this.toString()+"]":null);	synchronized(this) {	    if (terminated) {		if (debug) logger.debug("close",idstr + " already terminated.");		return;	    }	    if (debug) logger.debug("close",idstr + " closing.");	    terminated = true;	    if (serverCommunicatorAdmin != null) {		serverCommunicatorAdmin.terminate();	    }	    if (serverNotifForwarder != null) {		serverNotifForwarder.terminate();	    }	}        rmiServer.clientClosed(this);        if (debug) logger.debug("close",idstr + " closed.");    }    public void unreferenced() {        logger.debug("unreferenced", "called");        try {            close();            logger.debug("unreferenced", "done");        } catch (IOException e) {            logger.fine("unreferenced", e);        }    }    //-------------------------------------------------------------------------    // MBeanServerConnection Wrapper    //-------------------------------------------------------------------------    public ObjectInstance createMBean(String className,                                      ObjectName name,                                      Subject delegationSubject)        throws        ReflectionException,        InstanceAlreadyExistsException,        MBeanRegistrationException,        MBeanException,        NotCompliantMBeanException,        IOException {        try {            final Object params[] =                new Object[] { className, name };            if (logger.debugOn()) 		logger.debug("createMBean(String,ObjectName)",			     "connectionId=" + connectionId +", className=" + 			     className+", name=" + name);            return (ObjectInstance)                doPrivilegedOperation(                  CREATE_MBEAN,                  params,                  delegationSubject);        } catch (PrivilegedActionException pe) {            Exception e = extractException(pe);            if (e instanceof ReflectionException)                throw (ReflectionException) e;            if (e instanceof InstanceAlreadyExistsException)                throw (InstanceAlreadyExistsException) e;            if (e instanceof MBeanRegistrationException)                throw (MBeanRegistrationException) e;            if (e instanceof MBeanException)                throw (MBeanException) e;            if (e instanceof NotCompliantMBeanException)                throw (NotCompliantMBeanException) e;            if (e instanceof IOException)                throw (IOException) e;            throw newIOException("Got unexpected server exception: " + e, e);        }    }    public ObjectInstance createMBean(String className,                                      ObjectName name,                                      ObjectName loaderName,                                      Subject delegationSubject)        throws        ReflectionException,        InstanceAlreadyExistsException,        MBeanRegistrationException,        MBeanException,        NotCompliantMBeanException,        InstanceNotFoundException,        IOException {        try {            final Object params[] =                new Object[] { className, name, loaderName };            if (logger.debugOn())		logger.debug("createMBean(String,ObjectName,ObjectName)",		      "connectionId=" + connectionId		      +", className=" + className		      +", name=" + name		      +", loaderName=" + loaderName);            return (ObjectInstance)                doPrivilegedOperation(                  CREATE_MBEAN_LOADER,                  params,                  delegationSubject);        } catch (PrivilegedActionException pe) {            Exception e = extractException(pe);            if (e instanceof ReflectionException)                throw (ReflectionException) e;            if (e instanceof InstanceAlreadyExistsException)                throw (InstanceAlreadyExistsException) e;            if (e instanceof MBeanRegistrationException)                throw (MBeanRegistrationException) e;            if (e instanceof MBeanException)                throw (MBeanException) e;            if (e instanceof NotCompliantMBeanException)                throw (NotCompliantMBeanException) e;            if (e instanceof InstanceNotFoundException)                throw (InstanceNotFoundException) e;            if (e instanceof IOException)                throw (IOException) e;            throw newIOException("Got unexpected server exception: " + e, e);        }    }    public ObjectInstance createMBean(String className,                                      ObjectName name,                                      MarshalledObject params,                                      String signature[],                                      Subject delegationSubject)        throws        ReflectionException,        InstanceAlreadyExistsException,        MBeanRegistrationException,        MBeanException,        NotCompliantMBeanException,        IOException {        final Object[] values;        final boolean debug = logger.debugOn();	if (debug) logger.debug(		  "createMBean(String,ObjectName,Object[],String[])",                  "connectionId=" + connectionId                   +", unwrapping parameters using classLoaderWithRepository.");	values =            nullIsEmpty(unwrap(params, classLoaderWithRepository, Object[].class));        try {            final Object params2[] =                new Object[] { className, name, values,			       nullIsEmpty(signature) };            if (debug)                logger.debug("createMBean(String,ObjectName,Object[],String[])",                             "connectionId=" + connectionId                             +", className=" + className                             +", name=" + name                             +", params=" + objects(values)                             +", signature=" + strings(signature));            return (ObjectInstance)                doPrivilegedOperation(                  CREATE_MBEAN_PARAMS,                  params2,                  delegationSubject);        } catch (PrivilegedActionException pe) {            Exception e = extractException(pe);            if (e instanceof ReflectionException)                throw (ReflectionException) e;            if (e instanceof InstanceAlreadyExistsException)                throw (InstanceAlreadyExistsException) e;            if (e instanceof MBeanRegistrationException)                throw (MBeanRegistrationException) e;            if (e instanceof MBeanException)                throw (MBeanException) e;            if (e instanceof NotCompliantMBeanException)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -