0N/A/*
2362N/A * Copyright (c) 1999, 2008, 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 com.sun.jmx.mbeanserver;
0N/A
1790N/Aimport com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;
1790N/Aimport com.sun.jmx.interceptor.MBeanServerInterceptor;
528N/Aimport static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;
528N/A
0N/Aimport java.io.ObjectInputStream;
0N/Aimport java.security.AccessController;
0N/Aimport java.security.Permission;
6293N/Aimport java.security.PrivilegedAction;
0N/Aimport java.security.PrivilegedExceptionAction;
686N/Aimport java.util.List;
528N/Aimport java.util.Set;
528N/Aimport java.util.logging.Level;
0N/A
0N/Aimport javax.management.Attribute;
0N/Aimport javax.management.AttributeList;
528N/Aimport javax.management.AttributeNotFoundException;
528N/Aimport javax.management.InstanceAlreadyExistsException;
528N/Aimport javax.management.InstanceNotFoundException;
528N/Aimport javax.management.IntrospectionException;
528N/Aimport javax.management.InvalidAttributeValueException;
528N/Aimport javax.management.ListenerNotFoundException;
528N/Aimport javax.management.MBeanException;
528N/Aimport javax.management.MBeanInfo;
528N/Aimport javax.management.MBeanPermission;
528N/Aimport javax.management.MBeanRegistrationException;
0N/Aimport javax.management.MBeanServer;
0N/Aimport javax.management.MBeanServerDelegate;
5789N/Aimport javax.management.MBeanServerPermission;
528N/Aimport javax.management.NotCompliantMBeanException;
528N/Aimport javax.management.NotificationFilter;
528N/Aimport javax.management.NotificationListener;
528N/Aimport javax.management.ObjectInstance;
528N/Aimport javax.management.ObjectName;
528N/Aimport javax.management.OperationsException;
528N/Aimport javax.management.QueryExp;
528N/Aimport javax.management.ReflectionException;
528N/Aimport javax.management.RuntimeOperationsException;
0N/Aimport javax.management.loading.ClassLoaderRepository;
0N/A
0N/A/**
0N/A * This is the base class for MBean manipulation on the agent side. It
0N/A * contains the methods necessary for the creation, registration, and
0N/A * deletion of MBeans as well as the access methods for registered MBeans.
0N/A * This is the core component of the JMX infrastructure.
0N/A * <P>
0N/A * Every MBean which is added to the MBean server becomes manageable:
0N/A * its attributes and operations become remotely accessible through
0N/A * the connectors/adaptors connected to that MBean server.
0N/A * A Java object cannot be registered in the MBean server unless it is a
0N/A * JMX compliant MBean.
0N/A * <P>
0N/A * When an MBean is registered or unregistered in the MBean server an
0N/A * {@link javax.management.MBeanServerNotification MBeanServerNotification}
0N/A * Notification is emitted. To register an object as listener to
0N/A * MBeanServerNotifications you should call the MBean server method
0N/A * {@link #addNotificationListener addNotificationListener} with
0N/A * the <CODE>ObjectName</CODE> of the
0N/A * {@link javax.management.MBeanServerDelegate MBeanServerDelegate}.
0N/A * This <CODE>ObjectName</CODE> is:
0N/A * <BR>
0N/A * <CODE>JMImplementation:type=MBeanServerDelegate</CODE>.
0N/A *
0N/A * @since 1.5
0N/A */
0N/Apublic final class JmxMBeanServer
0N/A implements SunJmxMBeanServer {
0N/A
0N/A /** Control the default locking policy of the repository.
0N/A * By default, we will be using a fair locking policy.
0N/A **/
0N/A public static final boolean DEFAULT_FAIR_LOCK_POLICY = true;
0N/A
0N/A private final MBeanInstantiator instantiator;
0N/A private final SecureClassLoaderRepository secureClr;
0N/A
0N/A /** true if interceptors are enabled **/
0N/A private final boolean interceptorsEnabled;
0N/A
528N/A private final MBeanServer outerShell;
528N/A
528N/A private volatile MBeanServer mbsInterceptor = null;
0N/A
528N/A /** The MBeanServerDelegate object representing the MBean Server */
528N/A private final MBeanServerDelegate mBeanServerDelegateObject;
0N/A
0N/A /**
0N/A * <b>Package:</b> Creates an MBeanServer with the
0N/A * specified default domain name, outer interface, and delegate.
0N/A * <p>The default domain name is used as the domain part in the ObjectName
0N/A * of MBeans if no domain is specified by the user.
0N/A * <ul><b>Note:</b>Using this constructor directly is strongly
0N/A * discouraged. You should use
0N/A * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)}
0N/A * or
0N/A * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)}
0N/A * instead.
0N/A * <p>
699N/A * By default, interceptors are disabled. Use
0N/A * {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them.
0N/A * </ul>
0N/A * @param domain The default domain name used by this MBeanServer.
0N/A * @param outer A pointer to the MBeanServer object that must be
0N/A * passed to the MBeans when invoking their
0N/A * {@link javax.management.MBeanRegistration} interface.
0N/A * @param delegate A pointer to the MBeanServerDelegate associated
0N/A * with the new MBeanServer. The new MBeanServer must register
0N/A * this MBean in its MBean repository.
0N/A * @exception IllegalArgumentException if the instantiator is null.
0N/A */
0N/A JmxMBeanServer(String domain, MBeanServer outer,
0N/A MBeanServerDelegate delegate) {
0N/A this(domain,outer,delegate,null,false);
0N/A }
0N/A
0N/A /**
0N/A * <b>Package:</b> Creates an MBeanServer with the
0N/A * specified default domain name, outer interface, and delegate.
0N/A * <p>The default domain name is used as the domain part in the ObjectName
0N/A * of MBeans if no domain is specified by the user.
0N/A * <ul><b>Note:</b>Using this constructor directly is strongly
0N/A * discouraged. You should use
0N/A * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)}
0N/A * or
0N/A * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)}
0N/A * instead.
0N/A * </ul>
0N/A * @param domain The default domain name used by this MBeanServer.
0N/A * @param outer A pointer to the MBeanServer object that must be
0N/A * passed to the MBeans when invoking their
0N/A * {@link javax.management.MBeanRegistration} interface.
0N/A * @param delegate A pointer to the MBeanServerDelegate associated
0N/A * with the new MBeanServer. The new MBeanServer must register
0N/A * this MBean in its MBean repository.
0N/A * @param interceptors If <code>true</code>,
0N/A * {@link MBeanServerInterceptor} will be enabled (default is
0N/A * <code>false</code>)
0N/A * Note: this parameter is not taken into account by this
0N/A * implementation - the default value <code>false</code> is
0N/A * always used.
0N/A * @exception IllegalArgumentException if the instantiator is null.
0N/A */
0N/A JmxMBeanServer(String domain, MBeanServer outer,
0N/A MBeanServerDelegate delegate, boolean interceptors) {
0N/A this(domain,outer,delegate,null,false);
0N/A }
0N/A
0N/A /**
0N/A * <b>Package:</b> Creates an MBeanServer.
0N/A * @param domain The default domain name used by this MBeanServer.
0N/A * @param outer A pointer to the MBeanServer object that must be
0N/A * passed to the MBeans when invoking their
0N/A * {@link javax.management.MBeanRegistration} interface.
0N/A * @param delegate A pointer to the MBeanServerDelegate associated
0N/A * with the new MBeanServer. The new MBeanServer must register
0N/A * this MBean in its MBean repository.
0N/A * @param instantiator The MBeanInstantiator that will be used to
0N/A * instantiate MBeans and take care of class loading issues.
0N/A * @param metadata The MetaData object that will be used by the
0N/A * MBean server in order to invoke the MBean interface of
0N/A * the registered MBeans.
0N/A * @param interceptors If <code>true</code>,
0N/A * {@link MBeanServerInterceptor} will be enabled (default is
0N/A * <code>false</code>).
0N/A */
0N/A JmxMBeanServer(String domain, MBeanServer outer,
0N/A MBeanServerDelegate delegate,
0N/A MBeanInstantiator instantiator,
0N/A boolean interceptors) {
0N/A this(domain,outer,delegate,instantiator,interceptors,true);
0N/A }
0N/A
0N/A /**
0N/A * <b>Package:</b> Creates an MBeanServer.
0N/A * @param domain The default domain name used by this MBeanServer.
0N/A * @param outer A pointer to the MBeanServer object that must be
0N/A * passed to the MBeans when invoking their
0N/A * {@link javax.management.MBeanRegistration} interface.
0N/A * @param delegate A pointer to the MBeanServerDelegate associated
0N/A * with the new MBeanServer. The new MBeanServer must register
0N/A * this MBean in its MBean repository.
0N/A * @param instantiator The MBeanInstantiator that will be used to
0N/A * instantiate MBeans and take care of class loading issues.
0N/A * @param metadata The MetaData object that will be used by the
0N/A * MBean server in order to invoke the MBean interface of
0N/A * the registered MBeans.
0N/A * @param interceptors If <code>true</code>,
0N/A * {@link MBeanServerInterceptor} will be enabled (default is
0N/A * <code>false</code>).
0N/A * @param fairLock If {@code true}, the MBean repository will use a {@link
0N/A * java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
0N/A * fair locking} policy.
0N/A */
0N/A JmxMBeanServer(String domain, MBeanServer outer,
0N/A MBeanServerDelegate delegate,
0N/A MBeanInstantiator instantiator,
0N/A boolean interceptors,
0N/A boolean fairLock) {
0N/A
0N/A if (instantiator == null) {
0N/A final ModifiableClassLoaderRepository
0N/A clr = new ClassLoaderRepositorySupport();
0N/A instantiator = new MBeanInstantiator(clr);
0N/A }
6293N/A
6293N/A final MBeanInstantiator fInstantiator = instantiator;
0N/A this.secureClr = new
6293N/A SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {
6293N/A @Override
6293N/A public ClassLoaderRepository run() {
6293N/A return fInstantiator.getClassLoaderRepository();
6293N/A }
6293N/A })
6293N/A );
0N/A if (delegate == null)
0N/A delegate = new MBeanServerDelegateImpl();
0N/A if (outer == null)
0N/A outer = this;
0N/A
0N/A this.instantiator = instantiator;
0N/A this.mBeanServerDelegateObject = delegate;
0N/A this.outerShell = outer;
0N/A
699N/A final Repository repository = new Repository(domain);
0N/A this.mbsInterceptor =
1790N/A new DefaultMBeanServerInterceptor(outer, delegate, instantiator,
0N/A repository);
0N/A this.interceptorsEnabled = interceptors;
0N/A initialize();
0N/A }
0N/A
0N/A /**
0N/A * Tell whether {@link MBeanServerInterceptor}s are enabled on this
0N/A * object.
0N/A * @return <code>true</code> if {@link MBeanServerInterceptor}s are
0N/A * enabled.
0N/A * @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)
0N/A **/
0N/A public boolean interceptorsEnabled() {
0N/A return interceptorsEnabled;
0N/A }
0N/A
0N/A /**
0N/A * Return the MBeanInstantiator associated to this MBeanServer.
0N/A * @exception UnsupportedOperationException if
0N/A * {@link MBeanServerInterceptor}s
0N/A * are not enabled on this object.
0N/A * @see #interceptorsEnabled
0N/A **/
0N/A public MBeanInstantiator getMBeanInstantiator() {
0N/A if (interceptorsEnabled) return instantiator;
0N/A else throw new UnsupportedOperationException(
0N/A "MBeanServerInterceptors are disabled.");
0N/A }
0N/A
0N/A /**
0N/A * Instantiates and registers an MBean in the MBean server.
0N/A * The MBean server will use its
0N/A * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}
0N/A * to load the class of the MBean.
0N/A * An object name is associated to the MBean.
0N/A * If the object name given is null, the MBean can automatically
0N/A * provide its own name by implementing the
0N/A * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
0N/A * The call returns an <CODE>ObjectInstance</CODE> object representing
0N/A * the newly created MBean.
0N/A *
0N/A * @param className The class name of the MBean to be instantiated.
0N/A * @param name The object name of the MBean. May be null.
0N/A *
0N/A * @return An <CODE>ObjectInstance</CODE>, containing the
0N/A * <CODE>ObjectName</CODE> and the Java class name of the newly
0N/A * instantiated MBean.
0N/A *
0N/A * @exception ReflectionException Wraps an
0N/A * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
0N/A * <CODE>{@link java.lang.Exception}</CODE> that occurred
0N/A * when trying to invoke the MBean's constructor.
0N/A * @exception InstanceAlreadyExistsException The MBean is already
0N/A * under the control of the MBean server.
0N/A * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
0N/A * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
0N/A * has thrown an exception. The MBean will not be registered.
0N/A * @exception MBeanException The constructor of the MBean has thrown
0N/A * an exception.
0N/A * @exception NotCompliantMBeanException This class is not a JMX
0N/A * compliant MBean.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
0N/A * The className passed in parameter is null, the
0N/A * <CODE>ObjectName</CODE> passed in parameter contains a pattern
0N/A * or no <CODE>ObjectName</CODE> is specified for the MBean.
0N/A *
0N/A */
0N/A public ObjectInstance createMBean(String className, ObjectName name)
0N/A throws ReflectionException, InstanceAlreadyExistsException,
0N/A MBeanRegistrationException, MBeanException,
0N/A NotCompliantMBeanException {
0N/A
0N/A return mbsInterceptor.createMBean(className,
0N/A cloneObjectName(name),
0N/A (Object[]) null,
0N/A (String[]) null);
0N/A }
0N/A
0N/A /**
0N/A * Instantiates and registers an MBean in the MBean server.
0N/A * The class loader to be used is identified by its object name.
0N/A * An object name is associated to the MBean.
0N/A * If the object name of the loader is null, the ClassLoader that
0N/A * loaded the MBean server will be used.
0N/A * If the MBean's object name given is null, the MBean can
0N/A * automatically provide its own name by implementing the
0N/A * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
0N/A * The call returns an <CODE>ObjectInstance</CODE> object representing
0N/A * the newly created MBean.
0N/A *
0N/A * @param className The class name of the MBean to be instantiated.
0N/A * @param name The object name of the MBean. May be null.
0N/A * @param loaderName The object name of the class loader to be used.
0N/A *
0N/A * @return An <CODE>ObjectInstance</CODE>, containing the
0N/A * <CODE>ObjectName</CODE> and the Java class name
0N/A * of the newly instantiated MBean.
0N/A *
0N/A * @exception ReflectionException Wraps an
0N/A * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
0N/A * <CODE>{@link java.lang.Exception}</CODE> that occurred when trying
0N/A * to invoke the MBean's constructor.
0N/A * @exception InstanceAlreadyExistsException The MBean is already
0N/A * under the control of the MBean server.
0N/A * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
0N/A * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
0N/A * has thrown an exception. The MBean will not be registered.
0N/A * @exception MBeanException The constructor of the MBean has thrown
0N/A * an exception
0N/A * @exception NotCompliantMBeanException This class is not a JMX
0N/A * compliant MBean.
0N/A * @exception InstanceNotFoundException The specified class loader
0N/A * is not registered in the MBean server.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
0N/A * className passed in parameter is null, the <CODE>ObjectName</CODE>
0N/A * passed in parameter contains a pattern or no
0N/A * <CODE>ObjectName</CODE> is specified for the MBean.
0N/A */
0N/A public ObjectInstance createMBean(String className, ObjectName name,
0N/A ObjectName loaderName)
0N/A throws ReflectionException, InstanceAlreadyExistsException,
0N/A MBeanRegistrationException, MBeanException,
0N/A NotCompliantMBeanException, InstanceNotFoundException {
0N/A
0N/A return mbsInterceptor.createMBean(className,
0N/A cloneObjectName(name),
0N/A loaderName,
0N/A (Object[]) null,
0N/A (String[]) null);
0N/A }
0N/A
0N/A /**
0N/A * Instantiates and registers an MBean in the MBean server.
0N/A * The MBean server will use its
0N/A * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}
0N/A * to load the class of the MBean.
0N/A * An object name is associated to the MBean.
0N/A * If the object name given is null, the MBean can automatically
0N/A * provide its own name by implementing the
0N/A * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
0N/A * The call returns an <CODE>ObjectInstance</CODE> object representing
0N/A * the newly created MBean.
0N/A *
0N/A * @param className The class name of the MBean to be instantiated.
0N/A * @param name The object name of the MBean. May be null.
0N/A * @param params An array containing the parameters of the constructor
0N/A * to be invoked.
0N/A * @param signature An array containing the signature of the
0N/A * constructor to be invoked.
0N/A *
0N/A * @return An <CODE>ObjectInstance</CODE>, containing the
0N/A * <CODE>ObjectName</CODE> and the Java class name
0N/A * of the newly instantiated MBean.
0N/A *
0N/A * @exception ReflectionException Wraps a
0N/A * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
0N/A * <CODE>{@link java.lang.Exception}</CODE> that occurred
0N/A * when trying to invoke the MBean's constructor.
0N/A * @exception InstanceAlreadyExistsException The MBean is already
0N/A * under the control of the MBean server.
0N/A * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
0N/A * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
0N/A * has thrown an exception. The MBean will not be registered.
0N/A * @exception MBeanException The constructor of the MBean has
0N/A * thrown an exception.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
0N/A * className passed in parameter is null, the <CODE>ObjectName</CODE>
0N/A * passed in parameter contains a pattern or no
0N/A * <CODE>ObjectName</CODE> is specified for the MBean.
0N/A *
0N/A */
0N/A public ObjectInstance createMBean(String className, ObjectName name,
0N/A Object params[], String signature[])
0N/A throws ReflectionException, InstanceAlreadyExistsException,
0N/A MBeanRegistrationException, MBeanException,
0N/A NotCompliantMBeanException {
0N/A
0N/A return mbsInterceptor.createMBean(className, cloneObjectName(name),
0N/A params, signature);
0N/A }
0N/A
0N/A /**
0N/A * Instantiates and registers an MBean in the MBean server.
0N/A * The class loader to be used is identified by its object name.
0N/A * An object name is associated to the MBean. If the object name
0N/A * of the loader is not specified, the ClassLoader that loaded the
0N/A * MBean server will be used.
0N/A * If the MBean object name given is null, the MBean can automatically
0N/A * provide its own name by implementing the
0N/A * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
0N/A * The call returns an <CODE>ObjectInstance</CODE> object representing
0N/A * the newly created MBean.
0N/A *
0N/A * @param className The class name of the MBean to be instantiated.
0N/A * @param name The object name of the MBean. May be null.
0N/A * @param params An array containing the parameters of the constructor
0N/A * to be invoked.
0N/A * @param signature An array containing the signature of the
0N/A * constructor to be invoked.
0N/A * @param loaderName The object name of the class loader to be used.
0N/A *
0N/A * @return An <CODE>ObjectInstance</CODE>, containing the
0N/A * <CODE>ObjectName</CODE> and the Java class name of the newly
0N/A * instantiated MBean.
0N/A *
0N/A * @exception ReflectionException Wraps a
0N/A * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an
0N/A * <CODE>{@link java.lang.Exception}</CODE>
0N/A * that occurred when trying to invoke the MBean's constructor.
0N/A * @exception InstanceAlreadyExistsException The MBean is already
0N/A * under the control of the MBean server.
0N/A * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
0N/A * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
0N/A * has thrown an exception. The MBean will not be registered.
0N/A * @exception MBeanException The constructor of the MBean has
0N/A * thrown an exception
0N/A * @exception InstanceNotFoundException The specified class loader is
0N/A * not registered in the MBean server.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
0N/A * className passed in parameter is null, the <CODE>ObjectName</CODE>
0N/A * passed in parameter contains a pattern or no
0N/A * <CODE>ObjectName</CODE> is specified for the MBean.
0N/A *
0N/A */
0N/A public ObjectInstance createMBean(String className, ObjectName name,
0N/A ObjectName loaderName, Object params[],
0N/A String signature[])
0N/A throws ReflectionException, InstanceAlreadyExistsException,
0N/A MBeanRegistrationException, MBeanException,
0N/A NotCompliantMBeanException, InstanceNotFoundException {
0N/A
0N/A return mbsInterceptor.createMBean(className, cloneObjectName(name),
0N/A loaderName, params, signature);
0N/A }
0N/A
0N/A /**
0N/A * Registers a pre-existing object as an MBean with the MBean server.
0N/A * If the object name given is null, the MBean may automatically
0N/A * provide its own name by implementing the
0N/A * {@link javax.management.MBeanRegistration MBeanRegistration} interface.
0N/A * The call returns an <CODE>ObjectInstance</CODE> object representing
0N/A * the registered MBean.
0N/A *
0N/A * @param object The MBean to be registered as an MBean.
0N/A * @param name The object name of the MBean. May be null.
0N/A *
0N/A * @return The <CODE>ObjectInstance</CODE> for the MBean that has been
0N/A * registered.
0N/A *
0N/A * @exception InstanceAlreadyExistsException The MBean is already
0N/A * under the control of the MBean server.
0N/A * @exception MBeanRegistrationException The <CODE>preRegister()</CODE>
0N/A * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
0N/A * has thrown an exception. The MBean will not be registered.
0N/A * @exception NotCompliantMBeanException This object is not a JMX
0N/A * compliant MBean
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
0N/A * object passed in parameter is null or no object name is specified.
0N/A *
0N/A */
0N/A public ObjectInstance registerMBean(Object object, ObjectName name)
0N/A throws InstanceAlreadyExistsException, MBeanRegistrationException,
0N/A NotCompliantMBeanException {
0N/A
0N/A return mbsInterceptor.registerMBean(object, cloneObjectName(name));
0N/A }
0N/A
0N/A /**
0N/A * De-registers an MBean from the MBean server. The MBean is identified by
0N/A * its object name. Once the method has been invoked, the MBean may
0N/A * no longer be accessed by its object name.
0N/A *
0N/A * @param name The object name of the MBean to be de-registered.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean specified is not
0N/A * registered in the MBean server.
0N/A * @exception MBeanRegistrationException The <code>preDeregister()</code>
0N/A * (<CODE>MBeanRegistration</CODE> interface) method of the MBean
0N/A * has thrown an exception.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
0N/A * object name in parameter is null or the MBean you are when
0N/A * trying to de-register is the
0N/A * {@link javax.management.MBeanServerDelegate MBeanServerDelegate}
0N/A * MBean.
0N/A **/
0N/A public void unregisterMBean(ObjectName name)
0N/A throws InstanceNotFoundException, MBeanRegistrationException {
0N/A mbsInterceptor.unregisterMBean(cloneObjectName(name));
0N/A }
0N/A
0N/A /**
0N/A * Gets the <CODE>ObjectInstance</CODE> for a given MBean registered
0N/A * with the MBean server.
0N/A *
0N/A * @param name The object name of the MBean.
0N/A *
0N/A * @return The <CODE>ObjectInstance</CODE> associated to the MBean
0N/A * specified by <VAR>name</VAR>.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean specified is not
0N/A * registered in the MBean server.
0N/A */
0N/A public ObjectInstance getObjectInstance(ObjectName name)
0N/A throws InstanceNotFoundException {
0N/A
0N/A return mbsInterceptor.getObjectInstance(cloneObjectName(name));
0N/A }
0N/A
0N/A /**
0N/A * Gets MBeans controlled by the MBean server. This method allows any
0N/A * of the following to be obtained: All MBeans, a set of MBeans specified
0N/A * by pattern matching on the <CODE>ObjectName</CODE> and/or a Query
0N/A * expression, a specific MBean. When the object name is null or no
0N/A * domain and key properties are specified, all objects are to be
0N/A * selected (and filtered if a query is specified). It returns the
0N/A * set of <CODE>ObjectInstance</CODE> objects (containing the
0N/A * <CODE>ObjectName</CODE> and the Java Class name) for
0N/A * the selected MBeans.
0N/A *
0N/A * @param name The object name pattern identifying the MBeans to
0N/A * be retrieved. If null or or no domain and key properties
0N/A * are specified, all the MBeans registered will be retrieved.
0N/A * @param query The query expression to be applied for selecting
0N/A * MBeans. If null no query expression will be applied for
0N/A * selecting MBeans.
0N/A *
0N/A * @return A set containing the <CODE>ObjectInstance</CODE> objects
0N/A * for the selected MBeans.
0N/A * If no MBean satisfies the query an empty list is returned.
0N/A *
0N/A */
0N/A public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {
0N/A
0N/A return mbsInterceptor.queryMBeans(cloneObjectName(name), query);
0N/A }
0N/A
0N/A /**
0N/A * Gets the names of MBeans controlled by the MBean server. This method
0N/A * enables any of the following to be obtained: The names of all MBeans,
0N/A * the names of a set of MBeans specified by pattern matching on the
0N/A * <CODE>ObjectName</CODE> and/or a Query expression, a specific
0N/A * MBean name (equivalent to testing whether an MBean is registered).
0N/A * When the object name is null or or no domain and key properties are
0N/A * specified, all objects are selected (and filtered if a query is
0N/A * specified). It returns the set of ObjectNames for the MBeans
0N/A * selected.
0N/A *
0N/A * @param name The object name pattern identifying the MBeans to be
0N/A * retrieved. If null or no domain and key properties are
0N/A * specified, all the MBeans registered will be retrieved.
0N/A * @param query The query expression to be applied for selecting
0N/A * MBeans. If null no query expression will be applied for
0N/A * selecting MBeans.
0N/A *
0N/A * @return A set containing the ObjectNames for the MBeans selected.
0N/A * If no MBean satisfies the query, an empty list is returned.
0N/A *
0N/A */
0N/A public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {
0N/A
0N/A return mbsInterceptor.queryNames(cloneObjectName(name), query);
0N/A }
0N/A
0N/A /**
0N/A * Checks whether an MBean, identified by its object name, is already
0N/A * registered with the MBean server.
0N/A *
0N/A * @param name The object name of the MBean to be checked.
0N/A *
0N/A * @return True if the MBean is already registered in the MBean server,
0N/A * false otherwise.
0N/A *
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The object
0N/A * name in parameter is null.
0N/A *
0N/A */
0N/A public boolean isRegistered(ObjectName name) {
0N/A
0N/A return mbsInterceptor.isRegistered(name);
0N/A }
0N/A
0N/A /**
0N/A * Returns the number of MBeans registered in the MBean server.
0N/A */
0N/A public Integer getMBeanCount() {
0N/A
0N/A return mbsInterceptor.getMBeanCount();
0N/A }
0N/A
0N/A /**
0N/A * Gets the value of a specific attribute of a named MBean. The MBean
0N/A * is identified by its object name.
0N/A *
0N/A * @param name The object name of the MBean from which the attribute
0N/A * is to be retrieved.
0N/A * @param attribute A String specifying the name of the attribute to be
0N/A * retrieved.
0N/A *
0N/A * @return The value of the retrieved attribute.
0N/A *
0N/A * @exception AttributeNotFoundException The attribute specified
0N/A * is not accessible in the MBean.
0N/A * @exception MBeanException Wraps an exception thrown by the
0N/A * MBean's getter.
0N/A * @exception InstanceNotFoundException The MBean specified is not
0N/A * registered in the MBean server.
0N/A * @exception ReflectionException Wraps an
0N/A * <CODE>{@link java.lang.Exception}</CODE> thrown when trying to
0N/A * invoke the setter.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
0N/A * The object name in parameter is null or the attribute in
0N/A * parameter is null.
0N/A */
0N/A public Object getAttribute(ObjectName name, String attribute)
0N/A throws MBeanException, AttributeNotFoundException,
0N/A InstanceNotFoundException, ReflectionException {
0N/A
0N/A return mbsInterceptor.getAttribute(cloneObjectName(name), attribute);
0N/A }
0N/A
0N/A
0N/A /**
0N/A * Enables the values of several attributes of a named MBean. The MBean
0N/A * is identified by its object name.
0N/A *
0N/A * @param name The object name of the MBean from which the attributes are
0N/A * retrieved.
0N/A * @param attributes A list of the attributes to be retrieved.
0N/A *
0N/A * @return The list of the retrieved attributes.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean specified is not
0N/A * registered in the MBean server.
0N/A * @exception ReflectionException An exception occurred when trying
0N/A * to invoke the getAttributes method of a Dynamic MBean.
0N/A * @exception RuntimeOperationsException Wrap an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
0N/A * object name in parameter is null or attributes in parameter
0N/A * is null.
0N/A *
0N/A */
0N/A public AttributeList getAttributes(ObjectName name, String[] attributes)
0N/A throws InstanceNotFoundException, ReflectionException {
0N/A
0N/A return mbsInterceptor.getAttributes(cloneObjectName(name), attributes);
0N/A
0N/A }
0N/A
0N/A /**
0N/A * Sets the value of a specific attribute of a named MBean. The MBean
0N/A * is identified by its object name.
0N/A *
0N/A * @param name The name of the MBean within which the attribute is
0N/A * to be set.
0N/A * @param attribute The identification of the attribute to be set
0N/A * and the value it is to be set to.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean specified is
0N/A * not registered in the MBean server.
0N/A * @exception AttributeNotFoundException The attribute specified is
0N/A * not accessible in the MBean.
0N/A * @exception InvalidAttributeValueException The value specified for
0N/A * the attribute is not valid.
0N/A * @exception MBeanException Wraps an exception thrown by the
0N/A * MBean's setter.
0N/A * @exception ReflectionException Wraps an
0N/A * <CODE>{@link java.lang.Exception}</CODE> thrown when trying
0N/A * to invoke the setter.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
0N/A * object name in parameter is null or the attribute in parameter
0N/A * is null.
0N/A */
0N/A public void setAttribute(ObjectName name, Attribute attribute)
0N/A throws InstanceNotFoundException, AttributeNotFoundException,
0N/A InvalidAttributeValueException, MBeanException,
0N/A ReflectionException {
0N/A
0N/A mbsInterceptor.setAttribute(cloneObjectName(name),
0N/A cloneAttribute(attribute));
0N/A }
0N/A
0N/A /**
0N/A * Sets the values of several attributes of a named MBean. The MBean is
0N/A * identified by its object name.
0N/A *
0N/A * @param name The object name of the MBean within which the
0N/A * attributes are to be set.
0N/A * @param attributes A list of attributes: The identification of the
0N/A * attributes to be set and the values they are to be set to.
0N/A *
0N/A * @return The list of attributes that were set, with their new values.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean specified is not
0N/A * registered in the MBean server.
0N/A * @exception ReflectionException An exception occurred when trying
0N/A * to invoke the getAttributes method of a Dynamic MBean.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
0N/A * The object name in parameter is null or attributes in
0N/A * parameter is null.
0N/A *
0N/A */
0N/A public AttributeList setAttributes(ObjectName name,
0N/A AttributeList attributes)
0N/A throws InstanceNotFoundException, ReflectionException {
0N/A
0N/A return mbsInterceptor.setAttributes(cloneObjectName(name),
0N/A cloneAttributeList(attributes));
0N/A }
0N/A
0N/A /**
0N/A * Invokes an operation on an MBean.
0N/A *
0N/A * @param name The object name of the MBean on which the method is to be
0N/A * invoked.
0N/A * @param operationName The name of the operation to be invoked.
0N/A * @param params An array containing the parameters to be set when
0N/A * the operation is invoked
0N/A * @param signature An array containing the signature of the operation.
0N/A * The class objects will be loaded using the same class loader as
0N/A * the one used for loading the MBean on which the operation was
0N/A * invoked.
0N/A *
0N/A * @return The object returned by the operation, which represents the
0N/A * result ofinvoking the operation on the MBean specified.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean specified is not
0N/A * registered in the MBean server.
0N/A * @exception MBeanException Wraps an exception thrown by the MBean's
0N/A * invoked method.
0N/A * @exception ReflectionException Wraps an
0N/A * <CODE>{@link java.lang.Exception}</CODE> thrown while trying
0N/A * to invoke the method.
0N/A *
0N/A */
0N/A public Object invoke(ObjectName name, String operationName,
0N/A Object params[], String signature[])
0N/A throws InstanceNotFoundException, MBeanException,
0N/A ReflectionException {
0N/A return mbsInterceptor.invoke(cloneObjectName(name), operationName,
0N/A params, signature);
0N/A }
0N/A
0N/A /**
0N/A * Returns the default domain used for naming the MBean.
0N/A * The default domain name is used as the domain part in the ObjectName
0N/A * of MBeans if no domain is specified by the user.
0N/A */
0N/A public String getDefaultDomain() {
0N/A return mbsInterceptor.getDefaultDomain();
0N/A }
0N/A
0N/A // From MBeanServer
0N/A public String[] getDomains() {
0N/A return mbsInterceptor.getDomains();
0N/A }
0N/A
0N/A /**
0N/A * Adds a listener to a registered MBean.
0N/A *
0N/A * @param name The name of the MBean on which the listener should be added.
0N/A * @param listener The listener object which will handle the
0N/A * notifications emitted by the registered MBean.
0N/A * @param filter The filter object. If filter is null, no filtering
0N/A * will be performed before handling notifications.
0N/A * @param handback The context to be sent to the listener when a
0N/A * notification is emitted.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean name provided does
0N/A * not match any of the registered MBeans.
0N/A */
0N/A public void addNotificationListener(ObjectName name,
0N/A NotificationListener listener,
0N/A NotificationFilter filter,
0N/A Object handback)
0N/A throws InstanceNotFoundException {
0N/A
0N/A mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,
0N/A filter, handback);
0N/A }
0N/A
0N/A /**
0N/A * Adds a listener to a registered MBean.
0N/A *
0N/A * @param name The name of the MBean on which the listener should be added.
0N/A * @param listener The object name of the listener which will handle the
0N/A * notifications emitted by the registered MBean.
0N/A * @param filter The filter object. If filter is null, no filtering will
0N/A * be performed before handling notifications.
0N/A * @param handback The context to be sent to the listener when a
0N/A * notification is emitted.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean name of the
0N/A * notification listener or of the notification broadcaster
0N/A * does not match any of the registered MBeans.
0N/A */
0N/A public void addNotificationListener(ObjectName name, ObjectName listener,
0N/A NotificationFilter filter, Object handback)
0N/A throws InstanceNotFoundException {
0N/A
0N/A mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,
0N/A filter, handback);
0N/A }
0N/A
0N/A public void removeNotificationListener(ObjectName name,
0N/A NotificationListener listener)
0N/A throws InstanceNotFoundException, ListenerNotFoundException {
0N/A
0N/A mbsInterceptor.removeNotificationListener(cloneObjectName(name),
0N/A listener);
0N/A }
0N/A
0N/A public void removeNotificationListener(ObjectName name,
0N/A NotificationListener listener,
0N/A NotificationFilter filter,
0N/A Object handback)
0N/A throws InstanceNotFoundException, ListenerNotFoundException {
0N/A
0N/A mbsInterceptor.removeNotificationListener(cloneObjectName(name),
0N/A listener, filter, handback);
0N/A }
0N/A
0N/A public void removeNotificationListener(ObjectName name,
0N/A ObjectName listener)
0N/A throws InstanceNotFoundException, ListenerNotFoundException {
0N/A
0N/A mbsInterceptor.removeNotificationListener(cloneObjectName(name),
0N/A listener);
0N/A }
0N/A
0N/A public void removeNotificationListener(ObjectName name,
0N/A ObjectName listener,
0N/A NotificationFilter filter,
0N/A Object handback)
0N/A throws InstanceNotFoundException, ListenerNotFoundException {
0N/A
0N/A mbsInterceptor.removeNotificationListener(cloneObjectName(name),
0N/A listener, filter, handback);
0N/A }
0N/A
0N/A /**
0N/A * This method discovers the attributes and operations that an MBean exposes
0N/A * for management.
0N/A *
0N/A * @param name The name of the MBean to analyze
0N/A *
0N/A * @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of
0N/A * all attributes and operations of this MBean.
0N/A *
0N/A * @exception IntrospectionException An exception occurs during
0N/A * introspection.
0N/A * @exception InstanceNotFoundException The MBean specified is not found.
0N/A * @exception ReflectionException An exception occurred when trying to
0N/A * invoke the getMBeanInfo of a Dynamic MBean.
0N/A */
0N/A public MBeanInfo getMBeanInfo(ObjectName name) throws
0N/A InstanceNotFoundException, IntrospectionException, ReflectionException {
0N/A
0N/A return mbsInterceptor.getMBeanInfo(cloneObjectName(name));
0N/A }
0N/A
0N/A /**
0N/A * Instantiates an object using the list of all class loaders registered
0N/A * in the MBean server (using its
0N/A * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
0N/A * The object's class should have a public constructor.
0N/A * It returns a reference to the newly created object.
0N/A * The newly created object is not registered in the MBean server.
0N/A *
0N/A * @param className The class name of the object to be instantiated.
0N/A *
0N/A * @return The newly instantiated object.
0N/A *
0N/A * @exception ReflectionException Wraps the
0N/A * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
0N/A * <CODE>{@link java.lang.Exception}</CODE> that
0N/A * occurred when trying to invoke the object's constructor.
0N/A * @exception MBeanException The constructor of the object has thrown
0N/A * an exception.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
0N/A * The className passed in parameter is null.
0N/A *
0N/A */
0N/A public Object instantiate(String className)
0N/A throws ReflectionException, MBeanException {
0N/A
0N/A /* Permission check */
1790N/A checkMBeanPermission(className, null, null, "instantiate");
0N/A
0N/A return instantiator.instantiate(className);
0N/A }
0N/A
0N/A /**
0N/A * Instantiates an object using the class Loader specified by its
0N/A * <CODE>ObjectName</CODE>.
0N/A * If the loader name is null, the ClassLoader that loaded the
0N/A * MBean Server will be used.
0N/A * The object's class should have a public constructor.
0N/A * It returns a reference to the newly created object.
0N/A * The newly created object is not registered in the MBean server.
0N/A *
0N/A * @param className The class name of the MBean to be instantiated.
0N/A * @param loaderName The object name of the class loader to be used.
0N/A *
0N/A * @return The newly instantiated object.
0N/A *
0N/A * @exception ReflectionException Wraps the
0N/A * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
0N/A * <CODE>{@link java.lang.Exception}</CODE> that
0N/A * occurred when trying to invoke the object's constructor.
0N/A * @exception MBeanException The constructor of the object has thrown
0N/A * an exception.
0N/A * @exception InstanceNotFoundException The specified class loader
0N/A * is not registered in the MBaenServer.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The
0N/A * className passed in parameter is null.
0N/A *
0N/A */
0N/A public Object instantiate(String className, ObjectName loaderName)
0N/A throws ReflectionException, MBeanException,
0N/A InstanceNotFoundException {
0N/A
0N/A /* Permission check */
1790N/A checkMBeanPermission(className, null, null, "instantiate");
0N/A
0N/A ClassLoader myLoader = outerShell.getClass().getClassLoader();
0N/A return instantiator.instantiate(className, loaderName, myLoader);
0N/A }
0N/A
0N/A /**
0N/A * Instantiates an object using the list of all class loaders registered
0N/A * in the MBean server (using its
0N/A * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
0N/A * The object's class should have a public constructor.
0N/A * The call returns a reference to the newly created object.
0N/A * The newly created object is not registered in the MBean server.
0N/A *
0N/A * @param className The class name of the object to be instantiated.
0N/A * @param params An array containing the parameters of the constructor
0N/A * to be invoked.
0N/A * @param signature An array containing the signature of the
0N/A * constructor to be invoked.
0N/A *
0N/A * @return The newly instantiated object.
0N/A *
0N/A * @exception ReflectionException Wraps the
0N/A * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
0N/A * <CODE>{@link java.lang.Exception}</CODE> that
0N/A * occurred when trying to invoke the object's constructor.
0N/A * @exception MBeanException The constructor of the object has thrown
0N/A * an exception.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
0N/A * The className passed in parameter is null.
0N/A *
0N/A */
0N/A public Object instantiate(String className, Object params[],
0N/A String signature[])
0N/A throws ReflectionException, MBeanException {
0N/A
0N/A /* Permission check */
1790N/A checkMBeanPermission(className, null, null, "instantiate");
0N/A
0N/A ClassLoader myLoader = outerShell.getClass().getClassLoader();
0N/A return instantiator.instantiate(className, params, signature,
0N/A myLoader);
0N/A }
0N/A
0N/A /**
0N/A * Instantiates an object. The class loader to be used is identified
0N/A * by its object name. If the object name of the loader is null,
0N/A * the ClassLoader that loaded the MBean server will be used.
0N/A * The object's class should have a public constructor.
0N/A * The call returns a reference to the newly created object.
0N/A * The newly created object is not registered in the MBean server.
0N/A *
0N/A * @param className The class name of the object to be instantiated.
0N/A * @param params An array containing the parameters of the constructor
0N/A * to be invoked.
0N/A * @param signature An array containing the signature of the constructor
0N/A * to be invoked.
0N/A * @param loaderName The object name of the class loader to be used.
0N/A *
0N/A * @return The newly instantiated object.
0N/A *
0N/A * @exception ReflectionException Wraps the
0N/A * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the
0N/A * <CODE>{@link java.lang.Exception}</CODE> that
0N/A * occurred when trying to invoke the object's constructor.
0N/A * @exception MBeanException The constructor of the object has thrown
0N/A * an exception.
0N/A * @exception InstanceNotFoundException The specified class loader
0N/A * is not registered in the MBean server.
0N/A * @exception RuntimeOperationsException Wraps an
0N/A * <CODE>{@link java.lang.IllegalArgumentException}</CODE>:
0N/A * The className passed in parameter is null.
0N/A *
0N/A */
0N/A public Object instantiate(String className, ObjectName loaderName,
0N/A Object params[], String signature[])
0N/A throws ReflectionException, MBeanException,
0N/A InstanceNotFoundException {
0N/A
0N/A /* Permission check */
1790N/A checkMBeanPermission(className, null, null, "instantiate");
0N/A
0N/A ClassLoader myLoader = outerShell.getClass().getClassLoader();
0N/A return instantiator.instantiate(className,loaderName,params,signature,
0N/A myLoader);
0N/A }
0N/A
0N/A /**
0N/A * Returns true if the MBean specified is an instance of the specified
0N/A * class, false otherwise.
0N/A *
0N/A * @param name The <CODE>ObjectName</CODE> of the MBean.
0N/A * @param className The name of the class.
0N/A *
0N/A * @return true if the MBean specified is an instance of the specified
0N/A * class, false otherwise.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean specified is not
0N/A * registered in the MBean server.
0N/A */
0N/A public boolean isInstanceOf(ObjectName name, String className)
0N/A throws InstanceNotFoundException {
0N/A
0N/A return mbsInterceptor.isInstanceOf(cloneObjectName(name), className);
0N/A }
0N/A
0N/A /**
0N/A * De-serializes a byte array in the context of the class loader
0N/A * of an MBean.
0N/A *
0N/A * @param name The name of the MBean whose class loader should
0N/A * be used for the de-serialization.
0N/A * @param data The byte array to be de-sererialized.
0N/A *
0N/A * @return The de-serialized object stream.
0N/A *
0N/A * @exception InstanceNotFoundException The MBean specified is not
0N/A * found.
0N/A * @exception OperationsException Any of the usual Input/Output
0N/A * related exceptions.
0N/A *
0N/A */
0N/A @Deprecated
0N/A public ObjectInputStream deserialize(ObjectName name, byte[] data)
0N/A throws InstanceNotFoundException, OperationsException {
0N/A
0N/A /* Permission check */
0N/A // This call requires MBeanPermission 'getClassLoaderFor'
0N/A final ClassLoader loader = getClassLoaderFor(name);
0N/A
0N/A return instantiator.deserialize(loader, data);
0N/A }
0N/A
0N/A /**
0N/A * De-serializes a byte array in the context of a given MBean class loader.
0N/A * The class loader is the one that loaded the class with name "className".
0N/A *
0N/A * @param className The name of the class whose class loader should be
0N/A * used for the de-serialization.
0N/A * @param data The byte array to be de-sererialized.
0N/A *
0N/A * @return The de-serialized object stream.
0N/A *
0N/A * @exception OperationsException Any of the usual Input/Output
0N/A * related exceptions.
0N/A * @exception ReflectionException The specified class could not be
0N/A * loaded by the default loader repository
0N/A *
0N/A */
0N/A @Deprecated
0N/A public ObjectInputStream deserialize(String className, byte[] data)
0N/A throws OperationsException, ReflectionException {
0N/A
0N/A if (className == null) {
0N/A throw new RuntimeOperationsException(
0N/A new IllegalArgumentException(),
0N/A "Null className passed in parameter");
0N/A }
0N/A
0N/A /* Permission check */
0N/A // This call requires MBeanPermission 'getClassLoaderRepository'
0N/A final ClassLoaderRepository clr = getClassLoaderRepository();
0N/A
686N/A Class<?> theClass;
0N/A try {
0N/A if (clr == null) throw new ClassNotFoundException(className);
0N/A theClass = clr.loadClass(className);
0N/A } catch (ClassNotFoundException e) {
0N/A throw new ReflectionException(e,
0N/A "The given class could not be " +
0N/A "loaded by the default loader " +
0N/A "repository");
0N/A }
0N/A
0N/A return instantiator.deserialize(theClass.getClassLoader(), data);
0N/A }
0N/A
0N/A /**
0N/A * De-serializes a byte array in the context of a given MBean class loader.
0N/A * The class loader is the one that loaded the class with name "className".
0N/A * The name of the class loader to be used for loading the specified
0N/A * class is specified.
0N/A * If null, the MBean Server's class loader will be used.
0N/A *
0N/A * @param className The name of the class whose class loader should be
0N/A * used for the de-serialization.
0N/A * @param data The byte array to be de-sererialized.
0N/A * @param loaderName The name of the class loader to be used for
0N/A * loading the specified class.
0N/A * If null, the MBean Server's class loader will be used.
0N/A *
0N/A * @return The de-serialized object stream.
0N/A *
0N/A * @exception InstanceNotFoundException The specified class loader
0N/A * MBean is not found.
0N/A * @exception OperationsException Any of the usual Input/Output
0N/A * related exceptions.
0N/A * @exception ReflectionException The specified class could not
0N/A * be loaded by the specified class loader.
0N/A *
0N/A */
0N/A @Deprecated
0N/A public ObjectInputStream deserialize(String className,
0N/A ObjectName loaderName,
0N/A byte[] data) throws
0N/A InstanceNotFoundException, OperationsException, ReflectionException {
0N/A
0N/A // Clone ObjectName
0N/A //
0N/A loaderName = cloneObjectName(loaderName);
0N/A
0N/A /* Permission check */
0N/A // Make this call just to force the 'getClassLoader'
0N/A // permission check
0N/A try {
0N/A getClassLoader(loaderName);
0N/A } catch (SecurityException e) {
0N/A throw e;
0N/A } catch (Exception e) {
0N/A }
0N/A
0N/A ClassLoader myLoader = outerShell.getClass().getClassLoader();
0N/A return instantiator.deserialize(className, loaderName, data, myLoader);
0N/A }
0N/A
0N/A /**
0N/A * Initializes this MBeanServer, registering the MBeanServerDelegate.
0N/A * <p>This method must be called once, before using the MBeanServer.
0N/A **/
0N/A private void initialize() {
0N/A if (instantiator == null) throw new
0N/A IllegalStateException("instantiator must not be null.");
0N/A
0N/A // Registers the MBeanServer identification MBean
0N/A try {
0N/A AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
0N/A public Object run() throws Exception {
0N/A mbsInterceptor.registerMBean(
0N/A mBeanServerDelegateObject,
0N/A MBeanServerDelegate.DELEGATE_NAME);
0N/A return null;
0N/A }
0N/A });
0N/A } catch (SecurityException e) {
0N/A if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
0N/A MBEANSERVER_LOGGER.logp(Level.FINEST,
0N/A JmxMBeanServer.class.getName(), "initialize",
0N/A "Unexpected security exception occurred", e);
0N/A }
0N/A throw e;
0N/A } catch (Exception e) {
0N/A if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
0N/A MBEANSERVER_LOGGER.logp(Level.FINEST,
0N/A JmxMBeanServer.class.getName(), "initialize",
0N/A "Unexpected exception occurred", e);
0N/A }
0N/A throw new
528N/A IllegalStateException("Can't register delegate.",e);
0N/A }
0N/A
0N/A
0N/A /* Add my class loader to the repository
0N/A This can be null if my class loader is the bootstrap
0N/A class loader. The ClassLoaderRepository knows how
0N/A to handle that case. */
0N/A ClassLoader myLoader = outerShell.getClass().getClassLoader();
6293N/A final ModifiableClassLoaderRepository loaders = AccessController.doPrivileged(new PrivilegedAction<ModifiableClassLoaderRepository>() {
6293N/A
6293N/A @Override
6293N/A public ModifiableClassLoaderRepository run() {
6293N/A return instantiator.getClassLoaderRepository();
6293N/A }
6293N/A });
6293N/A
0N/A if (loaders != null) {
0N/A loaders.addClassLoader(myLoader);
0N/A
0N/A /* Add the system class loader, so that if the MBean server is
0N/A loaded by the bootstrap class loader we can still load
0N/A MBeans from the classpath using
0N/A createMBean(className, objectName).
0N/A
0N/A If this class (JmxMBeanServer) was not loaded by the
0N/A system class loader or a parent of it, then the caller
0N/A must have RuntimePermission("getClassLoader") for the
0N/A getSystemClassLoader() call to succeed. If the caller
0N/A does not have that permission, any call to
0N/A Class.getClassLoader() will fail. Since there are lots
0N/A of those in JMX, we better throw the exception now.
0N/A
0N/A This permission question is irrelevant when JMX is part
0N/A of J2SE (as of 1.5). */
0N/A ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
0N/A if (systemLoader != myLoader)
0N/A loaders.addClassLoader(systemLoader);
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Return the MBeanServerInterceptor.
0N/A * @exception UnsupportedOperationException if
0N/A * {@link MBeanServerInterceptor}s
0N/A * are not enabled on this object.
0N/A * @see #interceptorsEnabled
0N/A **/
528N/A public synchronized MBeanServer getMBeanServerInterceptor() {
0N/A if (interceptorsEnabled) return mbsInterceptor;
0N/A else throw new UnsupportedOperationException(
0N/A "MBeanServerInterceptors are disabled.");
0N/A }
0N/A
0N/A /**
0N/A * Set the MBeanServerInterceptor.
0N/A * @exception UnsupportedOperationException if
0N/A * {@link MBeanServerInterceptor}s
0N/A * are not enabled on this object.
0N/A * @see #interceptorsEnabled
0N/A **/
0N/A public synchronized void
528N/A setMBeanServerInterceptor(MBeanServer interceptor) {
0N/A if (!interceptorsEnabled) throw new UnsupportedOperationException(
0N/A "MBeanServerInterceptors are disabled.");
0N/A if (interceptor == null) throw new
0N/A IllegalArgumentException("MBeanServerInterceptor is null");
0N/A mbsInterceptor = interceptor;
0N/A }
0N/A
0N/A /**
0N/A * <p>Return the {@link java.lang.ClassLoader} that was used for
0N/A * loading the class of the named MBean.
0N/A * @param mbeanName The ObjectName of the MBean.
0N/A * @return The ClassLoader used for that MBean.
0N/A * @exception InstanceNotFoundException if the named MBean is not found.
0N/A */
0N/A public ClassLoader getClassLoaderFor(ObjectName mbeanName)
0N/A throws InstanceNotFoundException {
0N/A return mbsInterceptor.getClassLoaderFor(cloneObjectName(mbeanName));
0N/A }
0N/A
0N/A /**
0N/A * <p>Return the named {@link java.lang.ClassLoader}.
0N/A * @param loaderName The ObjectName of the ClassLoader.
0N/A * @return The named ClassLoader.
0N/A * @exception InstanceNotFoundException if the named ClassLoader
0N/A * is not found.
0N/A */
0N/A public ClassLoader getClassLoader(ObjectName loaderName)
0N/A throws InstanceNotFoundException {
0N/A return mbsInterceptor.getClassLoader(cloneObjectName(loaderName));
0N/A }
0N/A
0N/A /**
0N/A * <p>Return the ClassLoaderRepository for that MBeanServer.
0N/A * @return The ClassLoaderRepository for that MBeanServer.
0N/A **/
0N/A public ClassLoaderRepository getClassLoaderRepository() {
0N/A /* Permission check */
1790N/A checkMBeanPermission(null, null, null, "getClassLoaderRepository");
0N/A return secureClr;
0N/A }
0N/A
0N/A public MBeanServerDelegate getMBeanServerDelegate() {
0N/A if (!interceptorsEnabled) throw new UnsupportedOperationException(
0N/A "MBeanServerInterceptors are disabled.");
0N/A return mBeanServerDelegateObject;
0N/A }
0N/A
0N/A // These methods are called by the JMX MBeanServerBuilder.
0N/A
0N/A /**
0N/A * This method creates a new MBeanServerDelegate for a new MBeanServer.
0N/A * When creating a new MBeanServer the
0N/A * {@link javax.management.MBeanServerBuilder} first calls this method
0N/A * in order to create a new MBeanServerDelegate.
0N/A * <br>Then it calls
0N/A * <code>newMBeanServer(defaultDomain,outer,delegate,interceptors)</code>
0N/A * passing the <var>delegate</var> that should be used by the MBeanServer
0N/A * implementation.
0N/A * <p>Note that the passed <var>delegate</var> might not be directly the
0N/A * MBeanServerDelegate that was returned by this method. It could
0N/A * be, for instance, a new object wrapping the previously
0N/A * returned object.
0N/A *
0N/A * @return A new {@link javax.management.MBeanServerDelegate}.
0N/A **/
0N/A public static MBeanServerDelegate newMBeanServerDelegate() {
0N/A return new MBeanServerDelegateImpl();
0N/A }
0N/A
0N/A /**
0N/A * This method creates a new MBeanServer implementation object.
0N/A * When creating a new MBeanServer the
0N/A * {@link javax.management.MBeanServerBuilder} first calls
0N/A * <code>newMBeanServerDelegate()</code> in order to obtain a new
0N/A * {@link javax.management.MBeanServerDelegate} for the new
0N/A * MBeanServer. Then it calls
0N/A * <code>newMBeanServer(defaultDomain,outer,delegate)</code>
0N/A * passing the <var>delegate</var> that should be used by the
0N/A * MBeanServer implementation.
0N/A * <p>Note that the passed <var>delegate</var> might not be directly the
0N/A * MBeanServerDelegate that was returned by this implementation. It could
0N/A * be, for instance, a new object wrapping the previously
0N/A * returned delegate.
0N/A * <p>The <var>outer</var> parameter is a pointer to the MBeanServer that
0N/A * should be passed to the {@link javax.management.MBeanRegistration}
0N/A * interface when registering MBeans inside the MBeanServer.
0N/A * If <var>outer</var> is <code>null</code>, then the MBeanServer
0N/A * implementation is free to use its own <code>this</code> pointer when
0N/A * invoking the {@link javax.management.MBeanRegistration} interface.
0N/A * <p>This makes it possible for a MBeanServer implementation to wrap
0N/A * another MBeanServer implementation, in order to implement, e.g,
0N/A * security checks, or to prevent access to the actual MBeanServer
0N/A * implementation by returning a pointer to a wrapping object.
0N/A *
0N/A * @param defaultDomain Default domain of the new MBeanServer.
0N/A * @param outer A pointer to the MBeanServer object that must be
0N/A * passed to the MBeans when invoking their
0N/A * {@link javax.management.MBeanRegistration} interface.
0N/A * @param delegate A pointer to the MBeanServerDelegate associated
0N/A * with the new MBeanServer. The new MBeanServer must register
0N/A * this MBean in its MBean repository.
0N/A * @param interceptors If <code>true</code>,
0N/A * {@link MBeanServerInterceptor}s will be enabled (default is
0N/A * <code>false</code>).
0N/A * Note: this parameter is not taken into account by this
0N/A * implementation - the default value <code>false</code> is
0N/A * always used.
0N/A * @return A new private implementation of an MBeanServer.
0N/A * @see #interceptorsEnabled
0N/A * @see javax.management.MBeanServerBuilder
0N/A * @see com.sun.jmx.mbeanserver.JmxMBeanServerBuilder
0N/A **/
0N/A public static MBeanServer newMBeanServer(String defaultDomain,
0N/A MBeanServer outer,
0N/A MBeanServerDelegate delegate,
0N/A boolean interceptors) {
0N/A // Determine whether to use fair locking for the repository.
0N/A // Default is true.
0N/A final boolean fairLock = DEFAULT_FAIR_LOCK_POLICY;
0N/A
5789N/A checkNewMBeanServerPermission();
5789N/A
0N/A // This constructor happens to disregard the value of the interceptors
0N/A // flag - that is, it always uses the default value - false.
0N/A // This is admitedly a bug, but we chose not to fix it for now
0N/A // since we would rather not have anybody depending on the Sun private
0N/A // interceptor APIs - which is most probably going to be removed and
0N/A // replaced by a public (javax) feature in the future.
0N/A //
0N/A return new JmxMBeanServer(defaultDomain,outer,delegate,null,
0N/A interceptors,fairLock);
0N/A }
0N/A
0N/A // JMX OBJECT CLONING
0N/A //-------------------
0N/A
0N/A /**
0N/A * Clone object name.
0N/A */
0N/A private ObjectName cloneObjectName(ObjectName name) {
0N/A if (name != null) {
0N/A return ObjectName.getInstance(name);
0N/A }
0N/A return name;
0N/A }
0N/A
0N/A /**
0N/A * Clone attribute.
0N/A */
0N/A private Attribute cloneAttribute(Attribute attribute) {
0N/A if (attribute != null) {
0N/A if (!attribute.getClass().equals(Attribute.class)) {
0N/A return new Attribute(attribute.getName(), attribute.getValue());
0N/A }
0N/A }
0N/A return attribute;
0N/A }
0N/A
0N/A /**
0N/A * Clone attribute list.
0N/A */
0N/A private AttributeList cloneAttributeList(AttributeList list) {
0N/A if (list != null) {
686N/A List<Attribute> alist = list.asList();
0N/A if (!list.getClass().equals(AttributeList.class)) {
0N/A // Create new attribute list
0N/A //
686N/A AttributeList newList = new AttributeList(alist.size());
0N/A
0N/A // Iterate through list and replace non JMX attributes
0N/A //
686N/A for (Attribute attribute : alist)
0N/A newList.add(cloneAttribute(attribute));
0N/A return newList;
0N/A } else {
0N/A // Iterate through list and replace non JMX attributes
0N/A //
686N/A for (int i = 0; i < alist.size(); i++) {
686N/A Attribute attribute = alist.get(i);
0N/A if (!attribute.getClass().equals(Attribute.class)) {
0N/A list.set(i, cloneAttribute(attribute));
0N/A }
0N/A }
0N/A return list;
0N/A }
0N/A }
0N/A return list;
0N/A }
0N/A
0N/A // SECURITY CHECKS
0N/A //----------------
0N/A
1790N/A private static void checkMBeanPermission(String classname,
0N/A String member,
0N/A ObjectName objectName,
0N/A String actions)
0N/A throws SecurityException {
0N/A SecurityManager sm = System.getSecurityManager();
0N/A if (sm != null) {
1790N/A Permission perm = new MBeanPermission(classname,
0N/A member,
0N/A objectName,
0N/A actions);
0N/A sm.checkPermission(perm);
0N/A }
0N/A }
0N/A
5789N/A private static void checkNewMBeanServerPermission() {
5789N/A SecurityManager sm = System.getSecurityManager();
5789N/A if (sm != null) {
5789N/A Permission perm = new MBeanServerPermission("newMBeanServer");
5789N/A sm.checkPermission(perm);
5789N/A }
5789N/A }
0N/A}