FileDocCategorySizeDatePackage
RMIConnectionImpl.javaAPI DocJava SE 6 API62772Tue Jun 10 00:26:18 BST 2008javax.management.remote.rmi

RMIConnectionImpl

public class RMIConnectionImpl extends Object implements RMIConnection, Unreferenced

Implementation of the {@link RMIConnection} interface. User code will not usually reference this class.

since
1.5
since.unbundled
1.0

Fields Summary
private static final Object[]
NO_OBJECTS
private static final String[]
NO_STRINGS
private final Subject
subject
private final SubjectDelegator
subjectDelegator
private final boolean
removeCallerContext
private final AccessControlContext
acc
private final RMIServerImpl
rmiServer
private final MBeanServer
mbeanServer
private final ClassLoader
defaultClassLoader
private final ClassLoaderWithRepository
classLoaderWithRepository
private boolean
terminated
private final String
connectionId
private final ServerCommunicatorAdmin
serverCommunicatorAdmin
private static final int
ADD_NOTIFICATION_LISTENERS
private static final int
ADD_NOTIFICATION_LISTENER_OBJECTNAME
private static final int
CREATE_MBEAN
private static final int
CREATE_MBEAN_PARAMS
private static final int
CREATE_MBEAN_LOADER
private static final int
CREATE_MBEAN_LOADER_PARAMS
private static final int
GET_ATTRIBUTE
private static final int
GET_ATTRIBUTES
private static final int
GET_DEFAULT_DOMAIN
private static final int
GET_DOMAINS
private static final int
GET_MBEAN_COUNT
private static final int
GET_MBEAN_INFO
private static final int
GET_OBJECT_INSTANCE
private static final int
INVOKE
private static final int
IS_INSTANCE_OF
private static final int
IS_REGISTERED
private static final int
QUERY_MBEANS
private static final int
QUERY_NAMES
private static final int
REMOVE_NOTIFICATION_LISTENER
private static final int
REMOVE_NOTIFICATION_LISTENER_FILTER_HANDBACK
private static final int
REMOVE_NOTIFICATION_LISTENER_OBJECTNAME
private static final int
REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK
private static final int
SET_ATTRIBUTE
private static final int
SET_ATTRIBUTES
private static final int
UNREGISTER_MBEAN
private ServerNotifForwarder
serverNotifForwarder
private Map
env
private static final ClassLogger
logger
Constructors Summary
public RMIConnectionImpl(RMIServerImpl rmiServer, String connectionId, ClassLoader defaultClassLoader, Subject subject, Map env)
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 RMIServerImpl. Can be null, equivalent to an empty map.

	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;
    
