/* * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.jmx.mbeanserver; import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;import com.sun.jmx.interceptor.MBeanServerInterceptor;import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; import java.io.ObjectInputStream;import java.security.AccessController;import java.security.Permission;import java.security.PrivilegedExceptionAction;import java.util.List;import java.util.Set;import java.util.logging.Level; import javax.management.Attribute;import javax.management.AttributeList;import javax.management.AttributeNotFoundException;import javax.management.InstanceAlreadyExistsException;import javax.management.InstanceNotFoundException;import javax.management.IntrospectionException;import javax.management.InvalidAttributeValueException;import javax.management.ListenerNotFoundException;import javax.management.MBeanException;import javax.management.MBeanInfo;import javax.management.MBeanPermission;import javax.management.MBeanRegistrationException;import javax.management.MBeanServer;import javax.management.MBeanServerDelegate;import javax.management.NotCompliantMBeanException;import javax.management.NotificationFilter;import javax.management.NotificationListener;import javax.management.ObjectInstance;import javax.management.ObjectName;import javax.management.OperationsException;import javax.management.QueryExp;import javax.management.ReflectionException;import javax.management.RuntimeOperationsException;import javax.management.loading.ClassLoaderRepository; /** * This is the base class for MBean manipulation on the agent side. It * contains the methods necessary for the creation, registration, and * deletion of MBeans as well as the access methods for registered MBeans. * This is the core component of the JMX infrastructure. * <P> * Every MBean which is added to the MBean server becomes manageable: * its attributes and operations become remotely accessible through * the connectors/adaptors connected to that MBean server. * A Java object cannot be registered in the MBean server unless it is a * JMX compliant MBean. * <P> * When an MBean is registered or unregistered in the MBean server an * {@link javax.management.MBeanServerNotification MBeanServerNotification} * Notification is emitted. To register an object as listener to * MBeanServerNotifications you should call the MBean server method * {@link #addNotificationListener addNotificationListener} with * the <CODE>ObjectName</CODE> of the * {@link javax.management.MBeanServerDelegate MBeanServerDelegate}. * This <CODE>ObjectName</CODE> is: * <BR> * <CODE>JMImplementation:type=MBeanServerDelegate</CODE>. * * @since 1.5 */public final class JmxMBeanServer implements SunJmxMBeanServer { /** Control the default locking policy of the repository. * By default, we will be using a fair locking policy. **/ public static final boolean DEFAULT_FAIR_LOCK_POLICY = true; private final MBeanInstantiator instantiator; private final SecureClassLoaderRepository secureClr; /** true if interceptors are enabled **/ private final boolean interceptorsEnabled; private final MBeanServer outerShell; private volatile MBeanServer mbsInterceptor = null; /** The MBeanServerDelegate object representing the MBean Server */ private final MBeanServerDelegate mBeanServerDelegateObject; /** * <b>Package:</b> Creates an MBeanServer with the * specified default domain name, outer interface, and delegate. * <p>The default domain name is used as the domain part in the ObjectName * of MBeans if no domain is specified by the user. * <ul><b>Note:</b>Using this constructor directly is strongly * discouraged. You should use * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)} * or * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)} * instead. * <p> * By default, interceptors are disabled. Use * {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them. * </ul> * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @exception IllegalArgumentException if the instantiator is null. */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate) { this(domain,outer,delegate,null,false); } /** * <b>Package:</b> Creates an MBeanServer with the * specified default domain name, outer interface, and delegate. * <p>The default domain name is used as the domain part in the ObjectName * of MBeans if no domain is specified by the user. * <ul><b>Note:</b>Using this constructor directly is strongly * discouraged. You should use * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)} * or * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)} * instead. * </ul> * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @param interceptors If <code>true</code>, * {@link MBeanServerInterceptor} will be enabled (default is * <code>false</code>) * Note: this parameter is not taken into account by this * implementation - the default value <code>false</code> is * always used. * @exception IllegalArgumentException if the instantiator is null. */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate, boolean interceptors) { this(domain,outer,delegate,null,false); } /** * <b>Package:</b> Creates an MBeanServer. * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @param instantiator The MBeanInstantiator that will be used to * instantiate MBeans and take care of class loading issues. * @param metadata The MetaData object that will be used by the * MBean server in order to invoke the MBean interface of * the registered MBeans. * @param interceptors If <code>true</code>, * {@link MBeanServerInterceptor} will be enabled (default is * <code>false</code>). */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate, MBeanInstantiator instantiator, boolean interceptors) { this(domain,outer,delegate,instantiator,interceptors,true); } /** * <b>Package:</b> Creates an MBeanServer. * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @param instantiator The MBeanInstantiator that will be used to * instantiate MBeans and take care of class loading issues. * @param metadata The MetaData object that will be used by the * MBean server in order to invoke the MBean interface of * the registered MBeans. * @param interceptors If <code>true</code>, * {@link MBeanServerInterceptor} will be enabled (default is * <code>false</code>). * @param fairLock If {@code true}, the MBean repository will use a {@link * java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean) * fair locking} policy. */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate, MBeanInstantiator instantiator, boolean interceptors, boolean fairLock) { if (instantiator == null) { final ModifiableClassLoaderRepository clr = new ClassLoaderRepositorySupport(); instantiator = new MBeanInstantiator(clr); } this.secureClr = new SecureClassLoaderRepository(instantiator.getClassLoaderRepository()); if (delegate == null) delegate = new MBeanServerDelegateImpl(); if (outer == null) outer = this; this.instantiator = instantiator; this.mBeanServerDelegateObject = delegate; this.outerShell = outer; final Repository repository = new Repository(domain); this.mbsInterceptor = new DefaultMBeanServerInterceptor(outer, delegate, instantiator, repository); this.interceptorsEnabled = interceptors; initialize(); } /** * Tell whether {@link MBeanServerInterceptor}s are enabled on this * object. * @return <code>true</code> if {@link MBeanServerInterceptor}s are * enabled. * @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean) **/ public boolean interceptorsEnabled() { return interceptorsEnabled; } /** * Return the MBeanInstantiator associated to this MBeanServer. * @exception UnsupportedOperationException if * {@link MBeanServerInterceptor}s * are not enabled on this object. * @see #interceptorsEnabled **/ public MBeanInstantiator getMBeanInstantiator() { if (interceptorsEnabled) return instantiator; else throw new UnsupportedOperationException( "MBeanServerInterceptors are disabled."); } /** * Instantiates and registers an MBean in the MBean server. * The MBean server will use its * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository} * to load the class of the MBean. * An object name is associated to the MBean. * If the object name given is null, the MBean can automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name of the newly * instantiated MBean. * * @exception ReflectionException Wraps an * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> that occurred * when trying to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has thrown * an exception. * @exception NotCompliantMBeanException This class is not a JMX * compliant MBean. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: * The className passed in parameter is null, the * <CODE>ObjectName</CODE> passed in parameter contains a pattern * or no <CODE>ObjectName</CODE> is specified for the MBean. * */ public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException { return mbsInterceptor.createMBean(className, cloneObjectName(name), (Object[]) null, (String[]) null); } /** * Instantiates and registers an MBean in the MBean server. * The class loader to be used is identified by its object name. * An object name is associated to the MBean. * If the object name of the loader is null, the ClassLoader that * loaded the MBean server will be used. * If the MBean's object name given is null, the MBean can * automatically provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * @param loaderName The object name of the class loader to be used. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name * of the newly instantiated MBean. * * @exception ReflectionException Wraps an * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> that occurred when trying * to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has thrown * an exception * @exception NotCompliantMBeanException This class is not a JMX * compliant MBean. * @exception InstanceNotFoundException The specified class loader * is not registered in the MBean server. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The * className passed in parameter is null, the <CODE>ObjectName</CODE> * passed in parameter contains a pattern or no * <CODE>ObjectName</CODE> is specified for the MBean. */ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException { return mbsInterceptor.createMBean(className, cloneObjectName(name), loaderName, (Object[]) null, (String[]) null); } /** * Instantiates and registers an MBean in the MBean server. * The MBean server will use its * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository} * to load the class of the MBean. * An object name is associated to the MBean. * If the object name given is null, the MBean can automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * @param params An array containing the parameters of the constructor * to be invoked. * @param signature An array containing the signature of the * constructor to be invoked. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name * of the newly instantiated MBean. * * @exception ReflectionException Wraps a * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> that occurred * when trying to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has * thrown an exception. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The * className passed in parameter is null, the <CODE>ObjectName</CODE> * passed in parameter contains a pattern or no * <CODE>ObjectName</CODE> is specified for the MBean. * */ public ObjectInstance createMBean(String className, ObjectName name, Object params[], String signature[]) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException { return mbsInterceptor.createMBean(className, cloneObjectName(name), params, signature); } /** * Instantiates and registers an MBean in the MBean server. * The class loader to be used is identified by its object name. * An object name is associated to the MBean. If the object name * of the loader is not specified, the ClassLoader that loaded the * MBean server will be used. * If the MBean object name given is null, the MBean can automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * @param params An array containing the parameters of the constructor * to be invoked. * @param signature An array containing the signature of the * constructor to be invoked. * @param loaderName The object name of the class loader to be used. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name of the newly * instantiated MBean. * * @exception ReflectionException Wraps a * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> * that occurred when trying to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has * thrown an exception * @exception InstanceNotFoundException The specified class loader is * not registered in the MBean server. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The * className passed in parameter is null, the <CODE>ObjectName</CODE> * passed in parameter contains a pattern or no * <CODE>ObjectName</CODE> is specified for the MBean. * */ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object params[], String signature[]) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException { return mbsInterceptor.createMBean(className, cloneObjectName(name), loaderName, params, signature); } /** * Registers a pre-existing object as an MBean with the MBean server. * If the object name given is null, the MBean may automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the registered MBean. * * @param object The MBean to be registered as an MBean. * @param name The object name of the MBean. May be null. * * @return The <CODE>ObjectInstance</CODE> for the MBean that has been * registered. * * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered.Lines 1–500 of 1497. Load more
/* * Copyright (c) 1999, 2008, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. */ package com.sun.jmx.mbeanserver; import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor; import com.sun.jmx.interceptor.MBeanServerInterceptor; import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; import java.io.ObjectInputStream; import java.security.AccessController; import java.security.Permission; import java.security.PrivilegedExceptionAction; import java.util.List; import java.util.Set; import java.util.logging.Level; import javax.management.Attribute; import javax.management.AttributeList; import javax.management.AttributeNotFoundException; import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceNotFoundException; import javax.management.IntrospectionException; import javax.management.InvalidAttributeValueException; import javax.management.ListenerNotFoundException; import javax.management.MBeanException; import javax.management.MBeanInfo; import javax.management.MBeanPermission; import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; import javax.management.MBeanServerDelegate; import javax.management.NotCompliantMBeanException; import javax.management.NotificationFilter; import javax.management.NotificationListener; import javax.management.ObjectInstance; import javax.management.ObjectName; import javax.management.OperationsException; import javax.management.QueryExp; import javax.management.ReflectionException; import javax.management.RuntimeOperationsException; import javax.management.loading.ClassLoaderRepository; /** * This is the base class for MBean manipulation on the agent side. It * contains the methods necessary for the creation, registration, and * deletion of MBeans as well as the access methods for registered MBeans. * This is the core component of the JMX infrastructure. * <P> * Every MBean which is added to the MBean server becomes manageable: * its attributes and operations become remotely accessible through * the connectors/adaptors connected to that MBean server. * A Java object cannot be registered in the MBean server unless it is a * JMX compliant MBean. * <P> * When an MBean is registered or unregistered in the MBean server an * {@link javax.management.MBeanServerNotification MBeanServerNotification} * Notification is emitted. To register an object as listener to * MBeanServerNotifications you should call the MBean server method * {@link #addNotificationListener addNotificationListener} with * the <CODE>ObjectName</CODE> of the * {@link javax.management.MBeanServerDelegate MBeanServerDelegate}. * This <CODE>ObjectName</CODE> is: * <BR> * <CODE>JMImplementation:type=MBeanServerDelegate</CODE>. * * @since 1.5 */ public final class JmxMBeanServer implements SunJmxMBeanServer { /** Control the default locking policy of the repository. * By default, we will be using a fair locking policy. **/ public static final boolean DEFAULT_FAIR_LOCK_POLICY = true; private final MBeanInstantiator instantiator; private final SecureClassLoaderRepository secureClr; /** true if interceptors are enabled **/ private final boolean interceptorsEnabled; private final MBeanServer outerShell; private volatile MBeanServer mbsInterceptor = null; /** The MBeanServerDelegate object representing the MBean Server */ private final MBeanServerDelegate mBeanServerDelegateObject; /** * <b>Package:</b> Creates an MBeanServer with the * specified default domain name, outer interface, and delegate. * <p>The default domain name is used as the domain part in the ObjectName * of MBeans if no domain is specified by the user. * <ul><b>Note:</b>Using this constructor directly is strongly * discouraged. You should use * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)} * or * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)} * instead. * <p> * By default, interceptors are disabled. Use * {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them. * </ul> * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @exception IllegalArgumentException if the instantiator is null. */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate) { this(domain,outer,delegate,null,false); } /** * <b>Package:</b> Creates an MBeanServer with the * specified default domain name, outer interface, and delegate. * <p>The default domain name is used as the domain part in the ObjectName * of MBeans if no domain is specified by the user. * <ul><b>Note:</b>Using this constructor directly is strongly * discouraged. You should use * {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)} * or * {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)} * instead. * </ul> * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @param interceptors If <code>true</code>, * {@link MBeanServerInterceptor} will be enabled (default is * <code>false</code>) * Note: this parameter is not taken into account by this * implementation - the default value <code>false</code> is * always used. * @exception IllegalArgumentException if the instantiator is null. */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate, boolean interceptors) { this(domain,outer,delegate,null,false); } /** * <b>Package:</b> Creates an MBeanServer. * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @param instantiator The MBeanInstantiator that will be used to * instantiate MBeans and take care of class loading issues. * @param metadata The MetaData object that will be used by the * MBean server in order to invoke the MBean interface of * the registered MBeans. * @param interceptors If <code>true</code>, * {@link MBeanServerInterceptor} will be enabled (default is * <code>false</code>). */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate, MBeanInstantiator instantiator, boolean interceptors) { this(domain,outer,delegate,instantiator,interceptors,true); } /** * <b>Package:</b> Creates an MBeanServer. * @param domain The default domain name used by this MBeanServer. * @param outer A pointer to the MBeanServer object that must be * passed to the MBeans when invoking their * {@link javax.management.MBeanRegistration} interface. * @param delegate A pointer to the MBeanServerDelegate associated * with the new MBeanServer. The new MBeanServer must register * this MBean in its MBean repository. * @param instantiator The MBeanInstantiator that will be used to * instantiate MBeans and take care of class loading issues. * @param metadata The MetaData object that will be used by the * MBean server in order to invoke the MBean interface of * the registered MBeans. * @param interceptors If <code>true</code>, * {@link MBeanServerInterceptor} will be enabled (default is * <code>false</code>). * @param fairLock If {@code true}, the MBean repository will use a {@link * java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean) * fair locking} policy. */ JmxMBeanServer(String domain, MBeanServer outer, MBeanServerDelegate delegate, MBeanInstantiator instantiator, boolean interceptors, boolean fairLock) { if (instantiator == null) { final ModifiableClassLoaderRepository clr = new ClassLoaderRepositorySupport(); instantiator = new MBeanInstantiator(clr); } this.secureClr = new SecureClassLoaderRepository(instantiator.getClassLoaderRepository()); if (delegate == null) delegate = new MBeanServerDelegateImpl(); if (outer == null) outer = this; this.instantiator = instantiator; this.mBeanServerDelegateObject = delegate; this.outerShell = outer; final Repository repository = new Repository(domain); this.mbsInterceptor = new DefaultMBeanServerInterceptor(outer, delegate, instantiator, repository); this.interceptorsEnabled = interceptors; initialize(); } /** * Tell whether {@link MBeanServerInterceptor}s are enabled on this * object. * @return <code>true</code> if {@link MBeanServerInterceptor}s are * enabled. * @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean) **/ public boolean interceptorsEnabled() { return interceptorsEnabled; } /** * Return the MBeanInstantiator associated to this MBeanServer. * @exception UnsupportedOperationException if * {@link MBeanServerInterceptor}s * are not enabled on this object. * @see #interceptorsEnabled **/ public MBeanInstantiator getMBeanInstantiator() { if (interceptorsEnabled) return instantiator; else throw new UnsupportedOperationException( "MBeanServerInterceptors are disabled."); } /** * Instantiates and registers an MBean in the MBean server. * The MBean server will use its * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository} * to load the class of the MBean. * An object name is associated to the MBean. * If the object name given is null, the MBean can automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name of the newly * instantiated MBean. * * @exception ReflectionException Wraps an * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> that occurred * when trying to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has thrown * an exception. * @exception NotCompliantMBeanException This class is not a JMX * compliant MBean. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: * The className passed in parameter is null, the * <CODE>ObjectName</CODE> passed in parameter contains a pattern * or no <CODE>ObjectName</CODE> is specified for the MBean. * */ public ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException { return mbsInterceptor.createMBean(className, cloneObjectName(name), (Object[]) null, (String[]) null); } /** * Instantiates and registers an MBean in the MBean server. * The class loader to be used is identified by its object name. * An object name is associated to the MBean. * If the object name of the loader is null, the ClassLoader that * loaded the MBean server will be used. * If the MBean's object name given is null, the MBean can * automatically provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * @param loaderName The object name of the class loader to be used. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name * of the newly instantiated MBean. * * @exception ReflectionException Wraps an * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> that occurred when trying * to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has thrown * an exception * @exception NotCompliantMBeanException This class is not a JMX * compliant MBean. * @exception InstanceNotFoundException The specified class loader * is not registered in the MBean server. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The * className passed in parameter is null, the <CODE>ObjectName</CODE> * passed in parameter contains a pattern or no * <CODE>ObjectName</CODE> is specified for the MBean. */ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException { return mbsInterceptor.createMBean(className, cloneObjectName(name), loaderName, (Object[]) null, (String[]) null); } /** * Instantiates and registers an MBean in the MBean server. * The MBean server will use its * {@link javax.management.loading.ClassLoaderRepository Default Loader Repository} * to load the class of the MBean. * An object name is associated to the MBean. * If the object name given is null, the MBean can automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * @param params An array containing the parameters of the constructor * to be invoked. * @param signature An array containing the signature of the * constructor to be invoked. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name * of the newly instantiated MBean. * * @exception ReflectionException Wraps a * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> that occurred * when trying to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has * thrown an exception. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The * className passed in parameter is null, the <CODE>ObjectName</CODE> * passed in parameter contains a pattern or no * <CODE>ObjectName</CODE> is specified for the MBean. * */ public ObjectInstance createMBean(String className, ObjectName name, Object params[], String signature[]) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException { return mbsInterceptor.createMBean(className, cloneObjectName(name), params, signature); } /** * Instantiates and registers an MBean in the MBean server. * The class loader to be used is identified by its object name. * An object name is associated to the MBean. If the object name * of the loader is not specified, the ClassLoader that loaded the * MBean server will be used. * If the MBean object name given is null, the MBean can automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the newly created MBean. * * @param className The class name of the MBean to be instantiated. * @param name The object name of the MBean. May be null. * @param params An array containing the parameters of the constructor * to be invoked. * @param signature An array containing the signature of the * constructor to be invoked. * @param loaderName The object name of the class loader to be used. * * @return An <CODE>ObjectInstance</CODE>, containing the * <CODE>ObjectName</CODE> and the Java class name of the newly * instantiated MBean. * * @exception ReflectionException Wraps a * <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an * <CODE>{@link java.lang.Exception}</CODE> * that occurred when trying to invoke the MBean's constructor. * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered. * @exception MBeanException The constructor of the MBean has * thrown an exception * @exception InstanceNotFoundException The specified class loader is * not registered in the MBean server. * @exception RuntimeOperationsException Wraps an * <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The * className passed in parameter is null, the <CODE>ObjectName</CODE> * passed in parameter contains a pattern or no * <CODE>ObjectName</CODE> is specified for the MBean. * */ public ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object params[], String signature[]) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException { return mbsInterceptor.createMBean(className, cloneObjectName(name), loaderName, params, signature); } /** * Registers a pre-existing object as an MBean with the MBean server. * If the object name given is null, the MBean may automatically * provide its own name by implementing the * {@link javax.management.MBeanRegistration MBeanRegistration} interface. * The call returns an <CODE>ObjectInstance</CODE> object representing * the registered MBean. * * @param object The MBean to be registered as an MBean. * @param name The object name of the MBean. May be null. * * @return The <CODE>ObjectInstance</CODE> for the MBean that has been * registered. * * @exception InstanceAlreadyExistsException The MBean is already * under the control of the MBean server. * @exception MBeanRegistrationException The <CODE>preRegister()</CODE> * (<CODE>MBeanRegistration</CODE> interface) method of the MBean * has thrown an exception. The MBean will not be registered.