Path: blob/master/src/java.management/share/classes/com/sun/jmx/mbeanserver/JmxMBeanServer.java
41161 views
/*1* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.jmx.mbeanserver;2627import com.sun.jmx.interceptor.DefaultMBeanServerInterceptor;28import com.sun.jmx.interceptor.MBeanServerInterceptor;29import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER;3031import java.io.ObjectInputStream;32import java.security.AccessController;33import java.security.Permission;34import java.security.PrivilegedAction;35import java.security.PrivilegedExceptionAction;36import java.util.List;37import java.util.Set;38import java.lang.System.Logger.Level;3940import javax.management.Attribute;41import javax.management.AttributeList;42import javax.management.AttributeNotFoundException;43import javax.management.InstanceAlreadyExistsException;44import javax.management.InstanceNotFoundException;45import javax.management.IntrospectionException;46import javax.management.InvalidAttributeValueException;47import javax.management.ListenerNotFoundException;48import javax.management.MBeanException;49import javax.management.MBeanInfo;50import javax.management.MBeanPermission;51import javax.management.MBeanRegistrationException;52import javax.management.MBeanServer;53import javax.management.MBeanServerDelegate;54import javax.management.MBeanServerPermission;55import javax.management.NotCompliantMBeanException;56import javax.management.NotificationFilter;57import javax.management.NotificationListener;58import javax.management.ObjectInstance;59import javax.management.ObjectName;60import javax.management.OperationsException;61import javax.management.QueryExp;62import javax.management.ReflectionException;63import javax.management.RuntimeOperationsException;64import javax.management.loading.ClassLoaderRepository;6566/**67* This is the base class for MBean manipulation on the agent side. It68* contains the methods necessary for the creation, registration, and69* deletion of MBeans as well as the access methods for registered MBeans.70* This is the core component of the JMX infrastructure.71* <P>72* Every MBean which is added to the MBean server becomes manageable:73* its attributes and operations become remotely accessible through74* the connectors/adaptors connected to that MBean server.75* A Java object cannot be registered in the MBean server unless it is a76* JMX compliant MBean.77* <P>78* When an MBean is registered or unregistered in the MBean server an79* {@link javax.management.MBeanServerNotification MBeanServerNotification}80* Notification is emitted. To register an object as listener to81* MBeanServerNotifications you should call the MBean server method82* {@link #addNotificationListener addNotificationListener} with83* the <CODE>ObjectName</CODE> of the84* {@link javax.management.MBeanServerDelegate MBeanServerDelegate}.85* This <CODE>ObjectName</CODE> is:86* <BR>87* <CODE>JMImplementation:type=MBeanServerDelegate</CODE>.88*89* @since 1.590*/91public final class JmxMBeanServer92implements SunJmxMBeanServer {9394/** Control the default locking policy of the repository.95* By default, we will be using a fair locking policy.96**/97public static final boolean DEFAULT_FAIR_LOCK_POLICY = true;9899private final MBeanInstantiator instantiator;100private final SecureClassLoaderRepository secureClr;101102/** true if interceptors are enabled **/103private final boolean interceptorsEnabled;104105private final MBeanServer outerShell;106107private volatile MBeanServer mbsInterceptor = null;108109/** The MBeanServerDelegate object representing the MBean Server */110private final MBeanServerDelegate mBeanServerDelegateObject;111112/**113* <b>Package:</b> Creates an MBeanServer with the114* specified default domain name, outer interface, and delegate.115* <p>The default domain name is used as the domain part in the ObjectName116* of MBeans if no domain is specified by the user.117* <ul><b>Note:</b>Using this constructor directly is strongly118* discouraged. You should use119* {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)}120* or121* {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)}122* instead.123* <p>124* By default, interceptors are disabled. Use125* {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them.126* </ul>127* @param domain The default domain name used by this MBeanServer.128* @param outer A pointer to the MBeanServer object that must be129* passed to the MBeans when invoking their130* {@link javax.management.MBeanRegistration} interface.131* @param delegate A pointer to the MBeanServerDelegate associated132* with the new MBeanServer. The new MBeanServer must register133* this MBean in its MBean repository.134* @exception IllegalArgumentException if the instantiator is null.135*/136JmxMBeanServer(String domain, MBeanServer outer,137MBeanServerDelegate delegate) {138this(domain,outer,delegate,null,false);139}140141/**142* <b>Package:</b> Creates an MBeanServer with the143* specified default domain name, outer interface, and delegate.144* <p>The default domain name is used as the domain part in the ObjectName145* of MBeans if no domain is specified by the user.146* <ul><b>Note:</b>Using this constructor directly is strongly147* discouraged. You should use148* {@link javax.management.MBeanServerFactory#createMBeanServer(java.lang.String)}149* or150* {@link javax.management.MBeanServerFactory#newMBeanServer(java.lang.String)}151* instead.152* </ul>153* @param domain The default domain name used by this MBeanServer.154* @param outer A pointer to the MBeanServer object that must be155* passed to the MBeans when invoking their156* {@link javax.management.MBeanRegistration} interface.157* @param delegate A pointer to the MBeanServerDelegate associated158* with the new MBeanServer. The new MBeanServer must register159* this MBean in its MBean repository.160* @param interceptors If <code>true</code>,161* {@link MBeanServerInterceptor} will be enabled (default is162* <code>false</code>)163* Note: this parameter is not taken into account by this164* implementation - the default value <code>false</code> is165* always used.166* @exception IllegalArgumentException if the instantiator is null.167*/168JmxMBeanServer(String domain, MBeanServer outer,169MBeanServerDelegate delegate, boolean interceptors) {170this(domain,outer,delegate,null,false);171}172173/**174* <b>Package:</b> Creates an MBeanServer.175* @param domain The default domain name used by this MBeanServer.176* @param outer A pointer to the MBeanServer object that must be177* passed to the MBeans when invoking their178* {@link javax.management.MBeanRegistration} interface.179* @param delegate A pointer to the MBeanServerDelegate associated180* with the new MBeanServer. The new MBeanServer must register181* this MBean in its MBean repository.182* @param instantiator The MBeanInstantiator that will be used to183* instantiate MBeans and take care of class loading issues.184* @param metadata The MetaData object that will be used by the185* MBean server in order to invoke the MBean interface of186* the registered MBeans.187* @param interceptors If <code>true</code>,188* {@link MBeanServerInterceptor} will be enabled (default is189* <code>false</code>).190*/191JmxMBeanServer(String domain, MBeanServer outer,192MBeanServerDelegate delegate,193MBeanInstantiator instantiator,194boolean interceptors) {195this(domain,outer,delegate,instantiator,interceptors,true);196}197198/**199* <b>Package:</b> Creates an MBeanServer.200* @param domain The default domain name used by this MBeanServer.201* @param outer A pointer to the MBeanServer object that must be202* passed to the MBeans when invoking their203* {@link javax.management.MBeanRegistration} interface.204* @param delegate A pointer to the MBeanServerDelegate associated205* with the new MBeanServer. The new MBeanServer must register206* this MBean in its MBean repository.207* @param instantiator The MBeanInstantiator that will be used to208* instantiate MBeans and take care of class loading issues.209* @param metadata The MetaData object that will be used by the210* MBean server in order to invoke the MBean interface of211* the registered MBeans.212* @param interceptors If <code>true</code>,213* {@link MBeanServerInterceptor} will be enabled (default is214* <code>false</code>).215* @param fairLock If {@code true}, the MBean repository will use a {@link216* java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)217* fair locking} policy.218*/219@SuppressWarnings("removal")220JmxMBeanServer(String domain, MBeanServer outer,221MBeanServerDelegate delegate,222MBeanInstantiator instantiator,223boolean interceptors,224boolean fairLock) {225226if (instantiator == null) {227final ModifiableClassLoaderRepository228clr = new ClassLoaderRepositorySupport();229instantiator = new MBeanInstantiator(clr);230}231232final MBeanInstantiator fInstantiator = instantiator;233this.secureClr = new234SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {235@Override236public ClassLoaderRepository run() {237return fInstantiator.getClassLoaderRepository();238}239})240);241if (delegate == null)242delegate = new MBeanServerDelegateImpl();243if (outer == null)244outer = this;245246this.instantiator = instantiator;247this.mBeanServerDelegateObject = delegate;248this.outerShell = outer;249250final Repository repository = new Repository(domain);251this.mbsInterceptor =252new DefaultMBeanServerInterceptor(outer, delegate, instantiator,253repository);254this.interceptorsEnabled = interceptors;255initialize();256}257258/**259* Tell whether {@link MBeanServerInterceptor}s are enabled on this260* object.261* @return <code>true</code> if {@link MBeanServerInterceptor}s are262* enabled.263* @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)264**/265public boolean interceptorsEnabled() {266return interceptorsEnabled;267}268269/**270* Return the MBeanInstantiator associated to this MBeanServer.271* @exception UnsupportedOperationException if272* {@link MBeanServerInterceptor}s273* are not enabled on this object.274* @see #interceptorsEnabled275**/276public MBeanInstantiator getMBeanInstantiator() {277if (interceptorsEnabled) return instantiator;278else throw new UnsupportedOperationException(279"MBeanServerInterceptors are disabled.");280}281282/**283* Instantiates and registers an MBean in the MBean server.284* The MBean server will use its285* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}286* to load the class of the MBean.287* An object name is associated to the MBean.288* If the object name given is null, the MBean can automatically289* provide its own name by implementing the290* {@link javax.management.MBeanRegistration MBeanRegistration} interface.291* The call returns an <CODE>ObjectInstance</CODE> object representing292* the newly created MBean.293*294* @param className The class name of the MBean to be instantiated.295* @param name The object name of the MBean. May be null.296*297* @return An <CODE>ObjectInstance</CODE>, containing the298* <CODE>ObjectName</CODE> and the Java class name of the newly299* instantiated MBean.300*301* @exception ReflectionException Wraps an302* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an303* <CODE>{@link java.lang.Exception}</CODE> that occurred304* when trying to invoke the MBean's constructor.305* @exception InstanceAlreadyExistsException The MBean is already306* under the control of the MBean server.307* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>308* (<CODE>MBeanRegistration</CODE> interface) method of the MBean309* has thrown an exception. The MBean will not be registered.310* @exception MBeanException The constructor of the MBean has thrown311* an exception.312* @exception NotCompliantMBeanException This class is not a JMX313* compliant MBean.314* @exception RuntimeOperationsException Wraps an315* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:316* The className passed in parameter is null, the317* <CODE>ObjectName</CODE> passed in parameter contains a pattern318* or no <CODE>ObjectName</CODE> is specified for the MBean.319*320*/321public ObjectInstance createMBean(String className, ObjectName name)322throws ReflectionException, InstanceAlreadyExistsException,323MBeanRegistrationException, MBeanException,324NotCompliantMBeanException {325326return mbsInterceptor.createMBean(className,327cloneObjectName(name),328(Object[]) null,329(String[]) null);330}331332/**333* Instantiates and registers an MBean in the MBean server.334* The class loader to be used is identified by its object name.335* An object name is associated to the MBean.336* If the object name of the loader is null, the ClassLoader that337* loaded the MBean server will be used.338* If the MBean's object name given is null, the MBean can339* automatically provide its own name by implementing the340* {@link javax.management.MBeanRegistration MBeanRegistration} interface.341* The call returns an <CODE>ObjectInstance</CODE> object representing342* the newly created MBean.343*344* @param className The class name of the MBean to be instantiated.345* @param name The object name of the MBean. May be null.346* @param loaderName The object name of the class loader to be used.347*348* @return An <CODE>ObjectInstance</CODE>, containing the349* <CODE>ObjectName</CODE> and the Java class name350* of the newly instantiated MBean.351*352* @exception ReflectionException Wraps an353* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an354* <CODE>{@link java.lang.Exception}</CODE> that occurred when trying355* to invoke the MBean's constructor.356* @exception InstanceAlreadyExistsException The MBean is already357* under the control of the MBean server.358* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>359* (<CODE>MBeanRegistration</CODE> interface) method of the MBean360* has thrown an exception. The MBean will not be registered.361* @exception MBeanException The constructor of the MBean has thrown362* an exception363* @exception NotCompliantMBeanException This class is not a JMX364* compliant MBean.365* @exception InstanceNotFoundException The specified class loader366* is not registered in the MBean server.367* @exception RuntimeOperationsException Wraps an368* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The369* className passed in parameter is null, the <CODE>ObjectName</CODE>370* passed in parameter contains a pattern or no371* <CODE>ObjectName</CODE> is specified for the MBean.372*/373public ObjectInstance createMBean(String className, ObjectName name,374ObjectName loaderName)375throws ReflectionException, InstanceAlreadyExistsException,376MBeanRegistrationException, MBeanException,377NotCompliantMBeanException, InstanceNotFoundException {378379return mbsInterceptor.createMBean(className,380cloneObjectName(name),381loaderName,382(Object[]) null,383(String[]) null);384}385386/**387* Instantiates and registers an MBean in the MBean server.388* The MBean server will use its389* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}390* to load the class of the MBean.391* An object name is associated to the MBean.392* If the object name given is null, the MBean can automatically393* provide its own name by implementing the394* {@link javax.management.MBeanRegistration MBeanRegistration} interface.395* The call returns an <CODE>ObjectInstance</CODE> object representing396* the newly created MBean.397*398* @param className The class name of the MBean to be instantiated.399* @param name The object name of the MBean. May be null.400* @param params An array containing the parameters of the constructor401* to be invoked.402* @param signature An array containing the signature of the403* constructor to be invoked.404*405* @return An <CODE>ObjectInstance</CODE>, containing the406* <CODE>ObjectName</CODE> and the Java class name407* of the newly instantiated MBean.408*409* @exception ReflectionException Wraps a410* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an411* <CODE>{@link java.lang.Exception}</CODE> that occurred412* when trying to invoke the MBean's constructor.413* @exception InstanceAlreadyExistsException The MBean is already414* under the control of the MBean server.415* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>416* (<CODE>MBeanRegistration</CODE> interface) method of the MBean417* has thrown an exception. The MBean will not be registered.418* @exception MBeanException The constructor of the MBean has419* thrown an exception.420* @exception RuntimeOperationsException Wraps an421* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The422* className passed in parameter is null, the <CODE>ObjectName</CODE>423* passed in parameter contains a pattern or no424* <CODE>ObjectName</CODE> is specified for the MBean.425*426*/427public ObjectInstance createMBean(String className, ObjectName name,428Object params[], String signature[])429throws ReflectionException, InstanceAlreadyExistsException,430MBeanRegistrationException, MBeanException,431NotCompliantMBeanException {432433return mbsInterceptor.createMBean(className, cloneObjectName(name),434params, signature);435}436437/**438* Instantiates and registers an MBean in the MBean server.439* The class loader to be used is identified by its object name.440* An object name is associated to the MBean. If the object name441* of the loader is not specified, the ClassLoader that loaded the442* MBean server will be used.443* If the MBean object name given is null, the MBean can automatically444* provide its own name by implementing the445* {@link javax.management.MBeanRegistration MBeanRegistration} interface.446* The call returns an <CODE>ObjectInstance</CODE> object representing447* the newly created MBean.448*449* @param className The class name of the MBean to be instantiated.450* @param name The object name of the MBean. May be null.451* @param params An array containing the parameters of the constructor452* to be invoked.453* @param signature An array containing the signature of the454* constructor to be invoked.455* @param loaderName The object name of the class loader to be used.456*457* @return An <CODE>ObjectInstance</CODE>, containing the458* <CODE>ObjectName</CODE> and the Java class name of the newly459* instantiated MBean.460*461* @exception ReflectionException Wraps a462* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an463* <CODE>{@link java.lang.Exception}</CODE>464* that occurred when trying to invoke the MBean's constructor.465* @exception InstanceAlreadyExistsException The MBean is already466* under the control of the MBean server.467* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>468* (<CODE>MBeanRegistration</CODE> interface) method of the MBean469* has thrown an exception. The MBean will not be registered.470* @exception MBeanException The constructor of the MBean has471* thrown an exception472* @exception InstanceNotFoundException The specified class loader is473* not registered in the MBean server.474* @exception RuntimeOperationsException Wraps an475* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The476* className passed in parameter is null, the <CODE>ObjectName</CODE>477* passed in parameter contains a pattern or no478* <CODE>ObjectName</CODE> is specified for the MBean.479*480*/481public ObjectInstance createMBean(String className, ObjectName name,482ObjectName loaderName, Object params[],483String signature[])484throws ReflectionException, InstanceAlreadyExistsException,485MBeanRegistrationException, MBeanException,486NotCompliantMBeanException, InstanceNotFoundException {487488return mbsInterceptor.createMBean(className, cloneObjectName(name),489loaderName, params, signature);490}491492/**493* Registers a pre-existing object as an MBean with the MBean server.494* If the object name given is null, the MBean may automatically495* provide its own name by implementing the496* {@link javax.management.MBeanRegistration MBeanRegistration} interface.497* The call returns an <CODE>ObjectInstance</CODE> object representing498* the registered MBean.499*500* @param object The MBean to be registered as an MBean.501* @param name The object name of the MBean. May be null.502*503* @return The <CODE>ObjectInstance</CODE> for the MBean that has been504* registered.505*506* @exception InstanceAlreadyExistsException The MBean is already507* under the control of the MBean server.508* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>509* (<CODE>MBeanRegistration</CODE> interface) method of the MBean510* has thrown an exception. The MBean will not be registered.511* @exception NotCompliantMBeanException This object is not a JMX512* compliant MBean513* @exception RuntimeOperationsException Wraps an514* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The515* object passed in parameter is null or no object name is specified.516*517*/518public ObjectInstance registerMBean(Object object, ObjectName name)519throws InstanceAlreadyExistsException, MBeanRegistrationException,520NotCompliantMBeanException {521522return mbsInterceptor.registerMBean(object, cloneObjectName(name));523}524525/**526* De-registers an MBean from the MBean server. The MBean is identified by527* its object name. Once the method has been invoked, the MBean may528* no longer be accessed by its object name.529*530* @param name The object name of the MBean to be de-registered.531*532* @exception InstanceNotFoundException The MBean specified is not533* registered in the MBean server.534* @exception MBeanRegistrationException The <code>preDeregister()</code>535* (<CODE>MBeanRegistration</CODE> interface) method of the MBean536* has thrown an exception.537* @exception RuntimeOperationsException Wraps an538* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The539* object name in parameter is null or the MBean you are when540* trying to de-register is the541* {@link javax.management.MBeanServerDelegate MBeanServerDelegate}542* MBean.543**/544public void unregisterMBean(ObjectName name)545throws InstanceNotFoundException, MBeanRegistrationException {546mbsInterceptor.unregisterMBean(cloneObjectName(name));547}548549/**550* Gets the <CODE>ObjectInstance</CODE> for a given MBean registered551* with the MBean server.552*553* @param name The object name of the MBean.554*555* @return The <CODE>ObjectInstance</CODE> associated to the MBean556* specified by <VAR>name</VAR>.557*558* @exception InstanceNotFoundException The MBean specified is not559* registered in the MBean server.560*/561public ObjectInstance getObjectInstance(ObjectName name)562throws InstanceNotFoundException {563564return mbsInterceptor.getObjectInstance(cloneObjectName(name));565}566567/**568* Gets MBeans controlled by the MBean server. This method allows any569* of the following to be obtained: All MBeans, a set of MBeans specified570* by pattern matching on the <CODE>ObjectName</CODE> and/or a Query571* expression, a specific MBean. When the object name is null or no572* domain and key properties are specified, all objects are to be573* selected (and filtered if a query is specified). It returns the574* set of <CODE>ObjectInstance</CODE> objects (containing the575* <CODE>ObjectName</CODE> and the Java Class name) for576* the selected MBeans.577*578* @param name The object name pattern identifying the MBeans to579* be retrieved. If null or no domain and key properties580* are specified, all the MBeans registered will be retrieved.581* @param query The query expression to be applied for selecting582* MBeans. If null no query expression will be applied for583* selecting MBeans.584*585* @return A set containing the <CODE>ObjectInstance</CODE> objects586* for the selected MBeans.587* If no MBean satisfies the query an empty list is returned.588*589*/590public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {591592return mbsInterceptor.queryMBeans(cloneObjectName(name), query);593}594595/**596* Gets the names of MBeans controlled by the MBean server. This method597* enables any of the following to be obtained: The names of all MBeans,598* the names of a set of MBeans specified by pattern matching on the599* <CODE>ObjectName</CODE> and/or a Query expression, a specific600* MBean name (equivalent to testing whether an MBean is registered).601* When the object name is null or no domain and key properties are602* specified, all objects are selected (and filtered if a query is603* specified). It returns the set of ObjectNames for the MBeans604* selected.605*606* @param name The object name pattern identifying the MBeans to be607* retrieved. If null or no domain and key properties are608* specified, all the MBeans registered will be retrieved.609* @param query The query expression to be applied for selecting610* MBeans. If null no query expression will be applied for611* selecting MBeans.612*613* @return A set containing the ObjectNames for the MBeans selected.614* If no MBean satisfies the query, an empty list is returned.615*616*/617public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {618619return mbsInterceptor.queryNames(cloneObjectName(name), query);620}621622/**623* Checks whether an MBean, identified by its object name, is already624* registered with the MBean server.625*626* @param name The object name of the MBean to be checked.627*628* @return True if the MBean is already registered in the MBean server,629* false otherwise.630*631* @exception RuntimeOperationsException Wraps an632* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The object633* name in parameter is null.634*635*/636public boolean isRegistered(ObjectName name) {637638return mbsInterceptor.isRegistered(name);639}640641/**642* Returns the number of MBeans registered in the MBean server.643*/644public Integer getMBeanCount() {645646return mbsInterceptor.getMBeanCount();647}648649/**650* Gets the value of a specific attribute of a named MBean. The MBean651* is identified by its object name.652*653* @param name The object name of the MBean from which the attribute654* is to be retrieved.655* @param attribute A String specifying the name of the attribute to be656* retrieved.657*658* @return The value of the retrieved attribute.659*660* @exception AttributeNotFoundException The attribute specified661* is not accessible in the MBean.662* @exception MBeanException Wraps an exception thrown by the663* MBean's getter.664* @exception InstanceNotFoundException The MBean specified is not665* registered in the MBean server.666* @exception ReflectionException Wraps an667* <CODE>{@link java.lang.Exception}</CODE> thrown when trying to668* invoke the setter.669* @exception RuntimeOperationsException Wraps an670* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:671* The object name in parameter is null or the attribute in672* parameter is null.673*/674public Object getAttribute(ObjectName name, String attribute)675throws MBeanException, AttributeNotFoundException,676InstanceNotFoundException, ReflectionException {677678return mbsInterceptor.getAttribute(cloneObjectName(name), attribute);679}680681682/**683* Enables the values of several attributes of a named MBean. The MBean684* is identified by its object name.685*686* @param name The object name of the MBean from which the attributes are687* retrieved.688* @param attributes A list of the attributes to be retrieved.689*690* @return The list of the retrieved attributes.691*692* @exception InstanceNotFoundException The MBean specified is not693* registered in the MBean server.694* @exception ReflectionException An exception occurred when trying695* to invoke the getAttributes method of a Dynamic MBean.696* @exception RuntimeOperationsException Wrap an697* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The698* object name in parameter is null or attributes in parameter699* is null.700*701*/702public AttributeList getAttributes(ObjectName name, String[] attributes)703throws InstanceNotFoundException, ReflectionException {704705return mbsInterceptor.getAttributes(cloneObjectName(name), attributes);706707}708709/**710* Sets the value of a specific attribute of a named MBean. The MBean711* is identified by its object name.712*713* @param name The name of the MBean within which the attribute is714* to be set.715* @param attribute The identification of the attribute to be set716* and the value it is to be set to.717*718* @exception InstanceNotFoundException The MBean specified is719* not registered in the MBean server.720* @exception AttributeNotFoundException The attribute specified is721* not accessible in the MBean.722* @exception InvalidAttributeValueException The value specified for723* the attribute is not valid.724* @exception MBeanException Wraps an exception thrown by the725* MBean's setter.726* @exception ReflectionException Wraps an727* <CODE>{@link java.lang.Exception}</CODE> thrown when trying728* to invoke the setter.729* @exception RuntimeOperationsException Wraps an730* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The731* object name in parameter is null or the attribute in parameter732* is null.733*/734public void setAttribute(ObjectName name, Attribute attribute)735throws InstanceNotFoundException, AttributeNotFoundException,736InvalidAttributeValueException, MBeanException,737ReflectionException {738739mbsInterceptor.setAttribute(cloneObjectName(name),740cloneAttribute(attribute));741}742743/**744* Sets the values of several attributes of a named MBean. The MBean is745* identified by its object name.746*747* @param name The object name of the MBean within which the748* attributes are to be set.749* @param attributes A list of attributes: The identification of the750* attributes to be set and the values they are to be set to.751*752* @return The list of attributes that were set, with their new values.753*754* @exception InstanceNotFoundException The MBean specified is not755* registered in the MBean server.756* @exception ReflectionException An exception occurred when trying757* to invoke the getAttributes method of a Dynamic MBean.758* @exception RuntimeOperationsException Wraps an759* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:760* The object name in parameter is null or attributes in761* parameter is null.762*763*/764public AttributeList setAttributes(ObjectName name,765AttributeList attributes)766throws InstanceNotFoundException, ReflectionException {767768return mbsInterceptor.setAttributes(cloneObjectName(name),769cloneAttributeList(attributes));770}771772/**773* Invokes an operation on an MBean.774*775* @param name The object name of the MBean on which the method is to be776* invoked.777* @param operationName The name of the operation to be invoked.778* @param params An array containing the parameters to be set when779* the operation is invoked780* @param signature An array containing the signature of the operation.781* The class objects will be loaded using the same class loader as782* the one used for loading the MBean on which the operation was783* invoked.784*785* @return The object returned by the operation, which represents the786* result ofinvoking the operation on the MBean specified.787*788* @exception InstanceNotFoundException The MBean specified is not789* registered in the MBean server.790* @exception MBeanException Wraps an exception thrown by the MBean's791* invoked method.792* @exception ReflectionException Wraps an793* <CODE>{@link java.lang.Exception}</CODE> thrown while trying794* to invoke the method.795*796*/797public Object invoke(ObjectName name, String operationName,798Object params[], String signature[])799throws InstanceNotFoundException, MBeanException,800ReflectionException {801return mbsInterceptor.invoke(cloneObjectName(name), operationName,802params, signature);803}804805/**806* Returns the default domain used for naming the MBean.807* The default domain name is used as the domain part in the ObjectName808* of MBeans if no domain is specified by the user.809*/810public String getDefaultDomain() {811return mbsInterceptor.getDefaultDomain();812}813814// From MBeanServer815public String[] getDomains() {816return mbsInterceptor.getDomains();817}818819/**820* Adds a listener to a registered MBean.821*822* @param name The name of the MBean on which the listener should be added.823* @param listener The listener object which will handle the824* notifications emitted by the registered MBean.825* @param filter The filter object. If filter is null, no filtering826* will be performed before handling notifications.827* @param handback The context to be sent to the listener when a828* notification is emitted.829*830* @exception InstanceNotFoundException The MBean name provided does831* not match any of the registered MBeans.832*/833public void addNotificationListener(ObjectName name,834NotificationListener listener,835NotificationFilter filter,836Object handback)837throws InstanceNotFoundException {838839mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,840filter, handback);841}842843/**844* Adds a listener to a registered MBean.845*846* @param name The name of the MBean on which the listener should be added.847* @param listener The object name of the listener which will handle the848* notifications emitted by the registered MBean.849* @param filter The filter object. If filter is null, no filtering will850* be performed before handling notifications.851* @param handback The context to be sent to the listener when a852* notification is emitted.853*854* @exception InstanceNotFoundException The MBean name of the855* notification listener or of the notification broadcaster856* does not match any of the registered MBeans.857*/858public void addNotificationListener(ObjectName name, ObjectName listener,859NotificationFilter filter, Object handback)860throws InstanceNotFoundException {861862mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,863filter, handback);864}865866public void removeNotificationListener(ObjectName name,867NotificationListener listener)868throws InstanceNotFoundException, ListenerNotFoundException {869870mbsInterceptor.removeNotificationListener(cloneObjectName(name),871listener);872}873874public void removeNotificationListener(ObjectName name,875NotificationListener listener,876NotificationFilter filter,877Object handback)878throws InstanceNotFoundException, ListenerNotFoundException {879880mbsInterceptor.removeNotificationListener(cloneObjectName(name),881listener, filter, handback);882}883884public void removeNotificationListener(ObjectName name,885ObjectName listener)886throws InstanceNotFoundException, ListenerNotFoundException {887888mbsInterceptor.removeNotificationListener(cloneObjectName(name),889listener);890}891892public void removeNotificationListener(ObjectName name,893ObjectName listener,894NotificationFilter filter,895Object handback)896throws InstanceNotFoundException, ListenerNotFoundException {897898mbsInterceptor.removeNotificationListener(cloneObjectName(name),899listener, filter, handback);900}901902/**903* This method discovers the attributes and operations that an MBean exposes904* for management.905*906* @param name The name of the MBean to analyze907*908* @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of909* all attributes and operations of this MBean.910*911* @exception IntrospectionException An exception occurs during912* introspection.913* @exception InstanceNotFoundException The MBean specified is not found.914* @exception ReflectionException An exception occurred when trying to915* invoke the getMBeanInfo of a Dynamic MBean.916*/917public MBeanInfo getMBeanInfo(ObjectName name) throws918InstanceNotFoundException, IntrospectionException, ReflectionException {919920return mbsInterceptor.getMBeanInfo(cloneObjectName(name));921}922923/**924* Instantiates an object using the list of all class loaders registered925* in the MBean server (using its926* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).927* The object's class should have a public constructor.928* It returns a reference to the newly created object.929* The newly created object is not registered in the MBean server.930*931* @param className The class name of the object to be instantiated.932*933* @return The newly instantiated object.934*935* @exception ReflectionException Wraps the936* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the937* <CODE>{@link java.lang.Exception}</CODE> that938* occurred when trying to invoke the object's constructor.939* @exception MBeanException The constructor of the object has thrown940* an exception.941* @exception RuntimeOperationsException Wraps an942* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:943* The className passed in parameter is null.944*945*/946public Object instantiate(String className)947throws ReflectionException, MBeanException {948949/* Permission check */950checkMBeanPermission(className, null, null, "instantiate");951952return instantiator.instantiate(className);953}954955/**956* Instantiates an object using the class Loader specified by its957* <CODE>ObjectName</CODE>.958* If the loader name is null, the ClassLoader that loaded the959* MBean Server will be used.960* The object's class should have a public constructor.961* It returns a reference to the newly created object.962* The newly created object is not registered in the MBean server.963*964* @param className The class name of the MBean to be instantiated.965* @param loaderName The object name of the class loader to be used.966*967* @return The newly instantiated object.968*969* @exception ReflectionException Wraps the970* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the971* <CODE>{@link java.lang.Exception}</CODE> that972* occurred when trying to invoke the object's constructor.973* @exception MBeanException The constructor of the object has thrown974* an exception.975* @exception InstanceNotFoundException The specified class loader976* is not registered in the MBaenServer.977* @exception RuntimeOperationsException Wraps an978* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The979* className passed in parameter is null.980*981*/982public Object instantiate(String className, ObjectName loaderName)983throws ReflectionException, MBeanException,984InstanceNotFoundException {985986/* Permission check */987checkMBeanPermission(className, null, null, "instantiate");988989ClassLoader myLoader = outerShell.getClass().getClassLoader();990return instantiator.instantiate(className, loaderName, myLoader);991}992993/**994* Instantiates an object using the list of all class loaders registered995* in the MBean server (using its996* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).997* The object's class should have a public constructor.998* The call returns a reference to the newly created object.999* The newly created object is not registered in the MBean server.1000*1001* @param className The class name of the object to be instantiated.1002* @param params An array containing the parameters of the constructor1003* to be invoked.1004* @param signature An array containing the signature of the1005* constructor to be invoked.1006*1007* @return The newly instantiated object.1008*1009* @exception ReflectionException Wraps the1010* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the1011* <CODE>{@link java.lang.Exception}</CODE> that1012* occurred when trying to invoke the object's constructor.1013* @exception MBeanException The constructor of the object has thrown1014* an exception.1015* @exception RuntimeOperationsException Wraps an1016* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:1017* The className passed in parameter is null.1018*1019*/1020public Object instantiate(String className, Object params[],1021String signature[])1022throws ReflectionException, MBeanException {10231024/* Permission check */1025checkMBeanPermission(className, null, null, "instantiate");10261027ClassLoader myLoader = outerShell.getClass().getClassLoader();1028return instantiator.instantiate(className, params, signature,1029myLoader);1030}10311032/**1033* Instantiates an object. The class loader to be used is identified1034* by its object name. If the object name of the loader is null,1035* the ClassLoader that loaded the MBean server will be used.1036* The object's class should have a public constructor.1037* The call returns a reference to the newly created object.1038* The newly created object is not registered in the MBean server.1039*1040* @param className The class name of the object to be instantiated.1041* @param params An array containing the parameters of the constructor1042* to be invoked.1043* @param signature An array containing the signature of the constructor1044* to be invoked.1045* @param loaderName The object name of the class loader to be used.1046*1047* @return The newly instantiated object.1048*1049* @exception ReflectionException Wraps the1050* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the1051* <CODE>{@link java.lang.Exception}</CODE> that1052* occurred when trying to invoke the object's constructor.1053* @exception MBeanException The constructor of the object has thrown1054* an exception.1055* @exception InstanceNotFoundException The specified class loader1056* is not registered in the MBean server.1057* @exception RuntimeOperationsException Wraps an1058* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:1059* The className passed in parameter is null.1060*1061*/1062public Object instantiate(String className, ObjectName loaderName,1063Object params[], String signature[])1064throws ReflectionException, MBeanException,1065InstanceNotFoundException {10661067/* Permission check */1068checkMBeanPermission(className, null, null, "instantiate");10691070ClassLoader myLoader = outerShell.getClass().getClassLoader();1071return instantiator.instantiate(className,loaderName,params,signature,1072myLoader);1073}10741075/**1076* Returns true if the MBean specified is an instance of the specified1077* class, false otherwise.1078*1079* @param name The <CODE>ObjectName</CODE> of the MBean.1080* @param className The name of the class.1081*1082* @return true if the MBean specified is an instance of the specified1083* class, false otherwise.1084*1085* @exception InstanceNotFoundException The MBean specified is not1086* registered in the MBean server.1087*/1088public boolean isInstanceOf(ObjectName name, String className)1089throws InstanceNotFoundException {10901091return mbsInterceptor.isInstanceOf(cloneObjectName(name), className);1092}10931094/**1095* De-serializes a byte array in the context of the class loader1096* of an MBean.1097*1098* @param name The name of the MBean whose class loader should1099* be used for the de-serialization.1100* @param data The byte array to be de-sererialized.1101*1102* @return The de-serialized object stream.1103*1104* @exception InstanceNotFoundException The MBean specified is not1105* found.1106* @exception OperationsException Any of the usual Input/Output1107* related exceptions.1108*1109*/1110@Deprecated1111public ObjectInputStream deserialize(ObjectName name, byte[] data)1112throws InstanceNotFoundException, OperationsException {11131114/* Permission check */1115// This call requires MBeanPermission 'getClassLoaderFor'1116final ClassLoader loader = getClassLoaderFor(name);11171118return instantiator.deserialize(loader, data);1119}11201121/**1122* De-serializes a byte array in the context of a given MBean class loader.1123* The class loader is the one that loaded the class with name "className".1124*1125* @param className The name of the class whose class loader should be1126* used for the de-serialization.1127* @param data The byte array to be de-sererialized.1128*1129* @return The de-serialized object stream.1130*1131* @exception OperationsException Any of the usual Input/Output1132* related exceptions.1133* @exception ReflectionException The specified class could not be1134* loaded by the default loader repository1135*1136*/1137@Deprecated1138public ObjectInputStream deserialize(String className, byte[] data)1139throws OperationsException, ReflectionException {11401141if (className == null) {1142throw new RuntimeOperationsException(1143new IllegalArgumentException(),1144"Null className passed in parameter");1145}11461147/* Permission check */1148// This call requires MBeanPermission 'getClassLoaderRepository'1149final ClassLoaderRepository clr = getClassLoaderRepository();11501151Class<?> theClass;1152try {1153if (clr == null) throw new ClassNotFoundException(className);1154theClass = clr.loadClass(className);1155} catch (ClassNotFoundException e) {1156throw new ReflectionException(e,1157"The given class could not be " +1158"loaded by the default loader " +1159"repository");1160}11611162return instantiator.deserialize(theClass.getClassLoader(), data);1163}11641165/**1166* De-serializes a byte array in the context of a given MBean class loader.1167* The class loader is the one that loaded the class with name "className".1168* The name of the class loader to be used for loading the specified1169* class is specified.1170* If null, the MBean Server's class loader will be used.1171*1172* @param className The name of the class whose class loader should be1173* used for the de-serialization.1174* @param data The byte array to be de-sererialized.1175* @param loaderName The name of the class loader to be used for1176* loading the specified class.1177* If null, the MBean Server's class loader will be used.1178*1179* @return The de-serialized object stream.1180*1181* @exception InstanceNotFoundException The specified class loader1182* MBean is not found.1183* @exception OperationsException Any of the usual Input/Output1184* related exceptions.1185* @exception ReflectionException The specified class could not1186* be loaded by the specified class loader.1187*1188*/1189@Deprecated1190public ObjectInputStream deserialize(String className,1191ObjectName loaderName,1192byte[] data) throws1193InstanceNotFoundException, OperationsException, ReflectionException {11941195// Clone ObjectName1196//1197loaderName = cloneObjectName(loaderName);11981199/* Permission check */1200// Make this call just to force the 'getClassLoader'1201// permission check1202try {1203getClassLoader(loaderName);1204} catch (SecurityException e) {1205throw e;1206} catch (Exception e) {1207}12081209ClassLoader myLoader = outerShell.getClass().getClassLoader();1210return instantiator.deserialize(className, loaderName, data, myLoader);1211}12121213/**1214* Initializes this MBeanServer, registering the MBeanServerDelegate.1215* <p>This method must be called once, before using the MBeanServer.1216**/1217@SuppressWarnings("removal")1218private void initialize() {1219if (instantiator == null) throw new1220IllegalStateException("instantiator must not be null.");12211222// Registers the MBeanServer identification MBean1223try {1224AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {1225public Object run() throws Exception {1226mbsInterceptor.registerMBean(1227mBeanServerDelegateObject,1228MBeanServerDelegate.DELEGATE_NAME);1229return null;1230}1231});1232} catch (SecurityException e) {1233if (MBEANSERVER_LOGGER.isLoggable(Level.DEBUG)) {1234MBEANSERVER_LOGGER.log(Level.DEBUG,1235"Unexpected security exception occurred", e);1236}1237throw e;1238} catch (Exception e) {1239if (MBEANSERVER_LOGGER.isLoggable(Level.DEBUG)) {1240MBEANSERVER_LOGGER.log(Level.DEBUG,1241"Unexpected exception occurred", e);1242}1243throw new1244IllegalStateException("Can't register delegate.",e);1245}124612471248/* Add my class loader to the repository1249This can be null if my class loader is the bootstrap1250class loader. The ClassLoaderRepository knows how1251to handle that case. */1252ClassLoader myLoader = outerShell.getClass().getClassLoader();1253final ModifiableClassLoaderRepository loaders = AccessController.doPrivileged(new PrivilegedAction<ModifiableClassLoaderRepository>() {12541255@Override1256public ModifiableClassLoaderRepository run() {1257return instantiator.getClassLoaderRepository();1258}1259});12601261if (loaders != null) {1262loaders.addClassLoader(myLoader);12631264/* Add the system class loader, so that if the MBean server is1265loaded by the bootstrap class loader we can still load1266MBeans from the classpath using1267createMBean(className, objectName).12681269If this class (JmxMBeanServer) was not loaded by the1270system class loader or a parent of it, then the caller1271must have RuntimePermission("getClassLoader") for the1272getSystemClassLoader() call to succeed. If the caller1273does not have that permission, any call to1274Class.getClassLoader() will fail. Since there are lots1275of those in JMX, we better throw the exception now.12761277This permission question is irrelevant when JMX is part1278of J2SE (as of 1.5). */1279ClassLoader systemLoader = ClassLoader.getSystemClassLoader();1280if (systemLoader != myLoader)1281loaders.addClassLoader(systemLoader);1282}1283}12841285/**1286* Return the MBeanServerInterceptor.1287* @exception UnsupportedOperationException if1288* {@link MBeanServerInterceptor}s1289* are not enabled on this object.1290* @see #interceptorsEnabled1291**/1292public synchronized MBeanServer getMBeanServerInterceptor() {1293if (interceptorsEnabled) return mbsInterceptor;1294else throw new UnsupportedOperationException(1295"MBeanServerInterceptors are disabled.");1296}12971298/**1299* Set the MBeanServerInterceptor.1300* @exception UnsupportedOperationException if1301* {@link MBeanServerInterceptor}s1302* are not enabled on this object.1303* @see #interceptorsEnabled1304**/1305public synchronized void1306setMBeanServerInterceptor(MBeanServer interceptor) {1307if (!interceptorsEnabled) throw new UnsupportedOperationException(1308"MBeanServerInterceptors are disabled.");1309if (interceptor == null) throw new1310IllegalArgumentException("MBeanServerInterceptor is null");1311mbsInterceptor = interceptor;1312}13131314/**1315* <p>Return the {@link java.lang.ClassLoader} that was used for1316* loading the class of the named MBean.1317* @param mbeanName The ObjectName of the MBean.1318* @return The ClassLoader used for that MBean.1319* @exception InstanceNotFoundException if the named MBean is not found.1320*/1321public ClassLoader getClassLoaderFor(ObjectName mbeanName)1322throws InstanceNotFoundException {1323return mbsInterceptor.getClassLoaderFor(cloneObjectName(mbeanName));1324}13251326/**1327* <p>Return the named {@link java.lang.ClassLoader}.1328* @param loaderName The ObjectName of the ClassLoader.1329* @return The named ClassLoader.1330* @exception InstanceNotFoundException if the named ClassLoader1331* is not found.1332*/1333public ClassLoader getClassLoader(ObjectName loaderName)1334throws InstanceNotFoundException {1335return mbsInterceptor.getClassLoader(cloneObjectName(loaderName));1336}13371338/**1339* <p>Return the ClassLoaderRepository for that MBeanServer.1340* @return The ClassLoaderRepository for that MBeanServer.1341**/1342public ClassLoaderRepository getClassLoaderRepository() {1343/* Permission check */1344checkMBeanPermission(null, null, null, "getClassLoaderRepository");1345return secureClr;1346}13471348public MBeanServerDelegate getMBeanServerDelegate() {1349if (!interceptorsEnabled) throw new UnsupportedOperationException(1350"MBeanServerInterceptors are disabled.");1351return mBeanServerDelegateObject;1352}13531354// These methods are called by the JMX MBeanServerBuilder.13551356/**1357* This method creates a new MBeanServerDelegate for a new MBeanServer.1358* When creating a new MBeanServer the1359* {@link javax.management.MBeanServerBuilder} first calls this method1360* in order to create a new MBeanServerDelegate.1361* <br>Then it calls1362* <code>newMBeanServer(defaultDomain,outer,delegate,interceptors)</code>1363* passing the <var>delegate</var> that should be used by the MBeanServer1364* implementation.1365* <p>Note that the passed <var>delegate</var> might not be directly the1366* MBeanServerDelegate that was returned by this method. It could1367* be, for instance, a new object wrapping the previously1368* returned object.1369*1370* @return A new {@link javax.management.MBeanServerDelegate}.1371**/1372public static MBeanServerDelegate newMBeanServerDelegate() {1373return new MBeanServerDelegateImpl();1374}13751376/**1377* This method creates a new MBeanServer implementation object.1378* When creating a new MBeanServer the1379* {@link javax.management.MBeanServerBuilder} first calls1380* <code>newMBeanServerDelegate()</code> in order to obtain a new1381* {@link javax.management.MBeanServerDelegate} for the new1382* MBeanServer. Then it calls1383* <code>newMBeanServer(defaultDomain,outer,delegate)</code>1384* passing the <var>delegate</var> that should be used by the1385* MBeanServer implementation.1386* <p>Note that the passed <var>delegate</var> might not be directly the1387* MBeanServerDelegate that was returned by this implementation. It could1388* be, for instance, a new object wrapping the previously1389* returned delegate.1390* <p>The <var>outer</var> parameter is a pointer to the MBeanServer that1391* should be passed to the {@link javax.management.MBeanRegistration}1392* interface when registering MBeans inside the MBeanServer.1393* If <var>outer</var> is <code>null</code>, then the MBeanServer1394* implementation is free to use its own <code>this</code> pointer when1395* invoking the {@link javax.management.MBeanRegistration} interface.1396* <p>This makes it possible for a MBeanServer implementation to wrap1397* another MBeanServer implementation, in order to implement, e.g,1398* security checks, or to prevent access to the actual MBeanServer1399* implementation by returning a pointer to a wrapping object.1400*1401* @param defaultDomain Default domain of the new MBeanServer.1402* @param outer A pointer to the MBeanServer object that must be1403* passed to the MBeans when invoking their1404* {@link javax.management.MBeanRegistration} interface.1405* @param delegate A pointer to the MBeanServerDelegate associated1406* with the new MBeanServer. The new MBeanServer must register1407* this MBean in its MBean repository.1408* @param interceptors If <code>true</code>,1409* {@link MBeanServerInterceptor}s will be enabled (default is1410* <code>false</code>).1411* Note: this parameter is not taken into account by this1412* implementation - the default value <code>false</code> is1413* always used.1414* @return A new private implementation of an MBeanServer.1415* @see #interceptorsEnabled1416* @see javax.management.MBeanServerBuilder1417* @see com.sun.jmx.mbeanserver.JmxMBeanServerBuilder1418**/1419public static MBeanServer newMBeanServer(String defaultDomain,1420MBeanServer outer,1421MBeanServerDelegate delegate,1422boolean interceptors) {1423// Determine whether to use fair locking for the repository.1424// Default is true.1425final boolean fairLock = DEFAULT_FAIR_LOCK_POLICY;14261427checkNewMBeanServerPermission();14281429// This constructor happens to disregard the value of the interceptors1430// flag - that is, it always uses the default value - false.1431// This is admitedly a bug, but we chose not to fix it for now1432// since we would rather not have anybody depending on the Sun private1433// interceptor APIs - which is most probably going to be removed and1434// replaced by a public (javax) feature in the future.1435//1436return new JmxMBeanServer(defaultDomain,outer,delegate,null,1437interceptors,fairLock);1438}14391440// JMX OBJECT CLONING1441//-------------------14421443/**1444* Clone object name.1445*/1446private ObjectName cloneObjectName(ObjectName name) {1447if (name != null) {1448return ObjectName.getInstance(name);1449}1450return name;1451}14521453/**1454* Clone attribute.1455*/1456private Attribute cloneAttribute(Attribute attribute) {1457if (attribute != null) {1458if (!attribute.getClass().equals(Attribute.class)) {1459return new Attribute(attribute.getName(), attribute.getValue());1460}1461}1462return attribute;1463}14641465/**1466* Clone attribute list.1467*/1468private AttributeList cloneAttributeList(AttributeList list) {1469if (list != null) {1470List<Attribute> alist = list.asList();1471if (!list.getClass().equals(AttributeList.class)) {1472// Create new attribute list1473//1474AttributeList newList = new AttributeList(alist.size());14751476// Iterate through list and replace non JMX attributes1477//1478for (Attribute attribute : alist)1479newList.add(cloneAttribute(attribute));1480return newList;1481} else {1482// Iterate through list and replace non JMX attributes1483//1484for (int i = 0; i < alist.size(); i++) {1485Attribute attribute = alist.get(i);1486if (!attribute.getClass().equals(Attribute.class)) {1487list.set(i, cloneAttribute(attribute));1488}1489}1490return list;1491}1492}1493return list;1494}14951496// SECURITY CHECKS1497//----------------14981499private static void checkMBeanPermission(String classname,1500String member,1501ObjectName objectName,1502String actions)1503throws SecurityException {1504@SuppressWarnings("removal")1505SecurityManager sm = System.getSecurityManager();1506if (sm != null) {1507Permission perm = new MBeanPermission(classname,1508member,1509objectName,1510actions);1511sm.checkPermission(perm);1512}1513}15141515private static void checkNewMBeanServerPermission() {1516@SuppressWarnings("removal")1517SecurityManager sm = System.getSecurityManager();1518if (sm != null) {1519Permission perm = new MBeanServerPermission("newMBeanServer");1520sm.checkPermission(perm);1521}1522}1523}152415251526