Methods Summary
public voidaddNotificationListener(javax.management.ObjectName name, javax.management.ObjectName listener, java.rmi.MarshalledObject filter, java.rmi.MarshalledObject handback, javax.security.auth.Subject delegationSubject)


	checkNonNull("Target MBean name", name);
	checkNonNull("Listener MBean name", listener);

        final NotificationFilter filterValue;
        final Object handbackValue;
        final boolean debug=logger.debugOn();

	final ClassLoader targetCl = getClassLoaderFor(name);

	if (debug) logger.debug("addNotificationListener"+
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
                 "connectionId=" + connectionId
                 +" unwrapping filter with target extended ClassLoader.");

	filterValue =
            unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class);

	if (debug) logger.debug("addNotificationListener"+
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
                 "connectionId=" + connectionId
                 +" unwrapping handback with target extended ClassLoader.");

	handbackValue =
            unwrap(handback, targetCl, defaultClassLoader, Object.class);

        try {
            final Object params[] =
                new Object[] { name, listener, filterValue, handbackValue };

            if (debug) logger.debug("addNotificationListener"+
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
                             "connectionId=" + connectionId
                             +", name=" + name
                             +", listenerName=" + listener
                             +", filter=" + filterValue
                             +", handback=" + handbackValue);

            doPrivilegedOperation(
              ADD_NOTIFICATION_LISTENER_OBJECTNAME,
              params,
              delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public java.lang.Integer[]addNotificationListeners(javax.management.ObjectName[] names, java.rmi.MarshalledObject[] filters, javax.security.auth.Subject[] delegationSubjects)


	if (names == null || filters == null) {
	    throw new IllegalArgumentException("Got null arguments.");
	}

	Subject[] sbjs = (delegationSubjects != null) ? delegationSubjects : 
	new Subject[names.length];
	if (names.length != filters.length || filters.length != sbjs.length) {
	    final String msg = 
		"The value lengths of 3 parameters are not same.";
	    throw new IllegalArgumentException(msg);
	}

	for (int i=0; i<names.length; i++) {
	    if (names[i] == null) {
		throw new IllegalArgumentException("Null Object name.");
	    }
	}

	int i=0;
	ClassLoader targetCl;
	NotificationFilter[] filterValues = 
	new NotificationFilter[names.length];
	Object params[];
	Integer[] ids = new Integer[names.length];
	final boolean debug=logger.debugOn();
 
	try {
	    for (; i<names.length; i++) {
		targetCl = getClassLoaderFor(names[i]);

		if (debug) logger.debug("addNotificationListener"+
					"(ObjectName,NotificationFilter)",
					"connectionId=" + connectionId +
		      " unwrapping filter with target extended ClassLoader.");

		filterValues[i] =
                    unwrap(filters[i], targetCl, defaultClassLoader,
                           NotificationFilter.class);

		if (debug) logger.debug("addNotificationListener"+
					"(ObjectName,NotificationFilter)",
					"connectionId=" + connectionId
					+", name=" + names[i]
					+", filter=" + filterValues[i]);

		ids[i] = (Integer)
		    doPrivilegedOperation(ADD_NOTIFICATION_LISTENERS,
					  new Object[] { names[i], 
							 filterValues[i] },
					  sbjs[i]);
	    }

	    return ids;
	} catch (Exception e) {
	    // remove all registered listeners
	    for (int j=0; j<i; j++) {
		try {
		    getServerNotifFwd().removeNotificationListener(names[j], 
								   ids[j]);
		} catch (Exception eee) {
		    // strange
		}
	    }
		
	    if (e instanceof PrivilegedActionException) {
		e = extractException(e);
	    }

	    if (e instanceof ClassCastException) {
		throw (ClassCastException) e;
	    } else if (e instanceof IOException) {
		throw (IOException)e;
	    } else if (e instanceof InstanceNotFoundException) {
		throw (InstanceNotFoundException) e;
	    } else if (e instanceof RuntimeException) {
		throw (RuntimeException) e;
	    } else {
		throw newIOException("Got unexpected server exception: "+e,e);
	    }
	}
    
private static voidcheckNonNull(java.lang.String what, java.lang.Object x)

	if (x == null) {
	    RuntimeException wrapped =
		new IllegalArgumentException(what + " must not be null");
	    throw new RuntimeOperationsException(wrapped);
	}
    
public voidclose()

        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 javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name, javax.security.auth.Subject delegationSubject)

        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 javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name, javax.management.ObjectName loaderName, javax.security.auth.Subject delegationSubject)

        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 javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name, java.rmi.MarshalledObject params, java.lang.String[] signature, javax.security.auth.Subject delegationSubject)


        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)
                throw (NotCompliantMBeanException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public javax.management.ObjectInstancecreateMBean(java.lang.String className, javax.management.ObjectName name, javax.management.ObjectName loaderName, java.rmi.MarshalledObject params, java.lang.String[] signature, javax.security.auth.Subject delegationSubject)


        final Object[] values;
        final boolean debug = logger.debugOn();

	if (debug) logger.debug(
		 "createMBean(String,ObjectName,ObjectName,Object[],String[])",
                 "connectionId=" + connectionId 
                 +", unwrapping params with MBean extended ClassLoader.");

	values = nullIsEmpty(unwrap(params,
                                    getClassLoader(loaderName),
                                    defaultClassLoader,
                                    Object[].class));
	
        try {
            final Object params2[] =
               new Object[] { className, name, loaderName, values,
			      nullIsEmpty(signature) };

           if (debug) logger.debug(
		 "createMBean(String,ObjectName,ObjectName,Object[],String[])",
                 "connectionId=" + connectionId
                 +", className=" + className
                 +", name=" + name
                 +", loaderName=" + loaderName
                 +", params=" + objects(values)
                 +", signature=" + strings(signature));

            return (ObjectInstance)
                doPrivilegedOperation(
                  CREATE_MBEAN_LOADER_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)
                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);
        }
    
