Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/share/classes/com/sun/jmx/mbeanserver/JmxMBeanServer.java
38924 views
/*1* Copyright (c) 1999, 2013, 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.util.logging.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*/219JmxMBeanServer(String domain, MBeanServer outer,220MBeanServerDelegate delegate,221MBeanInstantiator instantiator,222boolean interceptors,223boolean fairLock) {224225if (instantiator == null) {226final ModifiableClassLoaderRepository227clr = new ClassLoaderRepositorySupport();228instantiator = new MBeanInstantiator(clr);229}230231final MBeanInstantiator fInstantiator = instantiator;232this.secureClr = new233SecureClassLoaderRepository(AccessController.doPrivileged(new PrivilegedAction<ClassLoaderRepository>() {234@Override235public ClassLoaderRepository run() {236return fInstantiator.getClassLoaderRepository();237}238})239);240if (delegate == null)241delegate = new MBeanServerDelegateImpl();242if (outer == null)243outer = this;244245this.instantiator = instantiator;246this.mBeanServerDelegateObject = delegate;247this.outerShell = outer;248249final Repository repository = new Repository(domain);250this.mbsInterceptor =251new DefaultMBeanServerInterceptor(outer, delegate, instantiator,252repository);253this.interceptorsEnabled = interceptors;254initialize();255}256257/**258* Tell whether {@link MBeanServerInterceptor}s are enabled on this259* object.260* @return <code>true</code> if {@link MBeanServerInterceptor}s are261* enabled.262* @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)263**/264public boolean interceptorsEnabled() {265return interceptorsEnabled;266}267268/**269* Return the MBeanInstantiator associated to this MBeanServer.270* @exception UnsupportedOperationException if271* {@link MBeanServerInterceptor}s272* are not enabled on this object.273* @see #interceptorsEnabled274**/275public MBeanInstantiator getMBeanInstantiator() {276if (interceptorsEnabled) return instantiator;277else throw new UnsupportedOperationException(278"MBeanServerInterceptors are disabled.");279}280281/**282* Instantiates and registers an MBean in the MBean server.283* The MBean server will use its284* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}285* to load the class of the MBean.286* An object name is associated to the MBean.287* If the object name given is null, the MBean can automatically288* provide its own name by implementing the289* {@link javax.management.MBeanRegistration MBeanRegistration} interface.290* The call returns an <CODE>ObjectInstance</CODE> object representing291* the newly created MBean.292*293* @param className The class name of the MBean to be instantiated.294* @param name The object name of the MBean. May be null.295*296* @return An <CODE>ObjectInstance</CODE>, containing the297* <CODE>ObjectName</CODE> and the Java class name of the newly298* instantiated MBean.299*300* @exception ReflectionException Wraps an301* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an302* <CODE>{@link java.lang.Exception}</CODE> that occurred303* when trying to invoke the MBean's constructor.304* @exception InstanceAlreadyExistsException The MBean is already305* under the control of the MBean server.306* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>307* (<CODE>MBeanRegistration</CODE> interface) method of the MBean308* has thrown an exception. The MBean will not be registered.309* @exception MBeanException The constructor of the MBean has thrown310* an exception.311* @exception NotCompliantMBeanException This class is not a JMX312* compliant MBean.313* @exception RuntimeOperationsException Wraps an314* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:315* The className passed in parameter is null, the316* <CODE>ObjectName</CODE> passed in parameter contains a pattern317* or no <CODE>ObjectName</CODE> is specified for the MBean.318*319*/320public ObjectInstance createMBean(String className, ObjectName name)321throws ReflectionException, InstanceAlreadyExistsException,322MBeanRegistrationException, MBeanException,323NotCompliantMBeanException {324325return mbsInterceptor.createMBean(className,326cloneObjectName(name),327(Object[]) null,328(String[]) null);329}330331/**332* Instantiates and registers an MBean in the MBean server.333* The class loader to be used is identified by its object name.334* An object name is associated to the MBean.335* If the object name of the loader is null, the ClassLoader that336* loaded the MBean server will be used.337* If the MBean's object name given is null, the MBean can338* automatically provide its own name by implementing the339* {@link javax.management.MBeanRegistration MBeanRegistration} interface.340* The call returns an <CODE>ObjectInstance</CODE> object representing341* the newly created MBean.342*343* @param className The class name of the MBean to be instantiated.344* @param name The object name of the MBean. May be null.345* @param loaderName The object name of the class loader to be used.346*347* @return An <CODE>ObjectInstance</CODE>, containing the348* <CODE>ObjectName</CODE> and the Java class name349* of the newly instantiated MBean.350*351* @exception ReflectionException Wraps an352* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an353* <CODE>{@link java.lang.Exception}</CODE> that occurred when trying354* to invoke the MBean's constructor.355* @exception InstanceAlreadyExistsException The MBean is already356* under the control of the MBean server.357* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>358* (<CODE>MBeanRegistration</CODE> interface) method of the MBean359* has thrown an exception. The MBean will not be registered.360* @exception MBeanException The constructor of the MBean has thrown361* an exception362* @exception NotCompliantMBeanException This class is not a JMX363* compliant MBean.364* @exception InstanceNotFoundException The specified class loader365* is not registered in the MBean server.366* @exception RuntimeOperationsException Wraps an367* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The368* className passed in parameter is null, the <CODE>ObjectName</CODE>369* passed in parameter contains a pattern or no370* <CODE>ObjectName</CODE> is specified for the MBean.371*/372public ObjectInstance createMBean(String className, ObjectName name,373ObjectName loaderName)374throws ReflectionException, InstanceAlreadyExistsException,375MBeanRegistrationException, MBeanException,376NotCompliantMBeanException, InstanceNotFoundException {377378return mbsInterceptor.createMBean(className,379cloneObjectName(name),380loaderName,381(Object[]) null,382(String[]) null);383}384385/**386* Instantiates and registers an MBean in the MBean server.387* The MBean server will use its388* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}389* to load the class of the MBean.390* An object name is associated to the MBean.391* If the object name given is null, the MBean can automatically392* provide its own name by implementing the393* {@link javax.management.MBeanRegistration MBeanRegistration} interface.394* The call returns an <CODE>ObjectInstance</CODE> object representing395* the newly created MBean.396*397* @param className The class name of the MBean to be instantiated.398* @param name The object name of the MBean. May be null.399* @param params An array containing the parameters of the constructor400* to be invoked.401* @param signature An array containing the signature of the402* constructor to be invoked.403*404* @return An <CODE>ObjectInstance</CODE>, containing the405* <CODE>ObjectName</CODE> and the Java class name406* of the newly instantiated MBean.407*408* @exception ReflectionException Wraps a409* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an410* <CODE>{@link java.lang.Exception}</CODE> that occurred411* when trying to invoke the MBean's constructor.412* @exception InstanceAlreadyExistsException The MBean is already413* under the control of the MBean server.414* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>415* (<CODE>MBeanRegistration</CODE> interface) method of the MBean416* has thrown an exception. The MBean will not be registered.417* @exception MBeanException The constructor of the MBean has418* thrown an exception.419* @exception RuntimeOperationsException Wraps an420* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The421* className passed in parameter is null, the <CODE>ObjectName</CODE>422* passed in parameter contains a pattern or no423* <CODE>ObjectName</CODE> is specified for the MBean.424*425*/426public ObjectInstance createMBean(String className, ObjectName name,427Object params[], String signature[])428throws ReflectionException, InstanceAlreadyExistsException,429MBeanRegistrationException, MBeanException,430NotCompliantMBeanException {431432return mbsInterceptor.createMBean(className, cloneObjectName(name),433params, signature);434}435436/**437* Instantiates and registers an MBean in the MBean server.438* The class loader to be used is identified by its object name.439* An object name is associated to the MBean. If the object name440* of the loader is not specified, the ClassLoader that loaded the441* MBean server will be used.442* If the MBean object name given is null, the MBean can automatically443* provide its own name by implementing the444* {@link javax.management.MBeanRegistration MBeanRegistration} interface.445* The call returns an <CODE>ObjectInstance</CODE> object representing446* the newly created MBean.447*448* @param className The class name of the MBean to be instantiated.449* @param name The object name of the MBean. May be null.450* @param params An array containing the parameters of the constructor451* to be invoked.452* @param signature An array containing the signature of the453* constructor to be invoked.454* @param loaderName The object name of the class loader to be used.455*456* @return An <CODE>ObjectInstance</CODE>, containing the457* <CODE>ObjectName</CODE> and the Java class name of the newly458* instantiated MBean.459*460* @exception ReflectionException Wraps a461* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or an462* <CODE>{@link java.lang.Exception}</CODE>463* that occurred when trying to invoke the MBean's constructor.464* @exception InstanceAlreadyExistsException The MBean is already465* under the control of the MBean server.466* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>467* (<CODE>MBeanRegistration</CODE> interface) method of the MBean468* has thrown an exception. The MBean will not be registered.469* @exception MBeanException The constructor of the MBean has470* thrown an exception471* @exception InstanceNotFoundException The specified class loader is472* not registered in the MBean server.473* @exception RuntimeOperationsException Wraps an474* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The475* className passed in parameter is null, the <CODE>ObjectName</CODE>476* passed in parameter contains a pattern or no477* <CODE>ObjectName</CODE> is specified for the MBean.478*479*/480public ObjectInstance createMBean(String className, ObjectName name,481ObjectName loaderName, Object params[],482String signature[])483throws ReflectionException, InstanceAlreadyExistsException,484MBeanRegistrationException, MBeanException,485NotCompliantMBeanException, InstanceNotFoundException {486487return mbsInterceptor.createMBean(className, cloneObjectName(name),488loaderName, params, signature);489}490491/**492* Registers a pre-existing object as an MBean with the MBean server.493* If the object name given is null, the MBean may automatically494* provide its own name by implementing the495* {@link javax.management.MBeanRegistration MBeanRegistration} interface.496* The call returns an <CODE>ObjectInstance</CODE> object representing497* the registered MBean.498*499* @param object The MBean to be registered as an MBean.500* @param name The object name of the MBean. May be null.501*502* @return The <CODE>ObjectInstance</CODE> for the MBean that has been503* registered.504*505* @exception InstanceAlreadyExistsException The MBean is already506* under the control of the MBean server.507* @exception MBeanRegistrationException The <CODE>preRegister()</CODE>508* (<CODE>MBeanRegistration</CODE> interface) method of the MBean509* has thrown an exception. The MBean will not be registered.510* @exception NotCompliantMBeanException This object is not a JMX511* compliant MBean512* @exception RuntimeOperationsException Wraps an513* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The514* object passed in parameter is null or no object name is specified.515*516*/517public ObjectInstance registerMBean(Object object, ObjectName name)518throws InstanceAlreadyExistsException, MBeanRegistrationException,519NotCompliantMBeanException {520521return mbsInterceptor.registerMBean(object, cloneObjectName(name));522}523524/**525* De-registers an MBean from the MBean server. The MBean is identified by526* its object name. Once the method has been invoked, the MBean may527* no longer be accessed by its object name.528*529* @param name The object name of the MBean to be de-registered.530*531* @exception InstanceNotFoundException The MBean specified is not532* registered in the MBean server.533* @exception MBeanRegistrationException The <code>preDeregister()</code>534* (<CODE>MBeanRegistration</CODE> interface) method of the MBean535* has thrown an exception.536* @exception RuntimeOperationsException Wraps an537* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The538* object name in parameter is null or the MBean you are when539* trying to de-register is the540* {@link javax.management.MBeanServerDelegate MBeanServerDelegate}541* MBean.542**/543public void unregisterMBean(ObjectName name)544throws InstanceNotFoundException, MBeanRegistrationException {545mbsInterceptor.unregisterMBean(cloneObjectName(name));546}547548/**549* Gets the <CODE>ObjectInstance</CODE> for a given MBean registered550* with the MBean server.551*552* @param name The object name of the MBean.553*554* @return The <CODE>ObjectInstance</CODE> associated to the MBean555* specified by <VAR>name</VAR>.556*557* @exception InstanceNotFoundException The MBean specified is not558* registered in the MBean server.559*/560public ObjectInstance getObjectInstance(ObjectName name)561throws InstanceNotFoundException {562563return mbsInterceptor.getObjectInstance(cloneObjectName(name));564}565566/**567* Gets MBeans controlled by the MBean server. This method allows any568* of the following to be obtained: All MBeans, a set of MBeans specified569* by pattern matching on the <CODE>ObjectName</CODE> and/or a Query570* expression, a specific MBean. When the object name is null or no571* domain and key properties are specified, all objects are to be572* selected (and filtered if a query is specified). It returns the573* set of <CODE>ObjectInstance</CODE> objects (containing the574* <CODE>ObjectName</CODE> and the Java Class name) for575* the selected MBeans.576*577* @param name The object name pattern identifying the MBeans to578* be retrieved. If null or or no domain and key properties579* are specified, all the MBeans registered will be retrieved.580* @param query The query expression to be applied for selecting581* MBeans. If null no query expression will be applied for582* selecting MBeans.583*584* @return A set containing the <CODE>ObjectInstance</CODE> objects585* for the selected MBeans.586* If no MBean satisfies the query an empty list is returned.587*588*/589public Set<ObjectInstance> queryMBeans(ObjectName name, QueryExp query) {590591return mbsInterceptor.queryMBeans(cloneObjectName(name), query);592}593594/**595* Gets the names of MBeans controlled by the MBean server. This method596* enables any of the following to be obtained: The names of all MBeans,597* the names of a set of MBeans specified by pattern matching on the598* <CODE>ObjectName</CODE> and/or a Query expression, a specific599* MBean name (equivalent to testing whether an MBean is registered).600* When the object name is null or or no domain and key properties are601* specified, all objects are selected (and filtered if a query is602* specified). It returns the set of ObjectNames for the MBeans603* selected.604*605* @param name The object name pattern identifying the MBeans to be606* retrieved. If null or no domain and key properties are607* specified, all the MBeans registered will be retrieved.608* @param query The query expression to be applied for selecting609* MBeans. If null no query expression will be applied for610* selecting MBeans.611*612* @return A set containing the ObjectNames for the MBeans selected.613* If no MBean satisfies the query, an empty list is returned.614*615*/616public Set<ObjectName> queryNames(ObjectName name, QueryExp query) {617618return mbsInterceptor.queryNames(cloneObjectName(name), query);619}620621/**622* Checks whether an MBean, identified by its object name, is already623* registered with the MBean server.624*625* @param name The object name of the MBean to be checked.626*627* @return True if the MBean is already registered in the MBean server,628* false otherwise.629*630* @exception RuntimeOperationsException Wraps an631* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The object632* name in parameter is null.633*634*/635public boolean isRegistered(ObjectName name) {636637return mbsInterceptor.isRegistered(name);638}639640/**641* Returns the number of MBeans registered in the MBean server.642*/643public Integer getMBeanCount() {644645return mbsInterceptor.getMBeanCount();646}647648/**649* Gets the value of a specific attribute of a named MBean. The MBean650* is identified by its object name.651*652* @param name The object name of the MBean from which the attribute653* is to be retrieved.654* @param attribute A String specifying the name of the attribute to be655* retrieved.656*657* @return The value of the retrieved attribute.658*659* @exception AttributeNotFoundException The attribute specified660* is not accessible in the MBean.661* @exception MBeanException Wraps an exception thrown by the662* MBean's getter.663* @exception InstanceNotFoundException The MBean specified is not664* registered in the MBean server.665* @exception ReflectionException Wraps an666* <CODE>{@link java.lang.Exception}</CODE> thrown when trying to667* invoke the setter.668* @exception RuntimeOperationsException Wraps an669* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:670* The object name in parameter is null or the attribute in671* parameter is null.672*/673public Object getAttribute(ObjectName name, String attribute)674throws MBeanException, AttributeNotFoundException,675InstanceNotFoundException, ReflectionException {676677return mbsInterceptor.getAttribute(cloneObjectName(name), attribute);678}679680681/**682* Enables the values of several attributes of a named MBean. The MBean683* is identified by its object name.684*685* @param name The object name of the MBean from which the attributes are686* retrieved.687* @param attributes A list of the attributes to be retrieved.688*689* @return The list of the retrieved attributes.690*691* @exception InstanceNotFoundException The MBean specified is not692* registered in the MBean server.693* @exception ReflectionException An exception occurred when trying694* to invoke the getAttributes method of a Dynamic MBean.695* @exception RuntimeOperationsException Wrap an696* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The697* object name in parameter is null or attributes in parameter698* is null.699*700*/701public AttributeList getAttributes(ObjectName name, String[] attributes)702throws InstanceNotFoundException, ReflectionException {703704return mbsInterceptor.getAttributes(cloneObjectName(name), attributes);705706}707708/**709* Sets the value of a specific attribute of a named MBean. The MBean710* is identified by its object name.711*712* @param name The name of the MBean within which the attribute is713* to be set.714* @param attribute The identification of the attribute to be set715* and the value it is to be set to.716*717* @exception InstanceNotFoundException The MBean specified is718* not registered in the MBean server.719* @exception AttributeNotFoundException The attribute specified is720* not accessible in the MBean.721* @exception InvalidAttributeValueException The value specified for722* the attribute is not valid.723* @exception MBeanException Wraps an exception thrown by the724* MBean's setter.725* @exception ReflectionException Wraps an726* <CODE>{@link java.lang.Exception}</CODE> thrown when trying727* to invoke the setter.728* @exception RuntimeOperationsException Wraps an729* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The730* object name in parameter is null or the attribute in parameter731* is null.732*/733public void setAttribute(ObjectName name, Attribute attribute)734throws InstanceNotFoundException, AttributeNotFoundException,735InvalidAttributeValueException, MBeanException,736ReflectionException {737738mbsInterceptor.setAttribute(cloneObjectName(name),739cloneAttribute(attribute));740}741742/**743* Sets the values of several attributes of a named MBean. The MBean is744* identified by its object name.745*746* @param name The object name of the MBean within which the747* attributes are to be set.748* @param attributes A list of attributes: The identification of the749* attributes to be set and the values they are to be set to.750*751* @return The list of attributes that were set, with their new values.752*753* @exception InstanceNotFoundException The MBean specified is not754* registered in the MBean server.755* @exception ReflectionException An exception occurred when trying756* to invoke the getAttributes method of a Dynamic MBean.757* @exception RuntimeOperationsException Wraps an758* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:759* The object name in parameter is null or attributes in760* parameter is null.761*762*/763public AttributeList setAttributes(ObjectName name,764AttributeList attributes)765throws InstanceNotFoundException, ReflectionException {766767return mbsInterceptor.setAttributes(cloneObjectName(name),768cloneAttributeList(attributes));769}770771/**772* Invokes an operation on an MBean.773*774* @param name The object name of the MBean on which the method is to be775* invoked.776* @param operationName The name of the operation to be invoked.777* @param params An array containing the parameters to be set when778* the operation is invoked779* @param signature An array containing the signature of the operation.780* The class objects will be loaded using the same class loader as781* the one used for loading the MBean on which the operation was782* invoked.783*784* @return The object returned by the operation, which represents the785* result ofinvoking the operation on the MBean specified.786*787* @exception InstanceNotFoundException The MBean specified is not788* registered in the MBean server.789* @exception MBeanException Wraps an exception thrown by the MBean's790* invoked method.791* @exception ReflectionException Wraps an792* <CODE>{@link java.lang.Exception}</CODE> thrown while trying793* to invoke the method.794*795*/796public Object invoke(ObjectName name, String operationName,797Object params[], String signature[])798throws InstanceNotFoundException, MBeanException,799ReflectionException {800return mbsInterceptor.invoke(cloneObjectName(name), operationName,801params, signature);802}803804/**805* Returns the default domain used for naming the MBean.806* The default domain name is used as the domain part in the ObjectName807* of MBeans if no domain is specified by the user.808*/809public String getDefaultDomain() {810return mbsInterceptor.getDefaultDomain();811}812813// From MBeanServer814public String[] getDomains() {815return mbsInterceptor.getDomains();816}817818/**819* Adds a listener to a registered MBean.820*821* @param name The name of the MBean on which the listener should be added.822* @param listener The listener object which will handle the823* notifications emitted by the registered MBean.824* @param filter The filter object. If filter is null, no filtering825* will be performed before handling notifications.826* @param handback The context to be sent to the listener when a827* notification is emitted.828*829* @exception InstanceNotFoundException The MBean name provided does830* not match any of the registered MBeans.831*/832public void addNotificationListener(ObjectName name,833NotificationListener listener,834NotificationFilter filter,835Object handback)836throws InstanceNotFoundException {837838mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,839filter, handback);840}841842/**843* Adds a listener to a registered MBean.844*845* @param name The name of the MBean on which the listener should be added.846* @param listener The object name of the listener which will handle the847* notifications emitted by the registered MBean.848* @param filter The filter object. If filter is null, no filtering will849* be performed before handling notifications.850* @param handback The context to be sent to the listener when a851* notification is emitted.852*853* @exception InstanceNotFoundException The MBean name of the854* notification listener or of the notification broadcaster855* does not match any of the registered MBeans.856*/857public void addNotificationListener(ObjectName name, ObjectName listener,858NotificationFilter filter, Object handback)859throws InstanceNotFoundException {860861mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,862filter, handback);863}864865public void removeNotificationListener(ObjectName name,866NotificationListener listener)867throws InstanceNotFoundException, ListenerNotFoundException {868869mbsInterceptor.removeNotificationListener(cloneObjectName(name),870listener);871}872873public void removeNotificationListener(ObjectName name,874NotificationListener listener,875NotificationFilter filter,876Object handback)877throws InstanceNotFoundException, ListenerNotFoundException {878879mbsInterceptor.removeNotificationListener(cloneObjectName(name),880listener, filter, handback);881}882883public void removeNotificationListener(ObjectName name,884ObjectName listener)885throws InstanceNotFoundException, ListenerNotFoundException {886887mbsInterceptor.removeNotificationListener(cloneObjectName(name),888listener);889}890891public void removeNotificationListener(ObjectName name,892ObjectName listener,893NotificationFilter filter,894Object handback)895throws InstanceNotFoundException, ListenerNotFoundException {896897mbsInterceptor.removeNotificationListener(cloneObjectName(name),898listener, filter, handback);899}900901/**902* This method discovers the attributes and operations that an MBean exposes903* for management.904*905* @param name The name of the MBean to analyze906*907* @return An instance of <CODE>MBeanInfo</CODE> allowing the retrieval of908* all attributes and operations of this MBean.909*910* @exception IntrospectionException An exception occurs during911* introspection.912* @exception InstanceNotFoundException The MBean specified is not found.913* @exception ReflectionException An exception occurred when trying to914* invoke the getMBeanInfo of a Dynamic MBean.915*/916public MBeanInfo getMBeanInfo(ObjectName name) throws917InstanceNotFoundException, IntrospectionException, ReflectionException {918919return mbsInterceptor.getMBeanInfo(cloneObjectName(name));920}921922/**923* Instantiates an object using the list of all class loaders registered924* in the MBean server (using its925* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).926* The object's class should have a public constructor.927* It returns a reference to the newly created object.928* The newly created object is not registered in the MBean server.929*930* @param className The class name of the object to be instantiated.931*932* @return The newly instantiated object.933*934* @exception ReflectionException Wraps the935* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the936* <CODE>{@link java.lang.Exception}</CODE> that937* occurred when trying to invoke the object's constructor.938* @exception MBeanException The constructor of the object has thrown939* an exception.940* @exception RuntimeOperationsException Wraps an941* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:942* The className passed in parameter is null.943*944*/945public Object instantiate(String className)946throws ReflectionException, MBeanException {947948/* Permission check */949checkMBeanPermission(className, null, null, "instantiate");950951return instantiator.instantiate(className);952}953954/**955* Instantiates an object using the class Loader specified by its956* <CODE>ObjectName</CODE>.957* If the loader name is null, the ClassLoader that loaded the958* MBean Server will be used.959* The object's class should have a public constructor.960* It returns a reference to the newly created object.961* The newly created object is not registered in the MBean server.962*963* @param className The class name of the MBean to be instantiated.964* @param loaderName The object name of the class loader to be used.965*966* @return The newly instantiated object.967*968* @exception ReflectionException Wraps the969* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the970* <CODE>{@link java.lang.Exception}</CODE> that971* occurred when trying to invoke the object's constructor.972* @exception MBeanException The constructor of the object has thrown973* an exception.974* @exception InstanceNotFoundException The specified class loader975* is not registered in the MBaenServer.976* @exception RuntimeOperationsException Wraps an977* <CODE>{@link java.lang.IllegalArgumentException}</CODE>: The978* className passed in parameter is null.979*980*/981public Object instantiate(String className, ObjectName loaderName)982throws ReflectionException, MBeanException,983InstanceNotFoundException {984985/* Permission check */986checkMBeanPermission(className, null, null, "instantiate");987988ClassLoader myLoader = outerShell.getClass().getClassLoader();989return instantiator.instantiate(className, loaderName, myLoader);990}991992/**993* Instantiates an object using the list of all class loaders registered994* in the MBean server (using its995* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).996* The object's class should have a public constructor.997* The call returns a reference to the newly created object.998* The newly created object is not registered in the MBean server.999*1000* @param className The class name of the object to be instantiated.1001* @param params An array containing the parameters of the constructor1002* to be invoked.1003* @param signature An array containing the signature of the1004* constructor to be invoked.1005*1006* @return The newly instantiated object.1007*1008* @exception ReflectionException Wraps the1009* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the1010* <CODE>{@link java.lang.Exception}</CODE> that1011* occurred when trying to invoke the object's constructor.1012* @exception MBeanException The constructor of the object has thrown1013* an exception.1014* @exception RuntimeOperationsException Wraps an1015* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:1016* The className passed in parameter is null.1017*1018*/1019public Object instantiate(String className, Object params[],1020String signature[])1021throws ReflectionException, MBeanException {10221023/* Permission check */1024checkMBeanPermission(className, null, null, "instantiate");10251026ClassLoader myLoader = outerShell.getClass().getClassLoader();1027return instantiator.instantiate(className, params, signature,1028myLoader);1029}10301031/**1032* Instantiates an object. The class loader to be used is identified1033* by its object name. If the object name of the loader is null,1034* the ClassLoader that loaded the MBean server will be used.1035* The object's class should have a public constructor.1036* The call returns a reference to the newly created object.1037* The newly created object is not registered in the MBean server.1038*1039* @param className The class name of the object to be instantiated.1040* @param params An array containing the parameters of the constructor1041* to be invoked.1042* @param signature An array containing the signature of the constructor1043* to be invoked.1044* @param loaderName The object name of the class loader to be used.1045*1046* @return The newly instantiated object.1047*1048* @exception ReflectionException Wraps the1049* <CODE>{@link java.lang.ClassNotFoundException}</CODE> or the1050* <CODE>{@link java.lang.Exception}</CODE> that1051* occurred when trying to invoke the object's constructor.1052* @exception MBeanException The constructor of the object has thrown1053* an exception.1054* @exception InstanceNotFoundException The specified class loader1055* is not registered in the MBean server.1056* @exception RuntimeOperationsException Wraps an1057* <CODE>{@link java.lang.IllegalArgumentException}</CODE>:1058* The className passed in parameter is null.1059*1060*/1061public Object instantiate(String className, ObjectName loaderName,1062Object params[], String signature[])1063throws ReflectionException, MBeanException,1064InstanceNotFoundException {10651066/* Permission check */1067checkMBeanPermission(className, null, null, "instantiate");10681069ClassLoader myLoader = outerShell.getClass().getClassLoader();1070return instantiator.instantiate(className,loaderName,params,signature,1071myLoader);1072}10731074/**1075* Returns true if the MBean specified is an instance of the specified1076* class, false otherwise.1077*1078* @param name The <CODE>ObjectName</CODE> of the MBean.1079* @param className The name of the class.1080*1081* @return true if the MBean specified is an instance of the specified1082* class, false otherwise.1083*1084* @exception InstanceNotFoundException The MBean specified is not1085* registered in the MBean server.1086*/1087public boolean isInstanceOf(ObjectName name, String className)1088throws InstanceNotFoundException {10891090return mbsInterceptor.isInstanceOf(cloneObjectName(name), className);1091}10921093/**1094* De-serializes a byte array in the context of the class loader1095* of an MBean.1096*1097* @param name The name of the MBean whose class loader should1098* be used for the de-serialization.1099* @param data The byte array to be de-sererialized.1100*1101* @return The de-serialized object stream.1102*1103* @exception InstanceNotFoundException The MBean specified is not1104* found.1105* @exception OperationsException Any of the usual Input/Output1106* related exceptions.1107*1108*/1109@Deprecated1110public ObjectInputStream deserialize(ObjectName name, byte[] data)1111throws InstanceNotFoundException, OperationsException {11121113/* Permission check */1114// This call requires MBeanPermission 'getClassLoaderFor'1115final ClassLoader loader = getClassLoaderFor(name);11161117return instantiator.deserialize(loader, data);1118}11191120/**1121* De-serializes a byte array in the context of a given MBean class loader.1122* The class loader is the one that loaded the class with name "className".1123*1124* @param className The name of the class whose class loader should be1125* used for the de-serialization.1126* @param data The byte array to be de-sererialized.1127*1128* @return The de-serialized object stream.1129*1130* @exception OperationsException Any of the usual Input/Output1131* related exceptions.1132* @exception ReflectionException The specified class could not be1133* loaded by the default loader repository1134*1135*/1136@Deprecated1137public ObjectInputStream deserialize(String className, byte[] data)1138throws OperationsException, ReflectionException {11391140if (className == null) {1141throw new RuntimeOperationsException(1142new IllegalArgumentException(),1143"Null className passed in parameter");1144}11451146/* Permission check */1147// This call requires MBeanPermission 'getClassLoaderRepository'1148final ClassLoaderRepository clr = getClassLoaderRepository();11491150Class<?> theClass;1151try {1152if (clr == null) throw new ClassNotFoundException(className);1153theClass = clr.loadClass(className);1154} catch (ClassNotFoundException e) {1155throw new ReflectionException(e,1156"The given class could not be " +1157"loaded by the default loader " +1158"repository");1159}11601161return instantiator.deserialize(theClass.getClassLoader(), data);1162}11631164/**1165* De-serializes a byte array in the context of a given MBean class loader.1166* The class loader is the one that loaded the class with name "className".1167* The name of the class loader to be used for loading the specified1168* class is specified.1169* If null, the MBean Server's class loader will be used.1170*1171* @param className The name of the class whose class loader should be1172* used for the de-serialization.1173* @param data The byte array to be de-sererialized.1174* @param loaderName The name of the class loader to be used for1175* loading the specified class.1176* If null, the MBean Server's class loader will be used.1177*1178* @return The de-serialized object stream.1179*1180* @exception InstanceNotFoundException The specified class loader1181* MBean is not found.1182* @exception OperationsException Any of the usual Input/Output1183* related exceptions.1184* @exception ReflectionException The specified class could not1185* be loaded by the specified class loader.1186*1187*/1188@Deprecated1189public ObjectInputStream deserialize(String className,1190ObjectName loaderName,1191byte[] data) throws1192InstanceNotFoundException, OperationsException, ReflectionException {11931194// Clone ObjectName1195//1196loaderName = cloneObjectName(loaderName);11971198/* Permission check */1199// Make this call just to force the 'getClassLoader'1200// permission check1201try {1202getClassLoader(loaderName);1203} catch (SecurityException e) {1204throw e;1205} catch (Exception e) {1206}12071208ClassLoader myLoader = outerShell.getClass().getClassLoader();1209return instantiator.deserialize(className, loaderName, data, myLoader);1210}12111212/**1213* Initializes this MBeanServer, registering the MBeanServerDelegate.1214* <p>This method must be called once, before using the MBeanServer.1215**/1216private void initialize() {1217if (instantiator == null) throw new1218IllegalStateException("instantiator must not be null.");12191220// Registers the MBeanServer identification MBean1221try {1222AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {1223public Object run() throws Exception {1224mbsInterceptor.registerMBean(1225mBeanServerDelegateObject,1226MBeanServerDelegate.DELEGATE_NAME);1227return null;1228}1229});1230} catch (SecurityException e) {1231if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {1232MBEANSERVER_LOGGER.logp(Level.FINEST,1233JmxMBeanServer.class.getName(), "initialize",1234"Unexpected security exception occurred", e);1235}1236throw e;1237} catch (Exception e) {1238if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {1239MBEANSERVER_LOGGER.logp(Level.FINEST,1240JmxMBeanServer.class.getName(), "initialize",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 {1504SecurityManager sm = System.getSecurityManager();1505if (sm != null) {1506Permission perm = new MBeanPermission(classname,1507member,1508objectName,1509actions);1510sm.checkPermission(perm);1511}1512}15131514private static void checkNewMBeanServerPermission() {1515SecurityManager sm = System.getSecurityManager();1516if (sm != null) {1517Permission perm = new MBeanServerPermission("newMBeanServer");1518sm.checkPermission(perm);1519}1520}1521}152215231524