0N/A/*
5410N/A * Copyright (c) 2002, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage javax.management.remote.rmi;
0N/A
0N/Aimport static com.sun.jmx.mbeanserver.Util.cast;
0N/Aimport com.sun.jmx.remote.internal.ServerCommunicatorAdmin;
0N/Aimport com.sun.jmx.remote.internal.ServerNotifForwarder;
0N/Aimport com.sun.jmx.remote.security.JMXSubjectDomainCombiner;
0N/Aimport com.sun.jmx.remote.security.SubjectDelegator;
0N/Aimport com.sun.jmx.remote.util.ClassLoaderWithRepository;
0N/Aimport com.sun.jmx.remote.util.ClassLogger;
0N/Aimport com.sun.jmx.remote.util.EnvHelp;
0N/Aimport com.sun.jmx.remote.util.OrderClassLoaders;
0N/A
0N/Aimport java.io.IOException;
0N/Aimport java.rmi.MarshalledObject;
0N/Aimport java.rmi.UnmarshalException;
0N/Aimport java.rmi.server.Unreferenced;
5410N/A
0N/Aimport java.security.AccessControlContext;
0N/Aimport java.security.AccessController;
5410N/Aimport java.security.Permission;
5410N/Aimport java.security.PermissionCollection;
5410N/Aimport java.security.Permissions;
0N/Aimport java.security.PrivilegedAction;
0N/Aimport java.security.PrivilegedActionException;
0N/Aimport java.security.PrivilegedExceptionAction;
5410N/Aimport java.security.ProtectionDomain;
5410N/A
0N/Aimport java.util.Arrays;
0N/Aimport java.util.Collections;
0N/Aimport java.util.Map;
0N/Aimport java.util.Set;
0N/A
0N/Aimport javax.management.Attribute;
0N/Aimport javax.management.AttributeList;
0N/Aimport javax.management.AttributeNotFoundException;
0N/Aimport javax.management.InstanceAlreadyExistsException;
0N/Aimport javax.management.InstanceNotFoundException;
0N/Aimport javax.management.IntrospectionException;
0N/Aimport javax.management.InvalidAttributeValueException;
0N/Aimport javax.management.ListenerNotFoundException;
0N/Aimport javax.management.MBeanException;
0N/Aimport javax.management.MBeanInfo;
0N/Aimport javax.management.MBeanRegistrationException;
5410N/Aimport javax.management.MBeanPermission;
0N/Aimport javax.management.MBeanServer;
0N/Aimport javax.management.NotCompliantMBeanException;
0N/Aimport javax.management.NotificationFilter;
0N/Aimport javax.management.ObjectInstance;
0N/Aimport javax.management.ObjectName;
0N/Aimport javax.management.QueryExp;
0N/Aimport javax.management.ReflectionException;
0N/Aimport javax.management.RuntimeOperationsException;
0N/Aimport javax.management.remote.JMXServerErrorException;
0N/Aimport javax.management.remote.NotificationResult;
0N/Aimport javax.management.remote.TargetedNotification;
0N/Aimport javax.security.auth.Subject;
6281N/Aimport sun.reflect.misc.ReflectUtil;
0N/A
0N/A/**
0N/A * <p>Implementation of the {@link RMIConnection} interface. User
0N/A * code will not usually reference this class.</p>
0N/A *
0N/A * @since 1.5
0N/A */
0N/A/*
0N/A * Notice that we omit the type parameter from MarshalledObject everywhere,
0N/A * even though it would add useful information to the documentation. The
0N/A * reason is that it was only added in Mustang (Java SE 6), whereas versions
0N/A * 1.4 and 2.0 of the JMX API must be implementable on Tiger per our
0N/A * commitments for JSR 255.
0N/A */
0N/Apublic class RMIConnectionImpl implements RMIConnection, Unreferenced {
0N/A
0N/A /**
0N/A * Constructs a new {@link RMIConnection}. This connection can be
0N/A * used with either the JRMP or IIOP transport. This object does
0N/A * not export itself: it is the responsibility of the caller to
0N/A * export it appropriately (see {@link
0N/A * RMIJRMPServerImpl#makeClient(String,Subject)} and {@link
0N/A * RMIIIOPServerImpl#makeClient(String,Subject)}.
0N/A *
0N/A * @param rmiServer The RMIServerImpl object for which this
0N/A * connection is created. The behavior is unspecified if this
0N/A * parameter is null.
0N/A * @param connectionId The ID for this connection. The behavior
0N/A * is unspecified if this parameter is null.
0N/A * @param defaultClassLoader The default ClassLoader to be used
0N/A * when deserializing marshalled objects. Can be null, to signify
0N/A * the bootstrap class loader.
0N/A * @param subject the authenticated subject to be used for
0N/A * authorization. Can be null, to signify that no subject has
0N/A * been authenticated.
0N/A * @param env the environment containing attributes for the new
0N/A * <code>RMIServerImpl</code>. Can be null, equivalent to an
0N/A * empty map.
0N/A */
0N/A public RMIConnectionImpl(RMIServerImpl rmiServer,
0N/A String connectionId,
0N/A ClassLoader defaultClassLoader,
0N/A Subject subject,
0N/A Map<String,?> env) {
0N/A if (rmiServer == null || connectionId == null)
0N/A throw new NullPointerException("Illegal null argument");
0N/A if (env == null)
0N/A env = Collections.emptyMap();
0N/A this.rmiServer = rmiServer;
0N/A this.connectionId = connectionId;
0N/A this.defaultClassLoader = defaultClassLoader;
0N/A
0N/A this.subjectDelegator = new SubjectDelegator();
0N/A this.subject = subject;
0N/A if (subject == null) {
0N/A this.acc = null;
0N/A this.removeCallerContext = false;
0N/A } else {
0N/A this.removeCallerContext =
0N/A SubjectDelegator.checkRemoveCallerContext(subject);
0N/A if (this.removeCallerContext) {
0N/A this.acc =
0N/A JMXSubjectDomainCombiner.getDomainCombinerContext(subject);
0N/A } else {
0N/A this.acc =
0N/A JMXSubjectDomainCombiner.getContext(subject);
0N/A }
0N/A }
0N/A this.mbeanServer = rmiServer.getMBeanServer();
0N/A
0N/A final ClassLoader dcl = defaultClassLoader;
5410N/A
0N/A this.classLoaderWithRepository =
0N/A AccessController.doPrivileged(
0N/A new PrivilegedAction<ClassLoaderWithRepository>() {
0N/A public ClassLoaderWithRepository run() {
0N/A return new ClassLoaderWithRepository(
469N/A mbeanServer.getClassLoaderRepository(),
469N/A dcl);
0N/A }
5410N/A },
5410N/A
5410N/A withPermissions( new MBeanPermission("*", "getClassLoaderRepository"),
5410N/A new RuntimePermission("createClassLoader"))
5410N/A );
5410N/A
5439N/A
5439N/A this.defaultContextClassLoader =
5439N/A AccessController.doPrivileged(
5439N/A new PrivilegedAction<ClassLoader>() {
5439N/A @Override
5439N/A public ClassLoader run() {
5439N/A return new CombinedClassLoader(Thread.currentThread().getContextClassLoader(),
5439N/A dcl);
5439N/A }
5439N/A });
5439N/A
0N/A serverCommunicatorAdmin = new
0N/A RMIServerCommunicatorAdmin(EnvHelp.getServerConnectionTimeout(env));
0N/A
0N/A this.env = env;
0N/A }
0N/A
5410N/A private static AccessControlContext withPermissions(Permission ... perms){
5410N/A Permissions col = new Permissions();
5410N/A
5410N/A for (Permission thePerm : perms ) {
5410N/A col.add(thePerm);
5410N/A }
5410N/A
5410N/A final ProtectionDomain pd = new ProtectionDomain(null, col);
5410N/A return new AccessControlContext( new ProtectionDomain[] { pd });
5410N/A }
5410N/A
1790N/A private synchronized ServerNotifForwarder getServerNotifFwd() {
1790N/A // Lazily created when first use. Mainly when
1790N/A // addNotificationListener is first called.
1790N/A if (serverNotifForwarder == null)
1790N/A serverNotifForwarder =
1790N/A new ServerNotifForwarder(mbeanServer,
1790N/A env,
1790N/A rmiServer.getNotifBuffer(),
1790N/A connectionId);
1790N/A return serverNotifForwarder;
1790N/A }
0N/A
0N/A public String getConnectionId() throws IOException {
0N/A // We should call reqIncomming() here... shouldn't we?
0N/A return connectionId;
0N/A }
0N/A
0N/A public void close() throws IOException {
0N/A final boolean debug = logger.debugOn();
0N/A final String idstr = (debug?"["+this.toString()+"]":null);
0N/A
0N/A synchronized (this) {
0N/A if (terminated) {
0N/A if (debug) logger.debug("close",idstr + " already terminated.");
0N/A return;
0N/A }
0N/A
0N/A if (debug) logger.debug("close",idstr + " closing.");
0N/A
0N/A terminated = true;
0N/A
0N/A if (serverCommunicatorAdmin != null) {
0N/A serverCommunicatorAdmin.terminate();
0N/A }
0N/A
1790N/A if (serverNotifForwarder != null) {
1790N/A serverNotifForwarder.terminate();
1790N/A }
0N/A }
0N/A
0N/A rmiServer.clientClosed(this);
0N/A
0N/A if (debug) logger.debug("close",idstr + " closed.");
0N/A }
0N/A
0N/A public void unreferenced() {
0N/A logger.debug("unreferenced", "called");
0N/A try {
0N/A close();
0N/A logger.debug("unreferenced", "done");
0N/A } catch (IOException e) {
0N/A logger.fine("unreferenced", e);
0N/A }
0N/A }
0N/A
0N/A //-------------------------------------------------------------------------
0N/A // MBeanServerConnection Wrapper
0N/A //-------------------------------------------------------------------------
0N/A
0N/A public ObjectInstance createMBean(String className,
0N/A ObjectName name,
0N/A Subject delegationSubject)
0N/A throws
0N/A ReflectionException,
0N/A InstanceAlreadyExistsException,
0N/A MBeanRegistrationException,
0N/A MBeanException,
0N/A NotCompliantMBeanException,
0N/A IOException {
0N/A try {
0N/A final Object params[] =
0N/A new Object[] { className, name };
0N/A
0N/A if (logger.debugOn())
0N/A logger.debug("createMBean(String,ObjectName)",
0N/A "connectionId=" + connectionId +", className=" +
0N/A className+", name=" + name);
0N/A
0N/A return (ObjectInstance)
0N/A doPrivilegedOperation(
0N/A CREATE_MBEAN,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof InstanceAlreadyExistsException)
0N/A throw (InstanceAlreadyExistsException) e;
0N/A if (e instanceof MBeanRegistrationException)
0N/A throw (MBeanRegistrationException) e;
0N/A if (e instanceof MBeanException)
0N/A throw (MBeanException) e;
0N/A if (e instanceof NotCompliantMBeanException)
0N/A throw (NotCompliantMBeanException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public ObjectInstance createMBean(String className,
0N/A ObjectName name,
0N/A ObjectName loaderName,
0N/A Subject delegationSubject)
0N/A throws
0N/A ReflectionException,
0N/A InstanceAlreadyExistsException,
0N/A MBeanRegistrationException,
0N/A MBeanException,
0N/A NotCompliantMBeanException,
0N/A InstanceNotFoundException,
0N/A IOException {
0N/A try {
0N/A final Object params[] =
0N/A new Object[] { className, name, loaderName };
0N/A
0N/A if (logger.debugOn())
0N/A logger.debug("createMBean(String,ObjectName,ObjectName)",
0N/A "connectionId=" + connectionId
0N/A +", className=" + className
0N/A +", name=" + name
0N/A +", loaderName=" + loaderName);
0N/A
0N/A return (ObjectInstance)
0N/A doPrivilegedOperation(
0N/A CREATE_MBEAN_LOADER,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof InstanceAlreadyExistsException)
0N/A throw (InstanceAlreadyExistsException) e;
0N/A if (e instanceof MBeanRegistrationException)
0N/A throw (MBeanRegistrationException) e;
0N/A if (e instanceof MBeanException)
0N/A throw (MBeanException) e;
0N/A if (e instanceof NotCompliantMBeanException)
0N/A throw (NotCompliantMBeanException) e;
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public ObjectInstance createMBean(String className,
0N/A ObjectName name,
0N/A MarshalledObject params,
0N/A String signature[],
0N/A Subject delegationSubject)
0N/A throws
0N/A ReflectionException,
0N/A InstanceAlreadyExistsException,
0N/A MBeanRegistrationException,
0N/A MBeanException,
0N/A NotCompliantMBeanException,
0N/A IOException {
0N/A
0N/A final Object[] values;
0N/A final boolean debug = logger.debugOn();
0N/A
0N/A if (debug) logger.debug(
0N/A "createMBean(String,ObjectName,Object[],String[])",
0N/A "connectionId=" + connectionId
0N/A +", unwrapping parameters using classLoaderWithRepository.");
0N/A
0N/A values =
0N/A nullIsEmpty(unwrap(params, classLoaderWithRepository, Object[].class));
0N/A
0N/A try {
0N/A final Object params2[] =
0N/A new Object[] { className, name, values,
0N/A nullIsEmpty(signature) };
0N/A
0N/A if (debug)
0N/A logger.debug("createMBean(String,ObjectName,Object[],String[])",
0N/A "connectionId=" + connectionId
0N/A +", className=" + className
0N/A +", name=" + name
0N/A +", params=" + objects(values)
0N/A +", signature=" + strings(signature));
0N/A
0N/A return (ObjectInstance)
0N/A doPrivilegedOperation(
0N/A CREATE_MBEAN_PARAMS,
0N/A params2,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof InstanceAlreadyExistsException)
0N/A throw (InstanceAlreadyExistsException) e;
0N/A if (e instanceof MBeanRegistrationException)
0N/A throw (MBeanRegistrationException) e;
0N/A if (e instanceof MBeanException)
0N/A throw (MBeanException) e;
0N/A if (e instanceof NotCompliantMBeanException)
0N/A throw (NotCompliantMBeanException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public ObjectInstance createMBean(String className,
0N/A ObjectName name,
0N/A ObjectName loaderName,
0N/A MarshalledObject params,
0N/A String signature[],
0N/A Subject delegationSubject)
0N/A throws
0N/A ReflectionException,
0N/A InstanceAlreadyExistsException,
0N/A MBeanRegistrationException,
0N/A MBeanException,
0N/A NotCompliantMBeanException,
0N/A InstanceNotFoundException,
0N/A IOException {
0N/A
0N/A final Object[] values;
0N/A final boolean debug = logger.debugOn();
0N/A
0N/A if (debug) logger.debug(
0N/A "createMBean(String,ObjectName,ObjectName,Object[],String[])",
0N/A "connectionId=" + connectionId
0N/A +", unwrapping params with MBean extended ClassLoader.");
0N/A
0N/A values = nullIsEmpty(unwrap(params,
0N/A getClassLoader(loaderName),
0N/A defaultClassLoader,
0N/A Object[].class));
0N/A
0N/A try {
0N/A final Object params2[] =
0N/A new Object[] { className, name, loaderName, values,
0N/A nullIsEmpty(signature) };
0N/A
0N/A if (debug) logger.debug(
0N/A "createMBean(String,ObjectName,ObjectName,Object[],String[])",
0N/A "connectionId=" + connectionId
0N/A +", className=" + className
0N/A +", name=" + name
0N/A +", loaderName=" + loaderName
0N/A +", params=" + objects(values)
0N/A +", signature=" + strings(signature));
0N/A
0N/A return (ObjectInstance)
0N/A doPrivilegedOperation(
0N/A CREATE_MBEAN_LOADER_PARAMS,
0N/A params2,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof InstanceAlreadyExistsException)
0N/A throw (InstanceAlreadyExistsException) e;
0N/A if (e instanceof MBeanRegistrationException)
0N/A throw (MBeanRegistrationException) e;
0N/A if (e instanceof MBeanException)
0N/A throw (MBeanException) e;
0N/A if (e instanceof NotCompliantMBeanException)
0N/A throw (NotCompliantMBeanException) e;
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public void unregisterMBean(ObjectName name, Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A MBeanRegistrationException,
0N/A IOException {
0N/A try {
0N/A final Object params[] = new Object[] { name };
0N/A
0N/A if (logger.debugOn()) logger.debug("unregisterMBean",
0N/A "connectionId=" + connectionId
0N/A +", name="+name);
0N/A
0N/A doPrivilegedOperation(
0N/A UNREGISTER_MBEAN,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof MBeanRegistrationException)
0N/A throw (MBeanRegistrationException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public ObjectInstance getObjectInstance(ObjectName name,
0N/A Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A IOException {
0N/A
0N/A checkNonNull("ObjectName", name);
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name };
0N/A
0N/A if (logger.debugOn()) logger.debug("getObjectInstance",
0N/A "connectionId=" + connectionId
0N/A +", name="+name);
0N/A
0N/A return (ObjectInstance)
0N/A doPrivilegedOperation(
0N/A GET_OBJECT_INSTANCE,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public Set<ObjectInstance>
0N/A queryMBeans(ObjectName name,
0N/A MarshalledObject query,
0N/A Subject delegationSubject)
0N/A throws IOException {
0N/A final QueryExp queryValue;
0N/A final boolean debug=logger.debugOn();
0N/A
0N/A if (debug) logger.debug("queryMBeans",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping query with defaultClassLoader.");
0N/A
5439N/A queryValue = unwrap(query, defaultContextClassLoader, QueryExp.class);
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name, queryValue };
0N/A
0N/A if (debug) logger.debug("queryMBeans",
0N/A "connectionId=" + connectionId
0N/A +", name="+name +", query="+query);
0N/A
0N/A return cast(
0N/A doPrivilegedOperation(
0N/A QUERY_MBEANS,
0N/A params,
0N/A delegationSubject));
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public Set<ObjectName>
0N/A queryNames(ObjectName name,
0N/A MarshalledObject query,
0N/A Subject delegationSubject)
0N/A throws IOException {
0N/A final QueryExp queryValue;
0N/A final boolean debug=logger.debugOn();
0N/A
0N/A if (debug) logger.debug("queryNames",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping query with defaultClassLoader.");
0N/A
5439N/A queryValue = unwrap(query, defaultContextClassLoader, QueryExp.class);
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name, queryValue };
0N/A
0N/A if (debug) logger.debug("queryNames",
0N/A "connectionId=" + connectionId
0N/A +", name="+name +", query="+query);
0N/A
0N/A return cast(
0N/A doPrivilegedOperation(
0N/A QUERY_NAMES,
0N/A params,
0N/A delegationSubject));
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public boolean isRegistered(ObjectName name,
0N/A Subject delegationSubject) throws IOException {
0N/A try {
0N/A final Object params[] = new Object[] { name };
0N/A return ((Boolean)
0N/A doPrivilegedOperation(
0N/A IS_REGISTERED,
0N/A params,
0N/A delegationSubject)).booleanValue();
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public Integer getMBeanCount(Subject delegationSubject)
0N/A throws IOException {
0N/A try {
0N/A final Object params[] = new Object[] { };
0N/A
0N/A if (logger.debugOn()) logger.debug("getMBeanCount",
0N/A "connectionId=" + connectionId);
0N/A
0N/A return (Integer)
0N/A doPrivilegedOperation(
0N/A GET_MBEAN_COUNT,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public Object getAttribute(ObjectName name,
0N/A String attribute,
0N/A Subject delegationSubject)
0N/A throws
0N/A MBeanException,
0N/A AttributeNotFoundException,
0N/A InstanceNotFoundException,
0N/A ReflectionException,
0N/A IOException {
0N/A try {
0N/A final Object params[] = new Object[] { name, attribute };
0N/A if (logger.debugOn()) logger.debug("getAttribute",
0N/A "connectionId=" + connectionId
0N/A +", name=" + name
0N/A +", attribute="+ attribute);
0N/A
0N/A return
0N/A doPrivilegedOperation(
0N/A GET_ATTRIBUTE,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof MBeanException)
0N/A throw (MBeanException) e;
0N/A if (e instanceof AttributeNotFoundException)
0N/A throw (AttributeNotFoundException) e;
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public AttributeList getAttributes(ObjectName name,
0N/A String[] attributes,
0N/A Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A ReflectionException,
0N/A IOException {
0N/A try {
0N/A final Object params[] = new Object[] { name, attributes };
0N/A
0N/A if (logger.debugOn()) logger.debug("getAttributes",
0N/A "connectionId=" + connectionId
0N/A +", name=" + name
0N/A +", attributes="+ strings(attributes));
0N/A
0N/A return (AttributeList)
0N/A doPrivilegedOperation(
0N/A GET_ATTRIBUTES,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public void setAttribute(ObjectName name,
0N/A MarshalledObject attribute,
0N/A Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A AttributeNotFoundException,
0N/A InvalidAttributeValueException,
0N/A MBeanException,
0N/A ReflectionException,
0N/A IOException {
0N/A final Attribute attr;
0N/A final boolean debug=logger.debugOn();
0N/A
0N/A if (debug) logger.debug("setAttribute",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping attribute with MBean extended ClassLoader.");
0N/A
0N/A attr = unwrap(attribute,
0N/A getClassLoaderFor(name),
0N/A defaultClassLoader,
0N/A Attribute.class);
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name, attr };
0N/A
0N/A if (debug) logger.debug("setAttribute",
0N/A "connectionId=" + connectionId
0N/A +", name="+name
0N/A +", attribute="+attr);
0N/A
0N/A doPrivilegedOperation(
0N/A SET_ATTRIBUTE,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof AttributeNotFoundException)
0N/A throw (AttributeNotFoundException) e;
0N/A if (e instanceof InvalidAttributeValueException)
0N/A throw (InvalidAttributeValueException) e;
0N/A if (e instanceof MBeanException)
0N/A throw (MBeanException) e;
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public AttributeList setAttributes(ObjectName name,
0N/A MarshalledObject attributes,
0N/A Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A ReflectionException,
0N/A IOException {
0N/A final AttributeList attrlist;
0N/A final boolean debug=logger.debugOn();
0N/A
0N/A if (debug) logger.debug("setAttributes",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping attributes with MBean extended ClassLoader.");
0N/A
0N/A attrlist =
0N/A unwrap(attributes,
0N/A getClassLoaderFor(name),
0N/A defaultClassLoader,
0N/A AttributeList.class);
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name, attrlist };
0N/A
0N/A if (debug) logger.debug("setAttributes",
0N/A "connectionId=" + connectionId
0N/A +", name="+name
0N/A +", attributes="+attrlist);
0N/A
0N/A return (AttributeList)
0N/A doPrivilegedOperation(
0N/A SET_ATTRIBUTES,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public Object invoke(ObjectName name,
0N/A String operationName,
0N/A MarshalledObject params,
0N/A String signature[],
0N/A Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A MBeanException,
0N/A ReflectionException,
0N/A IOException {
0N/A
0N/A checkNonNull("ObjectName", name);
0N/A checkNonNull("Operation name", operationName);
0N/A
0N/A final Object[] values;
0N/A final boolean debug=logger.debugOn();
0N/A
0N/A if (debug) logger.debug("invoke",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping params with MBean extended ClassLoader.");
0N/A
0N/A values = nullIsEmpty(unwrap(params,
0N/A getClassLoaderFor(name),
0N/A defaultClassLoader,
0N/A Object[].class));
0N/A
0N/A try {
0N/A final Object params2[] =
0N/A new Object[] { name, operationName, values,
0N/A nullIsEmpty(signature) };
0N/A
0N/A if (debug) logger.debug("invoke",
0N/A "connectionId=" + connectionId
0N/A +", name="+name
0N/A +", operationName="+operationName
0N/A +", params="+objects(values)
0N/A +", signature="+strings(signature));
0N/A
0N/A return
0N/A doPrivilegedOperation(
0N/A INVOKE,
0N/A params2,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof MBeanException)
0N/A throw (MBeanException) e;
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public String getDefaultDomain(Subject delegationSubject)
0N/A throws IOException {
0N/A try {
0N/A final Object params[] = new Object[] { };
0N/A
0N/A if (logger.debugOn()) logger.debug("getDefaultDomain",
0N/A "connectionId=" + connectionId);
0N/A
0N/A return (String)
0N/A doPrivilegedOperation(
0N/A GET_DEFAULT_DOMAIN,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public String[] getDomains(Subject delegationSubject) throws IOException {
0N/A try {
0N/A final Object params[] = new Object[] { };
0N/A
0N/A if (logger.debugOn()) logger.debug("getDomains",
0N/A "connectionId=" + connectionId);
0N/A
0N/A return (String[])
0N/A doPrivilegedOperation(
0N/A GET_DOMAINS,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public MBeanInfo getMBeanInfo(ObjectName name, Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A IntrospectionException,
0N/A ReflectionException,
0N/A IOException {
0N/A
0N/A checkNonNull("ObjectName", name);
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name };
0N/A
0N/A if (logger.debugOn()) logger.debug("getMBeanInfo",
0N/A "connectionId=" + connectionId
0N/A +", name="+name);
0N/A
0N/A return (MBeanInfo)
0N/A doPrivilegedOperation(
0N/A GET_MBEAN_INFO,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof IntrospectionException)
0N/A throw (IntrospectionException) e;
0N/A if (e instanceof ReflectionException)
0N/A throw (ReflectionException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public boolean isInstanceOf(ObjectName name,
0N/A String className,
0N/A Subject delegationSubject)
0N/A throws InstanceNotFoundException, IOException {
0N/A
0N/A checkNonNull("ObjectName", name);
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name, className };
0N/A
0N/A if (logger.debugOn()) logger.debug("isInstanceOf",
0N/A "connectionId=" + connectionId
0N/A +", name="+name
0N/A +", className="+className);
0N/A
0N/A return ((Boolean)
0N/A doPrivilegedOperation(
0N/A IS_INSTANCE_OF,
0N/A params,
0N/A delegationSubject)).booleanValue();
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public Integer[] addNotificationListeners(ObjectName[] names,
0N/A MarshalledObject[] filters,
0N/A Subject[] delegationSubjects)
0N/A throws InstanceNotFoundException, IOException {
0N/A
0N/A if (names == null || filters == null) {
0N/A throw new IllegalArgumentException("Got null arguments.");
0N/A }
0N/A
0N/A Subject[] sbjs = (delegationSubjects != null) ? delegationSubjects :
0N/A new Subject[names.length];
0N/A if (names.length != filters.length || filters.length != sbjs.length) {
0N/A final String msg =
0N/A "The value lengths of 3 parameters are not same.";
0N/A throw new IllegalArgumentException(msg);
0N/A }
0N/A
0N/A for (int i=0; i<names.length; i++) {
0N/A if (names[i] == null) {
0N/A throw new IllegalArgumentException("Null Object name.");
0N/A }
0N/A }
0N/A
0N/A int i=0;
0N/A ClassLoader targetCl;
0N/A NotificationFilter[] filterValues =
469N/A new NotificationFilter[names.length];
0N/A Integer[] ids = new Integer[names.length];
0N/A final boolean debug=logger.debugOn();
0N/A
0N/A try {
0N/A for (; i<names.length; i++) {
0N/A targetCl = getClassLoaderFor(names[i]);
0N/A
0N/A if (debug) logger.debug("addNotificationListener"+
0N/A "(ObjectName,NotificationFilter)",
0N/A "connectionId=" + connectionId +
0N/A " unwrapping filter with target extended ClassLoader.");
0N/A
0N/A filterValues[i] =
0N/A unwrap(filters[i], targetCl, defaultClassLoader,
0N/A NotificationFilter.class);
0N/A
0N/A if (debug) logger.debug("addNotificationListener"+
0N/A "(ObjectName,NotificationFilter)",
0N/A "connectionId=" + connectionId
0N/A +", name=" + names[i]
0N/A +", filter=" + filterValues[i]);
0N/A
0N/A ids[i] = (Integer)
0N/A doPrivilegedOperation(ADD_NOTIFICATION_LISTENERS,
0N/A new Object[] { names[i],
0N/A filterValues[i] },
0N/A sbjs[i]);
0N/A }
0N/A
0N/A return ids;
0N/A } catch (Exception e) {
0N/A // remove all registered listeners
0N/A for (int j=0; j<i; j++) {
0N/A try {
1790N/A getServerNotifFwd().removeNotificationListener(names[j],
1790N/A ids[j]);
0N/A } catch (Exception eee) {
0N/A // strange
0N/A }
0N/A }
0N/A
0N/A if (e instanceof PrivilegedActionException) {
0N/A e = extractException(e);
0N/A }
0N/A
0N/A if (e instanceof ClassCastException) {
0N/A throw (ClassCastException) e;
0N/A } else if (e instanceof IOException) {
0N/A throw (IOException)e;
0N/A } else if (e instanceof InstanceNotFoundException) {
0N/A throw (InstanceNotFoundException) e;
0N/A } else if (e instanceof RuntimeException) {
0N/A throw (RuntimeException) e;
0N/A } else {
0N/A throw newIOException("Got unexpected server exception: "+e,e);
0N/A }
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public void addNotificationListener(ObjectName name,
0N/A ObjectName listener,
0N/A MarshalledObject filter,
0N/A MarshalledObject handback,
0N/A Subject delegationSubject)
0N/A throws InstanceNotFoundException, IOException {
0N/A
0N/A checkNonNull("Target MBean name", name);
0N/A checkNonNull("Listener MBean name", listener);
0N/A
0N/A final NotificationFilter filterValue;
0N/A final Object handbackValue;
0N/A final boolean debug=logger.debugOn();
0N/A
0N/A final ClassLoader targetCl = getClassLoaderFor(name);
0N/A
0N/A if (debug) logger.debug("addNotificationListener"+
0N/A "(ObjectName,ObjectName,NotificationFilter,Object)",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping filter with target extended ClassLoader.");
0N/A
0N/A filterValue =
0N/A unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class);
0N/A
0N/A if (debug) logger.debug("addNotificationListener"+
0N/A "(ObjectName,ObjectName,NotificationFilter,Object)",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping handback with target extended ClassLoader.");
0N/A
0N/A handbackValue =
0N/A unwrap(handback, targetCl, defaultClassLoader, Object.class);
0N/A
0N/A try {
0N/A final Object params[] =
0N/A new Object[] { name, listener, filterValue, handbackValue };
0N/A
0N/A if (debug) logger.debug("addNotificationListener"+
0N/A "(ObjectName,ObjectName,NotificationFilter,Object)",
0N/A "connectionId=" + connectionId
0N/A +", name=" + name
0N/A +", listenerName=" + listener
0N/A +", filter=" + filterValue
0N/A +", handback=" + handbackValue);
0N/A
0N/A doPrivilegedOperation(
0N/A ADD_NOTIFICATION_LISTENER_OBJECTNAME,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public void removeNotificationListeners(ObjectName name,
0N/A Integer[] listenerIDs,
0N/A Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A ListenerNotFoundException,
0N/A IOException {
0N/A
0N/A if (name == null || listenerIDs == null)
0N/A throw new IllegalArgumentException("Illegal null parameter");
0N/A
0N/A for (int i = 0; i < listenerIDs.length; i++) {
0N/A if (listenerIDs[i] == null)
0N/A throw new IllegalArgumentException("Null listener ID");
0N/A }
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name, listenerIDs };
0N/A
0N/A if (logger.debugOn()) logger.debug("removeNotificationListener"+
0N/A "(ObjectName,Integer[])",
0N/A "connectionId=" + connectionId
0N/A +", name=" + name
0N/A +", listenerIDs=" + objects(listenerIDs));
0N/A
0N/A doPrivilegedOperation(
0N/A REMOVE_NOTIFICATION_LISTENER,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof ListenerNotFoundException)
0N/A throw (ListenerNotFoundException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public void removeNotificationListener(ObjectName name,
0N/A ObjectName listener,
0N/A Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A ListenerNotFoundException,
0N/A IOException {
0N/A
0N/A checkNonNull("Target MBean name", name);
0N/A checkNonNull("Listener MBean name", listener);
0N/A
0N/A try {
0N/A final Object params[] = new Object[] { name, listener };
0N/A
0N/A if (logger.debugOn()) logger.debug("removeNotificationListener"+
0N/A "(ObjectName,ObjectName)",
0N/A "connectionId=" + connectionId
0N/A +", name=" + name
0N/A +", listenerName=" + listener);
0N/A
0N/A doPrivilegedOperation(
0N/A REMOVE_NOTIFICATION_LISTENER_OBJECTNAME,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof ListenerNotFoundException)
0N/A throw (ListenerNotFoundException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
686N/A @SuppressWarnings("rawtypes") // MarshalledObject
0N/A public void removeNotificationListener(ObjectName name,
0N/A ObjectName listener,
0N/A MarshalledObject filter,
0N/A MarshalledObject handback,
0N/A Subject delegationSubject)
0N/A throws
0N/A InstanceNotFoundException,
0N/A ListenerNotFoundException,
0N/A IOException {
0N/A
0N/A checkNonNull("Target MBean name", name);
0N/A checkNonNull("Listener MBean name", listener);
0N/A
0N/A final NotificationFilter filterValue;
0N/A final Object handbackValue;
0N/A final boolean debug=logger.debugOn();
0N/A
0N/A final ClassLoader targetCl = getClassLoaderFor(name);
0N/A
0N/A if (debug) logger.debug("removeNotificationListener"+
0N/A "(ObjectName,ObjectName,NotificationFilter,Object)",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping filter with target extended ClassLoader.");
0N/A
0N/A filterValue =
0N/A unwrap(filter, targetCl, defaultClassLoader, NotificationFilter.class);
0N/A
0N/A if (debug) logger.debug("removeNotificationListener"+
0N/A "(ObjectName,ObjectName,NotificationFilter,Object)",
0N/A "connectionId=" + connectionId
0N/A +" unwrapping handback with target extended ClassLoader.");
0N/A
0N/A handbackValue =
0N/A unwrap(handback, targetCl, defaultClassLoader, Object.class);
0N/A
0N/A try {
0N/A final Object params[] =
0N/A new Object[] { name, listener, filterValue, handbackValue };
0N/A
0N/A if (debug) logger.debug("removeNotificationListener"+
0N/A "(ObjectName,ObjectName,NotificationFilter,Object)",
0N/A "connectionId=" + connectionId
0N/A +", name=" + name
0N/A +", listenerName=" + listener
0N/A +", filter=" + filterValue
0N/A +", handback=" + handbackValue);
0N/A
0N/A doPrivilegedOperation(
0N/A REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK,
0N/A params,
0N/A delegationSubject);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof InstanceNotFoundException)
0N/A throw (InstanceNotFoundException) e;
0N/A if (e instanceof ListenerNotFoundException)
0N/A throw (ListenerNotFoundException) e;
0N/A if (e instanceof IOException)
0N/A throw (IOException) e;
0N/A throw newIOException("Got unexpected server exception: " + e, e);
0N/A }
0N/A }
0N/A
0N/A public NotificationResult fetchNotifications(long clientSequenceNumber,
0N/A int maxNotifications,
0N/A long timeout)
0N/A throws IOException {
0N/A
0N/A if (logger.debugOn()) logger.debug("fetchNotifications",
0N/A "connectionId=" + connectionId
0N/A +", timeout=" + timeout);
0N/A
0N/A if (maxNotifications < 0 || timeout < 0)
0N/A throw new IllegalArgumentException("Illegal negative argument");
0N/A
0N/A final boolean serverTerminated =
0N/A serverCommunicatorAdmin.reqIncoming();
0N/A try {
0N/A if (serverTerminated) {
0N/A // we must not call fetchNotifs() if the server is
0N/A // terminated (timeout elapsed).
0N/A //
0N/A return new NotificationResult(0L, 0L,
0N/A new TargetedNotification[0]);
0N/A
0N/A }
0N/A final long csn = clientSequenceNumber;
0N/A final int mn = maxNotifications;
0N/A final long t = timeout;
1790N/A PrivilegedAction<NotificationResult> action =
1790N/A new PrivilegedAction<NotificationResult>() {
1790N/A public NotificationResult run() {
1790N/A return getServerNotifFwd().fetchNotifs(csn, t, mn);
0N/A }
0N/A };
1790N/A if (acc == null)
1790N/A return action.run();
1790N/A else
1790N/A return AccessController.doPrivileged(action, acc);
0N/A } finally {
0N/A serverCommunicatorAdmin.rspOutgoing();
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * <p>Returns a string representation of this object. In general,
0N/A * the <code>toString</code> method returns a string that
0N/A * "textually represents" this object. The result should be a
0N/A * concise but informative representation that is easy for a
0N/A * person to read.</p>
0N/A *
0N/A * @return a String representation of this object.
0N/A **/
2254N/A @Override
0N/A public String toString() {
0N/A return super.toString() + ": connectionId=" + connectionId;
0N/A }
0N/A
0N/A //------------------------------------------------------------------------
0N/A // private classes
0N/A //------------------------------------------------------------------------
0N/A
0N/A private class PrivilegedOperation
0N/A implements PrivilegedExceptionAction<Object> {
0N/A
0N/A public PrivilegedOperation(int operation, Object[] params) {
0N/A this.operation = operation;
0N/A this.params = params;
0N/A }
0N/A
0N/A public Object run() throws Exception {
0N/A return doOperation(operation, params);
0N/A }
0N/A
0N/A private int operation;
0N/A private Object[] params;
0N/A }
0N/A
0N/A //------------------------------------------------------------------------
0N/A // private classes
0N/A //------------------------------------------------------------------------
0N/A private class RMIServerCommunicatorAdmin extends ServerCommunicatorAdmin {
0N/A public RMIServerCommunicatorAdmin(long timeout) {
0N/A super(timeout);
0N/A }
0N/A
0N/A protected void doStop() {
0N/A try {
0N/A close();
0N/A } catch (IOException ie) {
0N/A logger.warning("RMIServerCommunicatorAdmin-doStop",
0N/A "Failed to close: " + ie);
0N/A logger.debug("RMIServerCommunicatorAdmin-doStop",ie);
0N/A }
0N/A }
0N/A
0N/A }
0N/A
0N/A
0N/A //------------------------------------------------------------------------
0N/A // private methods
0N/A //------------------------------------------------------------------------
0N/A
0N/A private ClassLoader getClassLoader(final ObjectName name)
0N/A throws InstanceNotFoundException {
0N/A try {
0N/A return
0N/A AccessController.doPrivileged(
0N/A new PrivilegedExceptionAction<ClassLoader>() {
0N/A public ClassLoader run() throws InstanceNotFoundException {
0N/A return mbeanServer.getClassLoader(name);
0N/A }
5410N/A },
5410N/A withPermissions(new MBeanPermission("*", "getClassLoader"))
5410N/A );
0N/A } catch (PrivilegedActionException pe) {
0N/A throw (InstanceNotFoundException) extractException(pe);
0N/A }
0N/A }
0N/A
0N/A private ClassLoader getClassLoaderFor(final ObjectName name)
0N/A throws InstanceNotFoundException {
0N/A try {
0N/A return (ClassLoader)
0N/A AccessController.doPrivileged(
0N/A new PrivilegedExceptionAction<Object>() {
0N/A public Object run() throws InstanceNotFoundException {
0N/A return mbeanServer.getClassLoaderFor(name);
0N/A }
5410N/A },
5410N/A withPermissions(new MBeanPermission("*", "getClassLoaderFor"))
5410N/A );
0N/A } catch (PrivilegedActionException pe) {
0N/A throw (InstanceNotFoundException) extractException(pe);
0N/A }
0N/A }
0N/A
0N/A private Object doPrivilegedOperation(final int operation,
0N/A final Object[] params,
0N/A final Subject delegationSubject)
0N/A throws PrivilegedActionException, IOException {
0N/A
0N/A serverCommunicatorAdmin.reqIncoming();
0N/A try {
0N/A
0N/A final AccessControlContext reqACC;
0N/A if (delegationSubject == null)
0N/A reqACC = acc;
0N/A else {
0N/A if (subject == null) {
0N/A final String msg =
0N/A "Subject delegation cannot be enabled unless " +
0N/A "an authenticated subject is put in place";
0N/A throw new SecurityException(msg);
0N/A }
0N/A reqACC = subjectDelegator.delegatedContext(
0N/A acc, delegationSubject, removeCallerContext);
0N/A }
0N/A
0N/A PrivilegedOperation op =
0N/A new PrivilegedOperation(operation, params);
0N/A if (reqACC == null) {
0N/A try {
0N/A return op.run();
0N/A } catch (Exception e) {
0N/A if (e instanceof RuntimeException)
0N/A throw (RuntimeException) e;
0N/A throw new PrivilegedActionException(e);
0N/A }
0N/A } else {
0N/A return AccessController.doPrivileged(op, reqACC);
0N/A }
0N/A } catch (Error e) {
0N/A throw new JMXServerErrorException(e.toString(),e);
0N/A } finally {
0N/A serverCommunicatorAdmin.rspOutgoing();
0N/A }
0N/A }
0N/A
0N/A private Object doOperation(int operation, Object[] params)
0N/A throws Exception {
0N/A
0N/A switch (operation) {
0N/A
0N/A case CREATE_MBEAN:
0N/A return mbeanServer.createMBean((String)params[0],
0N/A (ObjectName)params[1]);
0N/A
0N/A case CREATE_MBEAN_LOADER:
0N/A return mbeanServer.createMBean((String)params[0],
0N/A (ObjectName)params[1],
0N/A (ObjectName)params[2]);
0N/A
0N/A case CREATE_MBEAN_PARAMS:
0N/A return mbeanServer.createMBean((String)params[0],
0N/A (ObjectName)params[1],
0N/A (Object[])params[2],
0N/A (String[])params[3]);
0N/A
0N/A case CREATE_MBEAN_LOADER_PARAMS:
0N/A return mbeanServer.createMBean((String)params[0],
0N/A (ObjectName)params[1],
0N/A (ObjectName)params[2],
0N/A (Object[])params[3],
0N/A (String[])params[4]);
0N/A
0N/A case GET_ATTRIBUTE:
0N/A return mbeanServer.getAttribute((ObjectName)params[0],
0N/A (String)params[1]);
0N/A
0N/A case GET_ATTRIBUTES:
0N/A return mbeanServer.getAttributes((ObjectName)params[0],
0N/A (String[])params[1]);
0N/A
0N/A case GET_DEFAULT_DOMAIN:
0N/A return mbeanServer.getDefaultDomain();
0N/A
0N/A case GET_DOMAINS:
0N/A return mbeanServer.getDomains();
0N/A
0N/A case GET_MBEAN_COUNT:
0N/A return mbeanServer.getMBeanCount();
0N/A
0N/A case GET_MBEAN_INFO:
0N/A return mbeanServer.getMBeanInfo((ObjectName)params[0]);
0N/A
0N/A case GET_OBJECT_INSTANCE:
0N/A return mbeanServer.getObjectInstance((ObjectName)params[0]);
0N/A
0N/A case INVOKE:
0N/A return mbeanServer.invoke((ObjectName)params[0],
0N/A (String)params[1],
0N/A (Object[])params[2],
0N/A (String[])params[3]);
0N/A
0N/A case IS_INSTANCE_OF:
0N/A return mbeanServer.isInstanceOf((ObjectName)params[0],
0N/A (String)params[1])
0N/A ? Boolean.TRUE : Boolean.FALSE;
0N/A
0N/A case IS_REGISTERED:
0N/A return mbeanServer.isRegistered((ObjectName)params[0])
0N/A ? Boolean.TRUE : Boolean.FALSE;
0N/A
0N/A case QUERY_MBEANS:
0N/A return mbeanServer.queryMBeans((ObjectName)params[0],
0N/A (QueryExp)params[1]);
0N/A
0N/A case QUERY_NAMES:
0N/A return mbeanServer.queryNames((ObjectName)params[0],
0N/A (QueryExp)params[1]);
0N/A
0N/A case SET_ATTRIBUTE:
0N/A mbeanServer.setAttribute((ObjectName)params[0],
0N/A (Attribute)params[1]);
0N/A return null;
0N/A
0N/A case SET_ATTRIBUTES:
0N/A return mbeanServer.setAttributes((ObjectName)params[0],
0N/A (AttributeList)params[1]);
0N/A
0N/A case UNREGISTER_MBEAN:
0N/A mbeanServer.unregisterMBean((ObjectName)params[0]);
0N/A return null;
0N/A
0N/A case ADD_NOTIFICATION_LISTENERS:
1790N/A return getServerNotifFwd().addNotificationListener(
1790N/A (ObjectName)params[0],
1790N/A (NotificationFilter)params[1]);
0N/A
0N/A case ADD_NOTIFICATION_LISTENER_OBJECTNAME:
0N/A mbeanServer.addNotificationListener((ObjectName)params[0],
0N/A (ObjectName)params[1],
0N/A (NotificationFilter)params[2],
0N/A params[3]);
0N/A return null;
0N/A
0N/A case REMOVE_NOTIFICATION_LISTENER:
1790N/A getServerNotifFwd().removeNotificationListener(
1790N/A (ObjectName)params[0],
1790N/A (Integer[])params[1]);
0N/A return null;
0N/A
0N/A case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME:
0N/A mbeanServer.removeNotificationListener((ObjectName)params[0],
0N/A (ObjectName)params[1]);
0N/A return null;
0N/A
0N/A case REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK:
0N/A mbeanServer.removeNotificationListener(
0N/A (ObjectName)params[0],
0N/A (ObjectName)params[1],
0N/A (NotificationFilter)params[2],
0N/A params[3]);
0N/A return null;
0N/A
0N/A default:
0N/A throw new IllegalArgumentException("Invalid operation");
0N/A }
0N/A }
0N/A
2254N/A private static class SetCcl implements PrivilegedExceptionAction<ClassLoader> {
2254N/A private final ClassLoader classLoader;
2254N/A
2254N/A SetCcl(ClassLoader classLoader) {
2254N/A this.classLoader = classLoader;
2254N/A }
2254N/A
2254N/A public ClassLoader run() {
2254N/A Thread currentThread = Thread.currentThread();
2254N/A ClassLoader old = currentThread.getContextClassLoader();
2254N/A currentThread.setContextClassLoader(classLoader);
2254N/A return old;
2254N/A }
2254N/A }
2254N/A
686N/A private static <T> T unwrap(final MarshalledObject<?> mo,
0N/A final ClassLoader cl,
0N/A final Class<T> wrappedClass)
0N/A throws IOException {
0N/A if (mo == null) {
0N/A return null;
0N/A }
0N/A try {
2254N/A final ClassLoader old = AccessController.doPrivileged(new SetCcl(cl));
2254N/A try {
2254N/A return wrappedClass.cast(mo.get());
2254N/A } catch (ClassNotFoundException cnfe) {
2254N/A throw new UnmarshalException(cnfe.toString(), cnfe);
2254N/A } finally {
2254N/A AccessController.doPrivileged(new SetCcl(old));
2254N/A }
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof IOException) {
0N/A throw (IOException) e;
0N/A }
0N/A if (e instanceof ClassNotFoundException) {
0N/A throw new UnmarshalException(e.toString(), e);
0N/A }
0N/A logger.warning("unwrap", "Failed to unmarshall object: " + e);
0N/A logger.debug("unwrap", e);
0N/A }
0N/A return null;
0N/A }
0N/A
686N/A private static <T> T unwrap(final MarshalledObject<?> mo,
0N/A final ClassLoader cl1,
0N/A final ClassLoader cl2,
0N/A final Class<T> wrappedClass)
0N/A throws IOException {
0N/A if (mo == null) {
0N/A return null;
0N/A }
0N/A try {
2254N/A ClassLoader orderCL = AccessController.doPrivileged(
2254N/A new PrivilegedExceptionAction<ClassLoader>() {
2254N/A public ClassLoader run() throws Exception {
5439N/A return new CombinedClassLoader(Thread.currentThread().getContextClassLoader(),
5439N/A new OrderClassLoaders(cl1, cl2));
2254N/A }
2254N/A }
2254N/A );
2254N/A return unwrap(mo, orderCL, wrappedClass);
0N/A } catch (PrivilegedActionException pe) {
0N/A Exception e = extractException(pe);
0N/A if (e instanceof IOException) {
0N/A throw (IOException) e;
0N/A }
0N/A if (e instanceof ClassNotFoundException) {
0N/A throw new UnmarshalException(e.toString(), e);
0N/A }
0N/A logger.warning("unwrap", "Failed to unmarshall object: " + e);
0N/A logger.debug("unwrap", e);
0N/A }
0N/A return null;
0N/A }
0N/A
0N/A /**
0N/A * Construct a new IOException with a nested exception.
0N/A * The nested exception is set only if JDK >= 1.4
0N/A */
0N/A private static IOException newIOException(String message,
0N/A Throwable cause) {
0N/A final IOException x = new IOException(message);
0N/A return EnvHelp.initCause(x,cause);
0N/A }
0N/A
0N/A /**
0N/A * Iterate until we extract the real exception
0N/A * from a stack of PrivilegedActionExceptions.
0N/A */
0N/A private static Exception extractException(Exception e) {
0N/A while (e instanceof PrivilegedActionException) {
0N/A e = ((PrivilegedActionException)e).getException();
0N/A }
0N/A return e;
0N/A }
0N/A
0N/A private static final Object[] NO_OBJECTS = new Object[0];
0N/A private static final String[] NO_STRINGS = new String[0];
0N/A
0N/A /*
0N/A * The JMX spec doesn't explicitly say that a null Object[] or
0N/A * String[] in e.g. MBeanServer.invoke is equivalent to an empty
0N/A * array, but the RI behaves that way. In the interests of
0N/A * maximal interoperability, we make it so even when we're
0N/A * connected to some other JMX implementation that might not do
0N/A * that. This should be clarified in the next version of JMX.
0N/A */
0N/A private static Object[] nullIsEmpty(Object[] array) {
0N/A return (array == null) ? NO_OBJECTS : array;
0N/A }
0N/A
0N/A private static String[] nullIsEmpty(String[] array) {
0N/A return (array == null) ? NO_STRINGS : array;
0N/A }
0N/A
0N/A /*
0N/A * Similarly, the JMX spec says for some but not all methods in
0N/A * MBeanServer that take an ObjectName target, that if it's null
0N/A * you get this exception. We specify it for all of them, and
0N/A * make it so for the ones where it's not specified in JMX even if
0N/A * the JMX implementation doesn't do so.
0N/A */
0N/A private static void checkNonNull(String what, Object x) {
0N/A if (x == null) {
0N/A RuntimeException wrapped =
0N/A new IllegalArgumentException(what + " must not be null");
0N/A throw new RuntimeOperationsException(wrapped);
0N/A }
0N/A }
0N/A
0N/A //------------------------------------------------------------------------
0N/A // private variables
0N/A //------------------------------------------------------------------------
0N/A
0N/A private final Subject subject;
0N/A
0N/A private final SubjectDelegator subjectDelegator;
0N/A
0N/A private final boolean removeCallerContext;
0N/A
0N/A private final AccessControlContext acc;
0N/A
0N/A private final RMIServerImpl rmiServer;
0N/A
0N/A private final MBeanServer mbeanServer;
0N/A
0N/A private final ClassLoader defaultClassLoader;
0N/A
5439N/A private final ClassLoader defaultContextClassLoader;
5439N/A
0N/A private final ClassLoaderWithRepository classLoaderWithRepository;
0N/A
0N/A private boolean terminated = false;
0N/A
0N/A private final String connectionId;
0N/A
0N/A private final ServerCommunicatorAdmin serverCommunicatorAdmin;
0N/A
0N/A // Method IDs for doOperation
0N/A //---------------------------
0N/A
0N/A private final static int
0N/A ADD_NOTIFICATION_LISTENERS = 1;
0N/A private final static int
0N/A ADD_NOTIFICATION_LISTENER_OBJECTNAME = 2;
0N/A private final static int
0N/A CREATE_MBEAN = 3;
0N/A private final static int
0N/A CREATE_MBEAN_PARAMS = 4;
0N/A private final static int
0N/A CREATE_MBEAN_LOADER = 5;
0N/A private final static int
0N/A CREATE_MBEAN_LOADER_PARAMS = 6;
0N/A private final static int
0N/A GET_ATTRIBUTE = 7;
0N/A private final static int
0N/A GET_ATTRIBUTES = 8;
0N/A private final static int
0N/A GET_DEFAULT_DOMAIN = 9;
0N/A private final static int
0N/A GET_DOMAINS = 10;
0N/A private final static int
0N/A GET_MBEAN_COUNT = 11;
0N/A private final static int
0N/A GET_MBEAN_INFO = 12;
0N/A private final static int
0N/A GET_OBJECT_INSTANCE = 13;
0N/A private final static int
0N/A INVOKE = 14;
0N/A private final static int
0N/A IS_INSTANCE_OF = 15;
0N/A private final static int
0N/A IS_REGISTERED = 16;
0N/A private final static int
0N/A QUERY_MBEANS = 17;
0N/A private final static int
0N/A QUERY_NAMES = 18;
0N/A private final static int
0N/A REMOVE_NOTIFICATION_LISTENER = 19;
0N/A private final static int
469N/A REMOVE_NOTIFICATION_LISTENER_OBJECTNAME = 20;
0N/A private final static int
469N/A REMOVE_NOTIFICATION_LISTENER_OBJECTNAME_FILTER_HANDBACK = 21;
0N/A private final static int
469N/A SET_ATTRIBUTE = 22;
0N/A private final static int
469N/A SET_ATTRIBUTES = 23;
0N/A private final static int
469N/A UNREGISTER_MBEAN = 24;
0N/A
0N/A // SERVER NOTIFICATION
0N/A //--------------------
0N/A
1790N/A private ServerNotifForwarder serverNotifForwarder;
469N/A private Map<String, ?> env;
0N/A
0N/A // TRACES & DEBUG
0N/A //---------------
0N/A
0N/A private static String objects(final Object[] objs) {
0N/A if (objs == null)
0N/A return "null";
0N/A else
0N/A return Arrays.asList(objs).toString();
0N/A }
0N/A
0N/A private static String strings(final String[] strs) {
0N/A return objects(strs);
0N/A }
0N/A
0N/A private static final ClassLogger logger =
0N/A new ClassLogger("javax.management.remote.rmi", "RMIConnectionImpl");
5439N/A
5439N/A private static final class CombinedClassLoader extends ClassLoader {
5439N/A
5439N/A private final static class ClassLoaderWrapper extends ClassLoader {
5439N/A ClassLoaderWrapper(ClassLoader cl) {
5439N/A super(cl);
5439N/A }
5439N/A
5439N/A @Override
5439N/A protected Class<?> loadClass(String name, boolean resolve)
5439N/A throws ClassNotFoundException {
5439N/A return super.loadClass(name, resolve);
5439N/A }
5439N/A };
5439N/A
5439N/A final ClassLoaderWrapper defaultCL;
5439N/A
5439N/A private CombinedClassLoader(ClassLoader parent, ClassLoader defaultCL) {
5439N/A super(parent);
5439N/A this.defaultCL = new ClassLoaderWrapper(defaultCL);
5439N/A }
5439N/A
5439N/A @Override
5439N/A protected Class<?> loadClass(String name, boolean resolve)
5439N/A throws ClassNotFoundException {
6281N/A ReflectUtil.checkPackageAccess(name);
5439N/A try {
5439N/A super.loadClass(name, resolve);
5439N/A } catch(Exception e) {
5439N/A for(Throwable t = e; t != null; t = t.getCause()) {
5439N/A if(t instanceof SecurityException) {
5439N/A throw t==e?(SecurityException)t:new SecurityException(t.getMessage(), e);
5439N/A }
5439N/A }
5439N/A }
5439N/A final Class<?> cl = defaultCL.loadClass(name, resolve);
5439N/A return cl;
5439N/A }
5439N/A
5439N/A }
0N/A}