private java.lang.ObjectdoOperation(int operation, java.lang.Object[] params)


	switch (operation) {

	case CREATE_MBEAN:
	    return mbeanServer.createMBean((String)params[0],
					   (ObjectName)params[1]);

	case CREATE_MBEAN_LOADER:
	    return mbeanServer.createMBean((String)params[0],
					   (ObjectName)params[1],
					   (ObjectName)params[2]);

	case CREATE_MBEAN_PARAMS:
	    return mbeanServer.createMBean((String)params[0],
					   (ObjectName)params[1],
					   (Object[])params[2],
					   (String[])params[3]);

	case CREATE_MBEAN_LOADER_PARAMS:
	    return mbeanServer.createMBean((String)params[0],
					   (ObjectName)params[1],
					   (ObjectName)params[2],
					   (Object[])params[3],
					   (String[])params[4]);

	case GET_ATTRIBUTE:
	    return mbeanServer.getAttribute((ObjectName)params[0],
					    (String)params[1]);

	case GET_ATTRIBUTES:
	    return mbeanServer.getAttributes((ObjectName)params[0],
					     (String[])params[1]);

	case GET_DEFAULT_DOMAIN:
	    return mbeanServer.getDefaultDomain();
		
	case GET_DOMAINS:
	    return mbeanServer.getDomains();
		
	case GET_MBEAN_COUNT:
	    return mbeanServer.getMBeanCount();

	case GET_MBEAN_INFO:
	    return mbeanServer.getMBeanInfo((ObjectName)params[0]);
		
	case GET_OBJECT_INSTANCE:
	    return mbeanServer.getObjectInstance((ObjectName)params[0]);
		
	case INVOKE:
	    return mbeanServer.invoke((ObjectName)params[0],
				      (String)params[1],
				      (Object[])params[2],
				      (String[])params[3]);

	case IS_INSTANCE_OF:
	    return mbeanServer.isInstanceOf((ObjectName)params[0],
					    (String)params[1])
		? Boolean.TRUE : Boolean.FALSE;

	case IS_REGISTERED:
	    return mbeanServer.isRegistered((ObjectName)params[0])
		? Boolean.TRUE : Boolean.FALSE;

	case QUERY_MBEANS:
	    return mbeanServer.queryMBeans((ObjectName)params[0],
					   (QueryExp)params[1]);

	case QUERY_NAMES:
	    return mbeanServer.queryNames((ObjectName)params[0],
					  (QueryExp)params[1]);

	case SET_ATTRIBUTE:
	    mbeanServer.setAttribute((ObjectName)params[0],
				     (Attribute)params[1]);
	    return null;
		
	case SET_ATTRIBUTES:
	    return mbeanServer.setAttributes((ObjectName)params[0],
                                             (AttributeList)params[1]);

	case UNREGISTER_MBEAN:
	    mbeanServer.unregisterMBean((ObjectName)params[0]);
	    return null;

	case ADD_NOTIFICATION_LISTENERS:
	    return getServerNotifFwd().addNotificationListener(
						(ObjectName)params[0],
						(NotificationFilter)params[1]);
	    
	case ADD_NOTIFICATION_LISTENER_OBJECTNAME:
	    mbeanServer.addNotificationListener((ObjectName)params[0],
                                                (ObjectName)params[1],
                                                (NotificationFilter)params[2],
                                                (Object)params[3]);
	    return null;
	    
	case REMOVE_NOTIFICATION_LISTENER:
	    getServerNotifFwd().removeNotificationListener(
                                                   (ObjectName)params[0],
                                                   (Integer[])params[1]);
	    return null;

	case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME:
	    mbeanServer.removeNotificationListener((ObjectName)params[0],
                                                   (ObjectName)params[1]);
	    return null;

	case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK:
	    mbeanServer.removeNotificationListener(
                                          (ObjectName)params[0],
                                          (ObjectName)params[1],
                                          (NotificationFilter)params[2],
                                          (Object)params[3]);
	    return null;

	default:
	    throw new IllegalArgumentException("Invalid operation");
	}
    
