/* * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, * CA 95054 USA or visit www.sun.com if you need additional information or * have any questions. */ package com.sun.jmx.mbeanserver; import static com.sun.jmx.defaults.JmxProperties.MBEANSERVER_LOGGER; import com.sun.jmx.interceptor.NamespaceDispatchInterceptor; import java.io.ObjectInputStream; import java.security.AccessController; import java.security.Permission; import java.security.PrivilegedExceptionAction; import java.util.Iterator; import java.util.Set; import java.util.logging.Level; import javax.management.Attribute; import javax.management.AttributeList; import javax.management.AttributeNotFoundException; import javax.management.InstanceAlreadyExistsException; import javax.management.InstanceNotFoundException; import javax.management.IntrospectionException; import javax.management.InvalidAttributeValueException; import javax.management.ListenerNotFoundException; import javax.management.MBeanException; import javax.management.MBeanInfo; import javax.management.MBeanPermission; import javax.management.MBeanRegistrationException; import javax.management.MBeanServer; import javax.management.MBeanServerDelegate; import javax.management.NotCompliantMBeanException; import javax.management.NotificationFilter; import javax.management.NotificationListener; import javax.management.ObjectInstance; import javax.management.ObjectName; import javax.management.OperationsException; import javax.management.QueryExp; import javax.management.ReflectionException; import javax.management.RuntimeOperationsException; import javax.management.loading.ClassLoaderRepository; /** * This is the base class for MBean manipulation on the agent side. It * contains the methods necessary for the creation, registration, and * deletion of MBeans as well as the access methods for registered MBeans. * This is the core component of the JMX infrastructure. *
* Every MBean which is added to the MBean server becomes manageable: * its attributes and operations become remotely accessible through * the connectors/adaptors connected to that MBean server. * A Java object cannot be registered in the MBean server unless it is a * JMX compliant MBean. *
* When an MBean is registered or unregistered in the MBean server an
* {@link javax.management.MBeanServerNotification MBeanServerNotification}
* Notification is emitted. To register an object as listener to
* MBeanServerNotifications you should call the MBean server method
* {@link #addNotificationListener addNotificationListener} with
* the ObjectName
of the
* {@link javax.management.MBeanServerDelegate MBeanServerDelegate}.
* This ObjectName
is:
*
* JMImplementation:type=MBeanServerDelegate
.
*
* @since 1.5
*/
public final class JmxMBeanServer
implements SunJmxMBeanServer {
/** Control the default locking policy of the repository.
* By default, we will be using a fair locking policy.
**/
public static final boolean DEFAULT_FAIR_LOCK_POLICY = true;
private final MBeanInstantiator instantiator;
private final SecureClassLoaderRepository secureClr;
/** true if interceptors are enabled **/
private final boolean interceptorsEnabled;
private final MBeanServer outerShell;
private volatile MBeanServer mbsInterceptor = null;
/** The MBeanServerDelegate object representing the MBean Server */
private final MBeanServerDelegate mBeanServerDelegateObject;
private final String mbeanServerName;
/**
* Package: Creates an MBeanServer with the
* specified default domain name, outer interface, and delegate.
*
The default domain name is used as the domain part in the ObjectName * of MBeans if no domain is specified by the user. *
* By default, {@link MBeanServerInterceptor} are disabled. Use * {@link #JmxMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)} to enable them. *
The default domain name is used as the domain part in the ObjectName * of MBeans if no domain is specified by the user. *
true
,
* {@link MBeanServerInterceptor} will be enabled (default is
* false
)
* Note: this parameter is not taken into account by this
* implementation - the default value false
is
* always used.
* @exception IllegalArgumentException if the instantiator is null.
*/
JmxMBeanServer(String domain, MBeanServer outer,
MBeanServerDelegate delegate, boolean interceptors) {
this(domain,outer,delegate,null,false);
}
/**
* Package: Creates an MBeanServer.
* @param domain The default domain name used by this MBeanServer.
* @param outer A pointer to the MBeanServer object that must be
* passed to the MBeans when invoking their
* {@link javax.management.MBeanRegistration} interface.
* @param delegate A pointer to the MBeanServerDelegate associated
* with the new MBeanServer. The new MBeanServer must register
* this MBean in its MBean repository.
* @param instantiator The MBeanInstantiator that will be used to
* instantiate MBeans and take care of class loading issues.
* @param metadata The MetaData object that will be used by the
* MBean server in order to invoke the MBean interface of
* the registered MBeans.
* @param interceptors If true
,
* {@link MBeanServerInterceptor} will be enabled (default is
* false
).
*/
JmxMBeanServer(String domain, MBeanServer outer,
MBeanServerDelegate delegate,
MBeanInstantiator instantiator,
boolean interceptors) {
this(domain,outer,delegate,instantiator,interceptors,true);
}
/**
* Package: Creates an MBeanServer.
* @param domain The default domain name used by this MBeanServer.
* @param outer A pointer to the MBeanServer object that must be
* passed to the MBeans when invoking their
* {@link javax.management.MBeanRegistration} interface.
* @param delegate A pointer to the MBeanServerDelegate associated
* with the new MBeanServer. The new MBeanServer must register
* this MBean in its MBean repository.
* @param instantiator The MBeanInstantiator that will be used to
* instantiate MBeans and take care of class loading issues.
* @param metadata The MetaData object that will be used by the
* MBean server in order to invoke the MBean interface of
* the registered MBeans.
* @param interceptors If true
,
* {@link MBeanServerInterceptor} will be enabled (default is
* false
).
* @param fairLock If {@code true}, the MBean repository will use a {@link
* java.util.concurrent.locks.ReentrantReadWriteLock#ReentrantReadWriteLock(boolean)
* fair locking} policy.
*/
JmxMBeanServer(String domain, MBeanServer outer,
MBeanServerDelegate delegate,
MBeanInstantiator instantiator,
boolean interceptors,
boolean fairLock) {
if (instantiator == null) {
final ModifiableClassLoaderRepository
clr = new ClassLoaderRepositorySupport();
instantiator = new MBeanInstantiator(clr);
}
this.secureClr = new
SecureClassLoaderRepository(instantiator.getClassLoaderRepository());
if (delegate == null)
delegate = new MBeanServerDelegateImpl();
if (outer == null)
outer = this;
this.instantiator = instantiator;
this.mBeanServerDelegateObject = delegate;
this.outerShell = outer;
final Repository repository = new Repository(domain,fairLock);
this.mbsInterceptor =
new NamespaceDispatchInterceptor(outer, delegate, instantiator,
repository);
this.interceptorsEnabled = interceptors;
this.mbeanServerName = Util.getMBeanServerSecurityName(delegate);
initialize();
}
/**
* Tell whether {@link MBeanServerInterceptor}s are enabled on this
* object.
* @return true
if {@link MBeanServerInterceptor}s are
* enabled.
* @see #newMBeanServer(java.lang.String,javax.management.MBeanServer,javax.management.MBeanServerDelegate,boolean)
**/
public boolean interceptorsEnabled() {
return interceptorsEnabled;
}
/**
* Return the MBeanInstantiator associated to this MBeanServer.
* @exception UnsupportedOperationException if
* {@link MBeanServerInterceptor}s
* are not enabled on this object.
* @see #interceptorsEnabled
**/
public MBeanInstantiator getMBeanInstantiator() {
if (interceptorsEnabled) return instantiator;
else throw new UnsupportedOperationException(
"MBeanServerInterceptors are disabled.");
}
/**
* Instantiates and registers an MBean in the MBean server.
* The MBean server will use its
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}
* to load the class of the MBean.
* An object name is associated to the MBean.
* If the object name given is null, the MBean can automatically
* provide its own name by implementing the
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
* The call returns an ObjectInstance
object representing
* the newly created MBean.
*
* @param className The class name of the MBean to be instantiated.
* @param name The object name of the MBean. May be null.
*
* @return An ObjectInstance
, containing the
* ObjectName
and the Java class name of the newly
* instantiated MBean.
*
* @exception ReflectionException Wraps an
* {@link java.lang.ClassNotFoundException}
or an
* {@link java.lang.Exception}
that occurred
* when trying to invoke the MBean's constructor.
* @exception InstanceAlreadyExistsException The MBean is already
* under the control of the MBean server.
* @exception MBeanRegistrationException The preRegister()
* (MBeanRegistration
interface) method of the MBean
* has thrown an exception. The MBean will not be registered.
* @exception MBeanException The constructor of the MBean has thrown
* an exception.
* @exception NotCompliantMBeanException This class is not a JMX
* compliant MBean.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
:
* The className passed in parameter is null, the
* ObjectName
passed in parameter contains a pattern
* or no ObjectName
is specified for the MBean.
*
*/
public ObjectInstance createMBean(String className, ObjectName name)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
return mbsInterceptor.createMBean(className,
cloneObjectName(name),
(Object[]) null,
(String[]) null);
}
/**
* Instantiates and registers an MBean in the MBean server.
* The class loader to be used is identified by its object name.
* An object name is associated to the MBean.
* If the object name of the loader is null, the ClassLoader that
* loaded the MBean server will be used.
* If the MBean's object name given is null, the MBean can
* automatically provide its own name by implementing the
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
* The call returns an ObjectInstance
object representing
* the newly created MBean.
*
* @param className The class name of the MBean to be instantiated.
* @param name The object name of the MBean. May be null.
* @param loaderName The object name of the class loader to be used.
*
* @return An ObjectInstance
, containing the
* ObjectName
and the Java class name
* of the newly instantiated MBean.
*
* @exception ReflectionException Wraps an
* {@link java.lang.ClassNotFoundException}
or an
* {@link java.lang.Exception}
that occurred when trying
* to invoke the MBean's constructor.
* @exception InstanceAlreadyExistsException The MBean is already
* under the control of the MBean server.
* @exception MBeanRegistrationException The preRegister()
* (MBeanRegistration
interface) method of the MBean
* has thrown an exception. The MBean will not be registered.
* @exception MBeanException The constructor of the MBean has thrown
* an exception
* @exception NotCompliantMBeanException This class is not a JMX
* compliant MBean.
* @exception InstanceNotFoundException The specified class loader
* is not registered in the MBean server.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
: The
* className passed in parameter is null, the ObjectName
* passed in parameter contains a pattern or no
* ObjectName
is specified for the MBean.
*/
public ObjectInstance createMBean(String className, ObjectName name,
ObjectName loaderName)
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
return mbsInterceptor.createMBean(className,
cloneObjectName(name),
loaderName,
(Object[]) null,
(String[]) null);
}
/**
* Instantiates and registers an MBean in the MBean server.
* The MBean server will use its
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}
* to load the class of the MBean.
* An object name is associated to the MBean.
* If the object name given is null, the MBean can automatically
* provide its own name by implementing the
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
* The call returns an ObjectInstance
object representing
* the newly created MBean.
*
* @param className The class name of the MBean to be instantiated.
* @param name The object name of the MBean. May be null.
* @param params An array containing the parameters of the constructor
* to be invoked.
* @param signature An array containing the signature of the
* constructor to be invoked.
*
* @return An ObjectInstance
, containing the
* ObjectName
and the Java class name
* of the newly instantiated MBean.
*
* @exception ReflectionException Wraps a
* {@link java.lang.ClassNotFoundException}
or an
* {@link java.lang.Exception}
that occurred
* when trying to invoke the MBean's constructor.
* @exception InstanceAlreadyExistsException The MBean is already
* under the control of the MBean server.
* @exception MBeanRegistrationException The preRegister()
* (MBeanRegistration
interface) method of the MBean
* has thrown an exception. The MBean will not be registered.
* @exception MBeanException The constructor of the MBean has
* thrown an exception.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
: The
* className passed in parameter is null, the ObjectName
* passed in parameter contains a pattern or no
* ObjectName
is specified for the MBean.
*
*/
public ObjectInstance createMBean(String className, ObjectName name,
Object params[], String signature[])
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException {
return mbsInterceptor.createMBean(className, cloneObjectName(name),
params, signature);
}
/**
* Instantiates and registers an MBean in the MBean server.
* The class loader to be used is identified by its object name.
* An object name is associated to the MBean. If the object name
* of the loader is not specified, the ClassLoader that loaded the
* MBean server will be used.
* If the MBean object name given is null, the MBean can automatically
* provide its own name by implementing the
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
* The call returns an ObjectInstance
object representing
* the newly created MBean.
*
* @param className The class name of the MBean to be instantiated.
* @param name The object name of the MBean. May be null.
* @param params An array containing the parameters of the constructor
* to be invoked.
* @param signature An array containing the signature of the
* constructor to be invoked.
* @param loaderName The object name of the class loader to be used.
*
* @return An ObjectInstance
, containing the
* ObjectName
and the Java class name of the newly
* instantiated MBean.
*
* @exception ReflectionException Wraps a
* {@link java.lang.ClassNotFoundException}
or an
* {@link java.lang.Exception}
* that occurred when trying to invoke the MBean's constructor.
* @exception InstanceAlreadyExistsException The MBean is already
* under the control of the MBean server.
* @exception MBeanRegistrationException The preRegister()
* (MBeanRegistration
interface) method of the MBean
* has thrown an exception. The MBean will not be registered.
* @exception MBeanException The constructor of the MBean has
* thrown an exception
* @exception InstanceNotFoundException The specified class loader is
* not registered in the MBean server.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
: The
* className passed in parameter is null, the ObjectName
* passed in parameter contains a pattern or no
* ObjectName
is specified for the MBean.
*
*/
public ObjectInstance createMBean(String className, ObjectName name,
ObjectName loaderName, Object params[],
String signature[])
throws ReflectionException, InstanceAlreadyExistsException,
MBeanRegistrationException, MBeanException,
NotCompliantMBeanException, InstanceNotFoundException {
return mbsInterceptor.createMBean(className, cloneObjectName(name),
loaderName, params, signature);
}
/**
* Registers a pre-existing object as an MBean with the MBean server.
* If the object name given is null, the MBean may automatically
* provide its own name by implementing the
* {@link javax.management.MBeanRegistration MBeanRegistration} interface.
* The call returns an ObjectInstance
object representing
* the registered MBean.
*
* @param object The MBean to be registered as an MBean.
* @param name The object name of the MBean. May be null.
*
* @return The ObjectInstance
for the MBean that has been
* registered.
*
* @exception InstanceAlreadyExistsException The MBean is already
* under the control of the MBean server.
* @exception MBeanRegistrationException The preRegister()
* (MBeanRegistration
interface) method of the MBean
* has thrown an exception. The MBean will not be registered.
* @exception NotCompliantMBeanException This object is not a JMX
* compliant MBean
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
: The
* object passed in parameter is null or no object name is specified.
*
*/
public ObjectInstance registerMBean(Object object, ObjectName name)
throws InstanceAlreadyExistsException, MBeanRegistrationException,
NotCompliantMBeanException {
return mbsInterceptor.registerMBean(object, cloneObjectName(name));
}
/**
* De-registers an MBean from the MBean server. The MBean is identified by
* its object name. Once the method has been invoked, the MBean may
* no longer be accessed by its object name.
*
* @param name The object name of the MBean to be de-registered.
*
* @exception InstanceNotFoundException The MBean specified is not
* registered in the MBean server.
* @exception MBeanRegistrationException The preDeregister()
* (MBeanRegistration
interface) method of the MBean
* has thrown an exception.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
: The
* object name in parameter is null or the MBean you are when
* trying to de-register is the
* {@link javax.management.MBeanServerDelegate MBeanServerDelegate}
* MBean.
**/
public void unregisterMBean(ObjectName name)
throws InstanceNotFoundException, MBeanRegistrationException {
mbsInterceptor.unregisterMBean(cloneObjectName(name));
}
/**
* Gets the ObjectInstance
for a given MBean registered
* with the MBean server.
*
* @param name The object name of the MBean.
*
* @return The ObjectInstance
associated to the MBean
* specified by name.
*
* @exception InstanceNotFoundException The MBean specified is not
* registered in the MBean server.
*/
public ObjectInstance getObjectInstance(ObjectName name)
throws InstanceNotFoundException {
return mbsInterceptor.getObjectInstance(cloneObjectName(name));
}
/**
* Gets MBeans controlled by the MBean server. This method allows any
* of the following to be obtained: All MBeans, a set of MBeans specified
* by pattern matching on the ObjectName
and/or a Query
* expression, a specific MBean. When the object name is null or no
* domain and key properties are specified, all objects are to be
* selected (and filtered if a query is specified). It returns the
* set of ObjectInstance
objects (containing the
* ObjectName
and the Java Class name) for
* the selected MBeans.
*
* @param name The object name pattern identifying the MBeans to
* be retrieved. If null or or no domain and key properties
* are specified, all the MBeans registered will be retrieved.
* @param query The query expression to be applied for selecting
* MBeans. If null no query expression will be applied for
* selecting MBeans.
*
* @return A set containing the ObjectInstance
objects
* for the selected MBeans.
* If no MBean satisfies the query an empty list is returned.
*
*/
public SetObjectName
and/or a Query expression, a specific
* MBean name (equivalent to testing whether an MBean is registered).
* When the object name is null or or no domain and key properties are
* specified, all objects are selected (and filtered if a query is
* specified). It returns the set of ObjectNames for the MBeans
* selected.
*
* @param name The object name pattern identifying the MBeans to be
* retrieved. If null or no domain and key properties are
* specified, all the MBeans registered will be retrieved.
* @param query The query expression to be applied for selecting
* MBeans. If null no query expression will be applied for
* selecting MBeans.
*
* @return A set containing the ObjectNames for the MBeans selected.
* If no MBean satisfies the query, an empty list is returned.
*
*/
public Set{@link java.lang.IllegalArgumentException}
: The object
* name in parameter is null.
*
*/
public boolean isRegistered(ObjectName name) {
return mbsInterceptor.isRegistered(name);
}
/**
* Returns the number of MBeans registered in the MBean server.
*/
public Integer getMBeanCount() {
return mbsInterceptor.getMBeanCount();
}
/**
* Gets the value of a specific attribute of a named MBean. The MBean
* is identified by its object name.
*
* @param name The object name of the MBean from which the attribute
* is to be retrieved.
* @param attribute A String specifying the name of the attribute to be
* retrieved.
*
* @return The value of the retrieved attribute.
*
* @exception AttributeNotFoundException The attribute specified
* is not accessible in the MBean.
* @exception MBeanException Wraps an exception thrown by the
* MBean's getter.
* @exception InstanceNotFoundException The MBean specified is not
* registered in the MBean server.
* @exception ReflectionException Wraps an
* {@link java.lang.Exception}
thrown when trying to
* invoke the setter.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
:
* The object name in parameter is null or the attribute in
* parameter is null.
*/
public Object getAttribute(ObjectName name, String attribute)
throws MBeanException, AttributeNotFoundException,
InstanceNotFoundException, ReflectionException {
return mbsInterceptor.getAttribute(cloneObjectName(name), attribute);
}
/**
* Enables the values of several attributes of a named MBean. The MBean
* is identified by its object name.
*
* @param name The object name of the MBean from which the attributes are
* retrieved.
* @param attributes A list of the attributes to be retrieved.
*
* @return The list of the retrieved attributes.
*
* @exception InstanceNotFoundException The MBean specified is not
* registered in the MBean server.
* @exception ReflectionException An exception occurred when trying
* to invoke the getAttributes method of a Dynamic MBean.
* @exception RuntimeOperationsException Wrap an
* {@link java.lang.IllegalArgumentException}
: The
* object name in parameter is null or attributes in parameter
* is null.
*
*/
public AttributeList getAttributes(ObjectName name, String[] attributes)
throws InstanceNotFoundException, ReflectionException {
return mbsInterceptor.getAttributes(cloneObjectName(name), attributes);
}
/**
* Sets the value of a specific attribute of a named MBean. The MBean
* is identified by its object name.
*
* @param name The name of the MBean within which the attribute is
* to be set.
* @param attribute The identification of the attribute to be set
* and the value it is to be set to.
*
* @exception InstanceNotFoundException The MBean specified is
* not registered in the MBean server.
* @exception AttributeNotFoundException The attribute specified is
* not accessible in the MBean.
* @exception InvalidAttributeValueException The value specified for
* the attribute is not valid.
* @exception MBeanException Wraps an exception thrown by the
* MBean's setter.
* @exception ReflectionException Wraps an
* {@link java.lang.Exception}
thrown when trying
* to invoke the setter.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
: The
* object name in parameter is null or the attribute in parameter
* is null.
*/
public void setAttribute(ObjectName name, Attribute attribute)
throws InstanceNotFoundException, AttributeNotFoundException,
InvalidAttributeValueException, MBeanException,
ReflectionException {
mbsInterceptor.setAttribute(cloneObjectName(name),
cloneAttribute(attribute));
}
/**
* Sets the values of several attributes of a named MBean. The MBean is
* identified by its object name.
*
* @param name The object name of the MBean within which the
* attributes are to be set.
* @param attributes A list of attributes: The identification of the
* attributes to be set and the values they are to be set to.
*
* @return The list of attributes that were set, with their new values.
*
* @exception InstanceNotFoundException The MBean specified is not
* registered in the MBean server.
* @exception ReflectionException An exception occurred when trying
* to invoke the getAttributes method of a Dynamic MBean.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
:
* The object name in parameter is null or attributes in
* parameter is null.
*
*/
public AttributeList setAttributes(ObjectName name,
AttributeList attributes)
throws InstanceNotFoundException, ReflectionException {
return mbsInterceptor.setAttributes(cloneObjectName(name),
cloneAttributeList(attributes));
}
/**
* Invokes an operation on an MBean.
*
* @param name The object name of the MBean on which the method is to be
* invoked.
* @param operationName The name of the operation to be invoked.
* @param params An array containing the parameters to be set when
* the operation is invoked
* @param signature An array containing the signature of the operation.
* The class objects will be loaded using the same class loader as
* the one used for loading the MBean on which the operation was
* invoked.
*
* @return The object returned by the operation, which represents the
* result ofinvoking the operation on the MBean specified.
*
* @exception InstanceNotFoundException The MBean specified is not
* registered in the MBean server.
* @exception MBeanException Wraps an exception thrown by the MBean's
* invoked method.
* @exception ReflectionException Wraps an
* {@link java.lang.Exception}
thrown while trying
* to invoke the method.
*
*/
public Object invoke(ObjectName name, String operationName,
Object params[], String signature[])
throws InstanceNotFoundException, MBeanException,
ReflectionException {
return mbsInterceptor.invoke(cloneObjectName(name), operationName,
params, signature);
}
/**
* Returns the default domain used for naming the MBean.
* The default domain name is used as the domain part in the ObjectName
* of MBeans if no domain is specified by the user.
*/
public String getDefaultDomain() {
return mbsInterceptor.getDefaultDomain();
}
// From MBeanServer
public String[] getDomains() {
return mbsInterceptor.getDomains();
}
/**
* Adds a listener to a registered MBean.
*
* @param name The name of the MBean on which the listener should be added.
* @param listener The listener object which will handle the
* notifications emitted by the registered MBean.
* @param filter The filter object. If filter is null, no filtering
* will be performed before handling notifications.
* @param handback The context to be sent to the listener when a
* notification is emitted.
*
* @exception InstanceNotFoundException The MBean name provided does
* not match any of the registered MBeans.
*/
public void addNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
throws InstanceNotFoundException {
mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,
filter, handback);
}
/**
* Adds a listener to a registered MBean.
*
* @param name The name of the MBean on which the listener should be added.
* @param listener The object name of the listener which will handle the
* notifications emitted by the registered MBean.
* @param filter The filter object. If filter is null, no filtering will
* be performed before handling notifications.
* @param handback The context to be sent to the listener when a
* notification is emitted.
*
* @exception InstanceNotFoundException The MBean name of the
* notification listener or of the notification broadcaster
* does not match any of the registered MBeans.
*/
public void addNotificationListener(ObjectName name, ObjectName listener,
NotificationFilter filter, Object handback)
throws InstanceNotFoundException {
mbsInterceptor.addNotificationListener(cloneObjectName(name), listener,
filter, handback);
}
public void removeNotificationListener(ObjectName name,
NotificationListener listener)
throws InstanceNotFoundException, ListenerNotFoundException {
mbsInterceptor.removeNotificationListener(cloneObjectName(name),
listener);
}
public void removeNotificationListener(ObjectName name,
NotificationListener listener,
NotificationFilter filter,
Object handback)
throws InstanceNotFoundException, ListenerNotFoundException {
mbsInterceptor.removeNotificationListener(cloneObjectName(name),
listener, filter, handback);
}
public void removeNotificationListener(ObjectName name,
ObjectName listener)
throws InstanceNotFoundException, ListenerNotFoundException {
mbsInterceptor.removeNotificationListener(cloneObjectName(name),
listener);
}
public void removeNotificationListener(ObjectName name,
ObjectName listener,
NotificationFilter filter,
Object handback)
throws InstanceNotFoundException, ListenerNotFoundException {
mbsInterceptor.removeNotificationListener(cloneObjectName(name),
listener, filter, handback);
}
/**
* This method discovers the attributes and operations that an MBean exposes
* for management.
*
* @param name The name of the MBean to analyze
*
* @return An instance of MBeanInfo
allowing the retrieval of
* all attributes and operations of this MBean.
*
* @exception IntrospectionException An exception occurs during
* introspection.
* @exception InstanceNotFoundException The MBean specified is not found.
* @exception ReflectionException An exception occurred when trying to
* invoke the getMBeanInfo of a Dynamic MBean.
*/
public MBeanInfo getMBeanInfo(ObjectName name) throws
InstanceNotFoundException, IntrospectionException, ReflectionException {
return mbsInterceptor.getMBeanInfo(cloneObjectName(name));
}
/**
* Instantiates an object using the list of all class loaders registered
* in the MBean server (using its
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
* The object's class should have a public constructor.
* It returns a reference to the newly created object.
* The newly created object is not registered in the MBean server.
*
* @param className The class name of the object to be instantiated.
*
* @return The newly instantiated object.
*
* @exception ReflectionException Wraps the
* {@link java.lang.ClassNotFoundException}
or the
* {@link java.lang.Exception}
that
* occurred when trying to invoke the object's constructor.
* @exception MBeanException The constructor of the object has thrown
* an exception.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
:
* The className passed in parameter is null.
*
*/
public Object instantiate(String className)
throws ReflectionException, MBeanException {
/* Permission check */
checkMBeanPermission(mbeanServerName, className, null, null,
"instantiate");
return instantiator.instantiate(className);
}
/**
* Instantiates an object using the class Loader specified by its
* ObjectName
.
* If the loader name is null, the ClassLoader that loaded the
* MBean Server will be used.
* The object's class should have a public constructor.
* It returns a reference to the newly created object.
* The newly created object is not registered in the MBean server.
*
* @param className The class name of the MBean to be instantiated.
* @param loaderName The object name of the class loader to be used.
*
* @return The newly instantiated object.
*
* @exception ReflectionException Wraps the
* {@link java.lang.ClassNotFoundException}
or the
* {@link java.lang.Exception}
that
* occurred when trying to invoke the object's constructor.
* @exception MBeanException The constructor of the object has thrown
* an exception.
* @exception InstanceNotFoundException The specified class loader
* is not registered in the MBaenServer.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
: The
* className passed in parameter is null.
*
*/
public Object instantiate(String className, ObjectName loaderName)
throws ReflectionException, MBeanException,
InstanceNotFoundException {
/* Permission check */
checkMBeanPermission(mbeanServerName, className, null,
null, "instantiate");
ClassLoader myLoader = outerShell.getClass().getClassLoader();
return instantiator.instantiate(className, loaderName, myLoader);
}
/**
* Instantiates an object using the list of all class loaders registered
* in the MBean server (using its
* {@link javax.management.loading.ClassLoaderRepository Default Loader Repository}).
* The object's class should have a public constructor.
* The call returns a reference to the newly created object.
* The newly created object is not registered in the MBean server.
*
* @param className The class name of the object to be instantiated.
* @param params An array containing the parameters of the constructor
* to be invoked.
* @param signature An array containing the signature of the
* constructor to be invoked.
*
* @return The newly instantiated object.
*
* @exception ReflectionException Wraps the
* {@link java.lang.ClassNotFoundException}
or the
* {@link java.lang.Exception}
that
* occurred when trying to invoke the object's constructor.
* @exception MBeanException The constructor of the object has thrown
* an exception.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
:
* The className passed in parameter is null.
*
*/
public Object instantiate(String className, Object params[],
String signature[])
throws ReflectionException, MBeanException {
/* Permission check */
checkMBeanPermission(mbeanServerName, className, null, null,
"instantiate");
ClassLoader myLoader = outerShell.getClass().getClassLoader();
return instantiator.instantiate(className, params, signature,
myLoader);
}
/**
* Instantiates an object. The class loader to be used is identified
* by its object name. If the object name of the loader is null,
* the ClassLoader that loaded the MBean server will be used.
* The object's class should have a public constructor.
* The call returns a reference to the newly created object.
* The newly created object is not registered in the MBean server.
*
* @param className The class name of the object to be instantiated.
* @param params An array containing the parameters of the constructor
* to be invoked.
* @param signature An array containing the signature of the constructor
* to be invoked.
* @param loaderName The object name of the class loader to be used.
*
* @return The newly instantiated object.
*
* @exception ReflectionException Wraps the
* {@link java.lang.ClassNotFoundException}
or the
* {@link java.lang.Exception}
that
* occurred when trying to invoke the object's constructor.
* @exception MBeanException The constructor of the object has thrown
* an exception.
* @exception InstanceNotFoundException The specified class loader
* is not registered in the MBean server.
* @exception RuntimeOperationsException Wraps an
* {@link java.lang.IllegalArgumentException}
:
* The className passed in parameter is null.
*
*/
public Object instantiate(String className, ObjectName loaderName,
Object params[], String signature[])
throws ReflectionException, MBeanException,
InstanceNotFoundException {
/* Permission check */
checkMBeanPermission(mbeanServerName, className, null,
null, "instantiate");
ClassLoader myLoader = outerShell.getClass().getClassLoader();
return instantiator.instantiate(className,loaderName,params,signature,
myLoader);
}
/**
* Returns true if the MBean specified is an instance of the specified
* class, false otherwise.
*
* @param name The ObjectName
of the MBean.
* @param className The name of the class.
*
* @return true if the MBean specified is an instance of the specified
* class, false otherwise.
*
* @exception InstanceNotFoundException The MBean specified is not
* registered in the MBean server.
*/
public boolean isInstanceOf(ObjectName name, String className)
throws InstanceNotFoundException {
return mbsInterceptor.isInstanceOf(cloneObjectName(name), className);
}
/**
* De-serializes a byte array in the context of the class loader
* of an MBean.
*
* @param name The name of the MBean whose class loader should
* be used for the de-serialization.
* @param data The byte array to be de-sererialized.
*
* @return The de-serialized object stream.
*
* @exception InstanceNotFoundException The MBean specified is not
* found.
* @exception OperationsException Any of the usual Input/Output
* related exceptions.
*
*/
@Deprecated
public ObjectInputStream deserialize(ObjectName name, byte[] data)
throws InstanceNotFoundException, OperationsException {
/* Permission check */
// This call requires MBeanPermission 'getClassLoaderFor'
final ClassLoader loader = getClassLoaderFor(name);
return instantiator.deserialize(loader, data);
}
/**
* De-serializes a byte array in the context of a given MBean class loader.
* The class loader is the one that loaded the class with name "className".
*
* @param className The name of the class whose class loader should be
* used for the de-serialization.
* @param data The byte array to be de-sererialized.
*
* @return The de-serialized object stream.
*
* @exception OperationsException Any of the usual Input/Output
* related exceptions.
* @exception ReflectionException The specified class could not be
* loaded by the default loader repository
*
*/
@Deprecated
public ObjectInputStream deserialize(String className, byte[] data)
throws OperationsException, ReflectionException {
if (className == null) {
throw new RuntimeOperationsException(
new IllegalArgumentException(),
"Null className passed in parameter");
}
/* Permission check */
// This call requires MBeanPermission 'getClassLoaderRepository'
final ClassLoaderRepository clr = getClassLoaderRepository();
Class theClass;
try {
if (clr == null) throw new ClassNotFoundException(className);
theClass = clr.loadClass(className);
} catch (ClassNotFoundException e) {
throw new ReflectionException(e,
"The given class could not be " +
"loaded by the default loader " +
"repository");
}
return instantiator.deserialize(theClass.getClassLoader(), data);
}
/**
* De-serializes a byte array in the context of a given MBean class loader.
* The class loader is the one that loaded the class with name "className".
* The name of the class loader to be used for loading the specified
* class is specified.
* If null, the MBean Server's class loader will be used.
*
* @param className The name of the class whose class loader should be
* used for the de-serialization.
* @param data The byte array to be de-sererialized.
* @param loaderName The name of the class loader to be used for
* loading the specified class.
* If null, the MBean Server's class loader will be used.
*
* @return The de-serialized object stream.
*
* @exception InstanceNotFoundException The specified class loader
* MBean is not found.
* @exception OperationsException Any of the usual Input/Output
* related exceptions.
* @exception ReflectionException The specified class could not
* be loaded by the specified class loader.
*
*/
@Deprecated
public ObjectInputStream deserialize(String className,
ObjectName loaderName,
byte[] data) throws
InstanceNotFoundException, OperationsException, ReflectionException {
// Clone ObjectName
//
loaderName = cloneObjectName(loaderName);
/* Permission check */
// Make this call just to force the 'getClassLoader'
// permission check
try {
getClassLoader(loaderName);
} catch (SecurityException e) {
throw e;
} catch (Exception e) {
}
ClassLoader myLoader = outerShell.getClass().getClassLoader();
return instantiator.deserialize(className, loaderName, data, myLoader);
}
/**
* Initializes this MBeanServer, registering the MBeanServerDelegate.
* This method must be called once, before using the MBeanServer. **/ private void initialize() { if (instantiator == null) throw new IllegalStateException("instantiator must not be null."); // Registers the MBeanServer identification MBean try { AccessController.doPrivileged(new PrivilegedExceptionAction