private java.lang.ObjectdoPrivilegedOperation(int operation, java.lang.Object[] params, javax.security.auth.Subject delegationSubject)


	serverCommunicatorAdmin.reqIncoming();
	try {

	    final AccessControlContext reqACC;
	    if (delegationSubject == null)
		reqACC = acc;
	    else {
		if (subject == null) {
		    final String msg =
			"Subject delegation cannot be enabled unless " +
			"an authenticated subject is put in place";
		    throw new SecurityException(msg);
		}
		reqACC = subjectDelegator.delegatedContext(
                    acc, delegationSubject, removeCallerContext);
	    }

	    PrivilegedOperation op =
		new PrivilegedOperation(operation, params);
	    if (reqACC == null) {
		try {
		    return op.run();
		} catch (Exception e) {
		    if (e instanceof RuntimeException)
			throw (RuntimeException) e;
		    throw new PrivilegedActionException(e);
		}
	    } else {
		return AccessController.doPrivileged(op, reqACC);
	    }
	} catch (Error e) {
	    throw new JMXServerErrorException(e.toString(),e);
	} finally {
	    serverCommunicatorAdmin.rspOutgoing();
	}
    
private static java.lang.ExceptionextractException(java.lang.Exception e)
Iterate until we extract the real exception from a stack of PrivilegedActionExceptions.

        while (e instanceof PrivilegedActionException) {
            e = ((PrivilegedActionException)e).getException(); 
        }
        return e;
    
public javax.management.remote.NotificationResultfetchNotifications(long clientSequenceNumber, int maxNotifications, long timeout)


        if (logger.debugOn()) logger.debug("fetchNotifications",
                               "connectionId=" + connectionId
                               +", timeout=" + timeout);

	if (maxNotifications < 0 || timeout < 0)
	    throw new IllegalArgumentException("Illegal negative argument");

	final boolean serverTerminated = 
	    serverCommunicatorAdmin.reqIncoming();
	try {
	    if (serverTerminated) {
		// we must not call fetchNotifs() if the server is 
		// terminated (timeout elapsed).
		//
		return new NotificationResult(0L, 0L,
					      new TargetedNotification[0]);

	    }
            final long csn = clientSequenceNumber;
            final int mn = maxNotifications;
            final long t = timeout;
            PrivilegedAction<NotificationResult> action =
                new PrivilegedAction<NotificationResult>() {
                    public NotificationResult run() {
                        return getServerNotifFwd().fetchNotifs(csn, t, mn);
                    }
            };
            if (acc == null)
                return action.run();
            else
                return AccessController.doPrivileged(action, acc);
	} finally {
	    serverCommunicatorAdmin.rspOutgoing();
	}
    
public java.lang.ObjectgetAttribute(javax.management.ObjectName name, java.lang.String attribute, javax.security.auth.Subject delegationSubject)

        try {
            final Object params[] = new Object[] { name, attribute };
            if (logger.debugOn()) logger.debug("getAttribute",
                                   "connectionId=" + connectionId
                                   +", name=" + name 
                                   +", attribute="+ attribute);

            return (Object)
                doPrivilegedOperation(
                  GET_ATTRIBUTE,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof MBeanException)
                throw (MBeanException) e;
            if (e instanceof AttributeNotFoundException)
                throw (AttributeNotFoundException) e;
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof ReflectionException)
                throw (ReflectionException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public javax.management.AttributeListgetAttributes(javax.management.ObjectName name, java.lang.String[] attributes, javax.security.auth.Subject delegationSubject)

        try {
            final Object params[] = new Object[] { name, attributes };

            if (logger.debugOn()) logger.debug("getAttributes",
                                   "connectionId=" + connectionId
                                   +", name=" + name 
                                   +", attributes="+ strings(attributes));

            return (AttributeList)
                doPrivilegedOperation(
                  GET_ATTRIBUTES,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof ReflectionException)
                throw (ReflectionException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
private java.lang.ClassLoadergetClassLoader(javax.management.ObjectName name)

        try {
            return (ClassLoader)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                        public Object run() throws InstanceNotFoundException {
                            return mbeanServer.getClassLoader(name);
                        }
                    });
        } catch (PrivilegedActionException pe) {
            throw (InstanceNotFoundException) extractException(pe);
        }
    
private java.lang.ClassLoadergetClassLoaderFor(javax.management.ObjectName name)

        try {
            return (ClassLoader)
                AccessController.doPrivileged(new PrivilegedExceptionAction() {
                        public Object run() throws InstanceNotFoundException {
                            return mbeanServer.getClassLoaderFor(name);
                        }
                    });
        } catch (PrivilegedActionException pe) {
            throw (InstanceNotFoundException) extractException(pe);
        }
    
private javax.management.loading.ClassLoaderRepositorygetClassLoaderRepository()

        return (ClassLoaderRepository)
            AccessController.doPrivileged(new PrivilegedAction() {
                    public Object run() {
                        return mbeanServer.getClassLoaderRepository();
                    }
                });
    
public java.lang.StringgetConnectionId()

	// We should call reqIncomming() here... shouldn't we?
	return connectionId;
    
public java.lang.StringgetDefaultDomain(javax.security.auth.Subject delegationSubject)

        try {
            final Object params[] = new Object[] { };

            if (logger.debugOn())  logger.debug("getDefaultDomain",
                                    "connectionId=" + connectionId);

            return (String)
                doPrivilegedOperation(
                  GET_DEFAULT_DOMAIN,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public java.lang.String[]getDomains(javax.security.auth.Subject delegationSubject)

        try {
            final Object params[] = new Object[] { };

            if (logger.debugOn())  logger.debug("getDomains",
                                    "connectionId=" + connectionId);

            return (String[])
                doPrivilegedOperation(
                  GET_DOMAINS,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public java.lang.IntegergetMBeanCount(javax.security.auth.Subject delegationSubject)

        try {
            final Object params[] = new Object[] { };

            if (logger.debugOn()) logger.debug("getMBeanCount",
                 "connectionId=" + connectionId);

            return (Integer)
                doPrivilegedOperation(
                  GET_MBEAN_COUNT,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public javax.management.MBeanInfogetMBeanInfo(javax.management.ObjectName name, javax.security.auth.Subject delegationSubject)


	checkNonNull("ObjectName", name);

        try {
            final Object params[] = new Object[] { name };

            if (logger.debugOn())  logger.debug("getMBeanInfo",
                                    "connectionId=" + connectionId
                                    +", name="+name);

            return (MBeanInfo)
                doPrivilegedOperation(
                  GET_MBEAN_INFO,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof IntrospectionException)
                throw (IntrospectionException) e;
            if (e instanceof ReflectionException)
                throw (ReflectionException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public javax.management.ObjectInstancegetObjectInstance(javax.management.ObjectName name, javax.security.auth.Subject delegationSubject)


	checkNonNull("ObjectName", name);

        try {
            final Object params[] = new Object[] { name };

            if (logger.debugOn()) logger.debug("getObjectInstance",
                 "connectionId=" + connectionId
                 +", name="+name);

            return (ObjectInstance)
                doPrivilegedOperation(
                  GET_OBJECT_INSTANCE,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
private synchronized com.sun.jmx.remote.internal.ServerNotifForwardergetServerNotifFwd()

        // 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 java.lang.Objectinvoke(javax.management.ObjectName name, java.lang.String operationName, java.rmi.MarshalledObject params, java.lang.String[] signature, javax.security.auth.Subject delegationSubject)


	checkNonNull("ObjectName", name);
	checkNonNull("Operation name", operationName);

        final Object[] values;
        final boolean debug=logger.debugOn();

	if (debug) logger.debug("invoke",
                 "connectionId=" + connectionId
                 +" unwrapping params with MBean extended ClassLoader.");

	values = nullIsEmpty(unwrap(params,
                                    getClassLoaderFor(name), 
                                    defaultClassLoader,
                                    Object[].class));

        try {
            final Object params2[] =
                new Object[] { name, operationName, values,
			       nullIsEmpty(signature) };

            if (debug) logger.debug("invoke",
                             "connectionId=" + connectionId
                             +", name="+name
                             +", operationName="+operationName
                             +", params="+objects(values)
                             +", signature="+strings(signature));

            return (Object)
                doPrivilegedOperation(
                  INVOKE,
                  params2,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof MBeanException)
                throw (MBeanException) e;
            if (e instanceof ReflectionException)
                throw (ReflectionException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public booleanisInstanceOf(javax.management.ObjectName name, java.lang.String className, javax.security.auth.Subject delegationSubject)


	checkNonNull("ObjectName", name);

        try {
            final Object params[] = new Object[] { name, className };

            if (logger.debugOn())  logger.debug("isInstanceOf",
                                    "connectionId=" + connectionId
                                    +", name="+name
                                    +", className="+className);

            return ((Boolean)
                doPrivilegedOperation(
                  IS_INSTANCE_OF,
                  params,
                  delegationSubject)).booleanValue();
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public booleanisRegistered(javax.management.ObjectName name, javax.security.auth.Subject delegationSubject)

        try {
            final Object params[] = new Object[] { name };
            return ((Boolean)
                doPrivilegedOperation(
                  IS_REGISTERED,
                  params,
                  delegationSubject)).booleanValue();
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
private static java.io.IOExceptionnewIOException(java.lang.String message, java.lang.Throwable cause)
Construct a new IOException with a nested exception. The nested exception is set only if JDK >= 1.4

        final IOException x = new IOException(message);
        return EnvHelp.initCause(x,cause);
    
private static java.lang.Object[]nullIsEmpty(java.lang.Object[] array)


    /*
     * The JMX spec doesn't explicitly say that a null Object[] or
     * String[] in e.g. MBeanServer.invoke is equivalent to an empty
     * array, but the RI behaves that way.  In the interests of
     * maximal interoperability, we make it so even when we're
     * connected to some other JMX implementation that might not do
     * that.  This should be clarified in the next version of JMX.
     */
         
	return (array == null) ? NO_OBJECTS : array;
    
private static java.lang.String[]nullIsEmpty(java.lang.String[] array)

	return (array == null) ? NO_STRINGS : array;
    
private static java.lang.Stringobjects(java.lang.Object[] objs)

    
    // TRACES & DEBUG
    //---------------

          
        if (objs == null)
            return "null";
        else
            return Arrays.asList(objs).toString();
    
public java.util.SetqueryMBeans(javax.management.ObjectName name, java.rmi.MarshalledObject query, javax.security.auth.Subject delegationSubject)

        final QueryExp queryValue;
        final boolean debug=logger.debugOn();

	if (debug) logger.debug("queryMBeans",
                 "connectionId=" + connectionId
                 +" unwrapping query with defaultClassLoader.");

	queryValue = unwrap(query, defaultClassLoader, QueryExp.class);

        try {
            final Object params[] = new Object[] { name, queryValue };

            if (debug) logger.debug("queryMBeans",
                 "connectionId=" + connectionId
                 +", name="+name +", query="+query);

            return (Set)
                doPrivilegedOperation(
                  QUERY_MBEANS,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public java.util.SetqueryNames(javax.management.ObjectName name, java.rmi.MarshalledObject query, javax.security.auth.Subject delegationSubject)

        final QueryExp queryValue;
        final boolean debug=logger.debugOn();

	if (debug) logger.debug("queryNames",
                 "connectionId=" + connectionId
                 +" unwrapping query with defaultClassLoader.");

	queryValue = unwrap(query, defaultClassLoader, QueryExp.class);

        try {
            final Object params[] = new Object[] { name, queryValue };

            if (debug) logger.debug("queryNames",
                 "connectionId=" + connectionId
                 +", name="+name +", query="+query);

            return (Set)
                doPrivilegedOperation(
                  QUERY_NAMES,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public voidremoveNotificationListener(javax.management.ObjectName name, javax.management.ObjectName listener, javax.security.auth.Subject delegationSubject)


	checkNonNull("Target MBean name", name);
	checkNonNull("Listener MBean name", listener);

        try {
            final Object params[] = new Object[] { name, listener };

            if (logger.debugOn()) logger.debug("removeNotificationListener"+
                                   "(ObjectName,ObjectName)",
                                   "connectionId=" + connectionId
                                   +", name=" + name
                                   +", listenerName=" + listener);

            doPrivilegedOperation(
              REMOVE_NOTIFICATION_LISTENER_OBJECTNAME,
              params,
              delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof ListenerNotFoundException)
                throw (ListenerNotFoundException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public voidremoveNotificationListener(javax.management.ObjectName name, javax.management.ObjectName listener, java.rmi.MarshalledObject filter, java.rmi.MarshalledObject handback, javax.security.auth.Subject delegationSubject)


	checkNonNull("Target MBean name", name);
	checkNonNull("Listener MBean name", listener);

        final NotificationFilter filterValue;
        final Object handbackValue;
        final boolean debug=logger.debugOn();

	final ClassLoader targetCl = getClassLoaderFor(name);

	if (debug) logger.debug("removeNotificationListener"+
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
                 "connectionId=" + connectionId
                 +" unwrapping filter with target extended ClassLoader.");

	filterValue =
            unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class);

	if (debug) logger.debug("removeNotificationListener"+
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
                 "connectionId=" + connectionId
                 +" unwrapping handback with target extended ClassLoader.");

	handbackValue =
            unwrap(handback, targetCl, defaultClassLoader, Object.class);

        try {
            final Object params[] =
                new Object[] { name, listener, filterValue, handbackValue };

            if (debug) logger.debug("removeNotificationListener"+
                 "(ObjectName,ObjectName,NotificationFilter,Object)",
                             "connectionId=" + connectionId
                             +", name=" + name
                             +", listenerName=" + listener
                             +", filter=" + filterValue
                             +", handback=" + handbackValue);

            doPrivilegedOperation(
              REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK,
              params,
              delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof ListenerNotFoundException)
                throw (ListenerNotFoundException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public voidremoveNotificationListeners(javax.management.ObjectName name, java.lang.Integer[] listenerIDs, javax.security.auth.Subject delegationSubject)


	if (name == null || listenerIDs == null)
	    throw new IllegalArgumentException("Illegal null parameter");

	for (int i = 0; i < listenerIDs.length; i++) {
	    if (listenerIDs[i] == null)
		throw new IllegalArgumentException("Null listener ID");
	}

        try {
            final Object params[] = new Object[] { name, listenerIDs };

            if (logger.debugOn()) logger.debug("removeNotificationListener"+
                                   "(ObjectName,Integer[])",
                                   "connectionId=" + connectionId
                                   +", name=" + name
                                   +", listenerIDs=" + objects(listenerIDs));

            doPrivilegedOperation(
              REMOVE_NOTIFICATION_LISTENER,
              params,
              delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof ListenerNotFoundException)
                throw (ListenerNotFoundException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public voidsetAttribute(javax.management.ObjectName name, java.rmi.MarshalledObject attribute, javax.security.auth.Subject delegationSubject)

        final Attribute attr;
        final boolean debug=logger.debugOn();

	if (debug) logger.debug("setAttribute",
                 "connectionId=" + connectionId
                 +" unwrapping attribute with MBean extended ClassLoader.");

	attr = unwrap(attribute,
		      getClassLoaderFor(name),
		      defaultClassLoader,
                      Attribute.class);

        try {
            final Object params[] = new Object[] { name, attr };

            if (debug) logger.debug("setAttribute",
                             "connectionId=" + connectionId
                             +", name="+name
                             +", attribute="+attr);

            doPrivilegedOperation(
              SET_ATTRIBUTE,
              params,
              delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof AttributeNotFoundException)
                throw (AttributeNotFoundException) e;
            if (e instanceof InvalidAttributeValueException)
                throw (InvalidAttributeValueException) e;
            if (e instanceof MBeanException)
                throw (MBeanException) e;
            if (e instanceof ReflectionException)
                throw (ReflectionException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
public javax.management.AttributeListsetAttributes(javax.management.ObjectName name, java.rmi.MarshalledObject attributes, javax.security.auth.Subject delegationSubject)

        final AttributeList attrlist;
        final boolean debug=logger.debugOn();

	if (debug) logger.debug("setAttributes",
                 "connectionId=" + connectionId
                 +" unwrapping attributes with MBean extended ClassLoader.");

	attrlist =
	    unwrap(attributes,
		   getClassLoaderFor(name),
		   defaultClassLoader,
                   AttributeList.class);

        try {
            final Object params[] = new Object[] { name, attrlist };

            if (debug) logger.debug("setAttributes",
                             "connectionId=" + connectionId
                             +", name="+name
                             +", attributes="+attrlist);

            return (AttributeList)
                doPrivilegedOperation(
                  SET_ATTRIBUTES,
                  params,
                  delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof ReflectionException)
                throw (ReflectionException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
private static java.lang.Stringstrings(java.lang.String[] strs)

	return objects(strs);
    
public java.lang.StringtoString()

Returns a string representation of this object. In general, the toString method returns a string that "textually represents" this object. The result should be a concise but informative representation that is easy for a person to read.

return
a String representation of this object.

        return super.toString() + ": connectionId=" + connectionId;
    
public voidunreferenced()

        logger.debug("unreferenced", "called");
        try {
            close();
            logger.debug("unreferenced", "done");
        } catch (IOException e) {
            logger.fine("unreferenced", e);
        }
    
public voidunregisterMBean(javax.management.ObjectName name, javax.security.auth.Subject delegationSubject)

        try {
            final Object params[] = new Object[] { name };

            if (logger.debugOn()) logger.debug("unregisterMBean",
                 "connectionId=" + connectionId
                 +", name="+name);

            doPrivilegedOperation(
              UNREGISTER_MBEAN,
              params,
              delegationSubject);
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof InstanceNotFoundException)
                throw (InstanceNotFoundException) e;
            if (e instanceof MBeanRegistrationException)
                throw (MBeanRegistrationException) e;
            if (e instanceof IOException)
                throw (IOException) e;
            throw newIOException("Got unexpected server exception: " + e, e);
        }
    
private static Tunwrap(java.rmi.MarshalledObject mo, java.lang.ClassLoader cl, java.lang.Class wrappedClass)

        if (mo == null) {
            return null;
        }
        try {
            return AccessController.doPrivileged(
		new PrivilegedExceptionAction<T>() {
                    public T run()
			    throws IOException {
                        final ClassLoader old =
                            Thread.currentThread().getContextClassLoader();
                        Thread.currentThread().setContextClassLoader(cl);
                        try {
			    return wrappedClass.cast(mo.get());
			} catch (ClassNotFoundException cnfe) {
			    throw new UnmarshalException(cnfe.toString(), cnfe);
                        } finally {
                            Thread.currentThread().setContextClassLoader(old);
                        }
                    }
                });
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof IOException) {
                throw (IOException) e;
            }
            if (e instanceof ClassNotFoundException) {
		throw new UnmarshalException(e.toString(), e);
            }
	    logger.warning("unwrap", "Failed to unmarshall object: " + e);
	    logger.debug("unwrap", e);
        }
        return null;
    
private static Tunwrap(java.rmi.MarshalledObject mo, java.lang.ClassLoader cl1, java.lang.ClassLoader cl2, java.lang.Class wrappedClass)

        if (mo == null) {
            return null;
        }
        try {
            return AccessController.doPrivileged(
                   new PrivilegedExceptionAction<T>() {
                       public T run()
                           throws IOException {
                           return unwrap(mo, new OrderClassLoaders(cl1, cl2),
                                         wrappedClass);
                       }
                   });
        } catch (PrivilegedActionException pe) {
            Exception e = extractException(pe);
            if (e instanceof IOException) {
                throw (IOException) e;
            }
            if (e instanceof ClassNotFoundException) {
                throw new UnmarshalException(e.toString(), e);
            }
	    logger.warning("unwrap", "Failed to unmarshall object: " + e);
	    logger.debug("unwrap", e);
        }
        return null;