Interface MBeanServer
- All Superinterfaces:
MBeanServerConnection
- All Known Subinterfaces:
MBeanServerForwarder
This is the interface 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.
User code does not usually implement this interface. Instead,
an object that implements this interface is obtained with one of
the methods in the MBeanServerFactory
class.
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 a MBeanServerNotification
Notification is emitted. To register an
object as listener to MBeanServerNotifications you should call the
MBean server method addNotificationListener
with ObjectName
the
ObjectName
of the MBeanServerDelegate
. This
ObjectName
is:
JMImplementation:type=MBeanServerDelegate
.
Methods of MBeanServer
and its subclasses may throw
SecurityException
if the implementation doesn't authorize
access to the underlying resource.
- Since:
- 1.5
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addNotificationListener
(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) Adds a listener to a registered MBean.void
addNotificationListener
(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) Adds a listener to a registered MBean.createMBean
(String className, ObjectName name) Instantiates and registers an MBean in the MBean server.createMBean
(String className, ObjectName name, Object[] params, String[] signature) Instantiates and registers an MBean in the MBean server.createMBean
(String className, ObjectName name, ObjectName loaderName) Instantiates and registers an MBean in the MBean server.createMBean
(String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature) Instantiates and registers an MBean in the MBean server.default ObjectInputStream
deserialize
(String className, byte[] data) Deprecated.default ObjectInputStream
deserialize
(String className, ObjectName loaderName, byte[] data) Deprecated.UsegetClassLoader
to obtain the class loader for deserialization.default ObjectInputStream
deserialize
(ObjectName name, byte[] data) Deprecated.UsegetClassLoaderFor
to obtain the appropriate class loader for deserialization.getAttribute
(ObjectName name, String attribute) Gets the value of a specific attribute of a named MBean.getAttributes
(ObjectName name, String[] attributes) Retrieves the values of several attributes of a named MBean.getClassLoader
(ObjectName loaderName) Return the namedClassLoader
.getClassLoaderFor
(ObjectName mbeanName) Return theClassLoader
that was used for loading the class of the named MBean.Return the ClassLoaderRepository for this MBeanServer.Returns the default domain used for naming the MBean.String[]
Returns the list of domains in which any MBean is currently registered.Returns the number of MBeans registered in the MBean server.getMBeanInfo
(ObjectName name) This method discovers the attributes and operations that an MBean exposes for management.getObjectInstance
(ObjectName name) Gets theObjectInstance
for a given MBean registered with the MBean server.instantiate
(String className) Instantiates an object using the list of all class loaders registered in the MBean server'sClass Loader Repository
.instantiate
(String className, Object[] params, String[] signature) Instantiates an object using the list of all class loaders registered in the MBean serverClass Loader Repository
.instantiate
(String className, ObjectName loaderName) Instantiates an object using the class Loader specified by itsObjectName
.instantiate
(String className, ObjectName loaderName, Object[] params, String[] signature) Instantiates an object.invoke
(ObjectName name, String operationName, Object[] params, String[] signature) Invokes an operation on an MBean.boolean
isInstanceOf
(ObjectName name, String className) Returns true if the MBean specified is an instance of the specified class, false otherwise.boolean
isRegistered
(ObjectName name) Checks whether an MBean, identified by its object name, is already registered with the MBean server.queryMBeans
(ObjectName name, QueryExp query) Gets MBeans controlled by the MBean server.queryNames
(ObjectName name, QueryExp query) Gets the names of MBeans controlled by the MBean server.registerMBean
(Object object, ObjectName name) Registers a pre-existing object as an MBean with the MBean server.void
removeNotificationListener
(ObjectName name, NotificationListener listener) Removes a listener from a registered MBean.void
removeNotificationListener
(ObjectName name, NotificationListener listener, NotificationFilter filter, Object handback) Removes a listener from a registered MBean.void
removeNotificationListener
(ObjectName name, ObjectName listener) Removes a listener from a registered MBean.void
removeNotificationListener
(ObjectName name, ObjectName listener, NotificationFilter filter, Object handback) Removes a listener from a registered MBean.void
setAttribute
(ObjectName name, Attribute attribute) Sets the value of a specific attribute of a named MBean.setAttributes
(ObjectName name, AttributeList attributes) Sets the values of several attributes of a named MBean.void
unregisterMBean
(ObjectName name) Unregisters an MBean from the MBean server.
-
Method Details
-
createMBean
ObjectInstance createMBean(String className, ObjectName name) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException Instantiates and registers an MBean in the MBean server. The MBean server will use its
Default Loader Repository
to load the class of the MBean. An object name is associated with the MBean. If the object name given is null, the MBean must provide its own name by implementing theMBeanRegistration
interface and returning the name from thepreRegister
method.This method is equivalent to
createMBean(className, name, (Object[]) null, (String[]) null)
.If this method successfully creates an MBean, a notification is sent as described above.
- Specified by:
createMBean
in interfaceMBeanServerConnection
- Parameters:
className
- The class name of the MBean to be instantiated.name
- The object name of the MBean. May be null.- Returns:
- An
ObjectInstance
, containing theObjectName
and the Java class name of the newly instantiated MBean. If the containedObjectName
isn
, the contained Java class name is
.getMBeanInfo(n)
.getClassName() - Throws:
RuntimeOperationsException
- Wraps ajava.lang.IllegalArgumentException
: The className passed in parameter is null, theObjectName
passed in parameter contains a pattern or noObjectName
is specified for the MBean.RuntimeMBeanException
- If the MBean's constructor or itspreRegister
orpostRegister
method threw aRuntimeException
. If thepostRegister
(MBeanRegistration
interface) method of the MBean throws aRuntimeException
, thecreateMBean
method will throw aRuntimeMBeanException
, although the MBean creation and registration succeeded. In such a case, the MBean will be actually registered even though thecreateMBean
method threw an exception. Note thatRuntimeMBeanException
can also be thrown bypreRegister
, in which case the MBean will not be registered.RuntimeErrorException
- If thepostRegister
(MBeanRegistration
interface) method of the MBean throws anError
, thecreateMBean
method will throw aRuntimeErrorException
, although the MBean creation and registration succeeded. In such a case, the MBean will be actually registered even though thecreateMBean
method threw an exception. Note thatRuntimeErrorException
can also be thrown bypreRegister
, in which case the MBean will not be registered.ReflectionException
- Wraps ajava.lang.ClassNotFoundException
or ajava.lang.Exception
that occurred when trying to invoke the MBean's constructor.InstanceAlreadyExistsException
- The MBean is already under the control of the MBean server.MBeanRegistrationException
- ThepreRegister
(MBeanRegistration
interface) method of the MBean has thrown an exception. The MBean will not be registered.MBeanException
- The constructor of the MBean has thrown an exceptionNotCompliantMBeanException
- This class is not a JMX compliant MBean- See Also:
-
createMBean
ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException 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 with 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 must provide its own name by implementing the
MBeanRegistration
interface and returning the name from thepreRegister
method.This method is equivalent to
createMBean(className, name, loaderName, (Object[]) null, (String[]) null)
.If this method successfully creates an MBean, a notification is sent as described above.
- Specified by:
createMBean
in interfaceMBeanServerConnection
- Parameters:
className
- The class name of the MBean to be instantiated.name
- The object name of the MBean. May be null.loaderName
- The object name of the class loader to be used.- Returns:
- An
ObjectInstance
, containing theObjectName
and the Java class name of the newly instantiated MBean. If the containedObjectName
isn
, the contained Java class name is
.getMBeanInfo(n)
.getClassName() - Throws:
RuntimeOperationsException
- Wraps ajava.lang.IllegalArgumentException
: The className passed in parameter is null, theObjectName
passed in parameter contains a pattern or noObjectName
is specified for the MBean.RuntimeMBeanException
- If the MBean's constructor or itspreRegister
orpostRegister
method threw aRuntimeException
. If thepostRegister
(MBeanRegistration
interface) method of the MBean throws aRuntimeException
, thecreateMBean
method will throw aRuntimeMBeanException
, although the MBean creation and registration succeeded. In such a case, the MBean will be actually registered even though thecreateMBean
method threw an exception. Note thatRuntimeMBeanException
can also be thrown bypreRegister
, in which case the MBean will not be registered.RuntimeErrorException
- If thepostRegister
(MBeanRegistration
interface) method of the MBean throws anError
, thecreateMBean
method will throw aRuntimeErrorException
, although the MBean creation and registration succeeded. In such a case, the MBean will be actually registered even though thecreateMBean
method threw an exception. Note thatRuntimeErrorException
can also be thrown bypreRegister
, in which case the MBean will not be registered.ReflectionException
- Wraps ajava.lang.ClassNotFoundException
or ajava.lang.Exception
that occurred when trying to invoke the MBean's constructor.InstanceAlreadyExistsException
- The MBean is already under the control of the MBean server.MBeanRegistrationException
- ThepreRegister
(MBeanRegistration
interface) method of the MBean has thrown an exception. The MBean will not be registered.MBeanException
- The constructor of the MBean has thrown an exceptionNotCompliantMBeanException
- This class is not a JMX compliant MBeanInstanceNotFoundException
- The specified class loader is not registered in the MBean server.- See Also:
-
createMBean
ObjectInstance createMBean(String className, ObjectName name, Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException Instantiates and registers an MBean in the MBean server. The MBean server will use itsDefault Loader Repository
to load the class of the MBean. An object name is associated with the MBean. If the object name given is null, the MBean must provide its own name by implementing theMBeanRegistration
interface and returning the name from thepreRegister
method.If this method successfully creates an MBean, a notification is sent as described above.
- Specified by:
createMBean
in interfaceMBeanServerConnection
- Parameters:
className
- The class name of the MBean to be instantiated.name
- The object name of the MBean. May be null.params
- An array containing the parameters of the constructor to be invoked.signature
- An array containing the signature of the constructor to be invoked.- Returns:
- An
ObjectInstance
, containing theObjectName
and the Java class name of the newly instantiated MBean. If the containedObjectName
isn
, the contained Java class name is
.getMBeanInfo(n)
.getClassName() - Throws:
RuntimeOperationsException
- Wraps ajava.lang.IllegalArgumentException
: The className passed in parameter is null, theObjectName
passed in parameter contains a pattern or noObjectName
is specified for the MBean.RuntimeMBeanException
- If the MBean's constructor or itspreRegister
orpostRegister
method threw aRuntimeException
. If thepostRegister
(MBeanRegistration
interface) method of the MBean throws aRuntimeException
, thecreateMBean
method will throw aRuntimeMBeanException
, although the MBean creation and registration succeeded. In such a case, the MBean will be actually registered even though thecreateMBean
method threw an exception. Note thatRuntimeMBeanException
can also be thrown bypreRegister
, in which case the MBean will not be registered.RuntimeErrorException
- If thepostRegister
(MBeanRegistration
interface) method of the MBean throws anError
, thecreateMBean
method will throw aRuntimeErrorException
, although the MBean creation and registration succeeded. In such a case, the MBean will be actually registered even though thecreateMBean
method threw an exception. Note thatRuntimeErrorException
can also be thrown bypreRegister
, in which case the MBean will not be registered.ReflectionException
- Wraps ajava.lang.ClassNotFoundException
or ajava.lang.Exception
that occurred when trying to invoke the MBean's constructor.InstanceAlreadyExistsException
- The MBean is already under the control of the MBean server.MBeanRegistrationException
- ThepreRegister
(MBeanRegistration
interface) method of the MBean has thrown an exception. The MBean will not be registered.MBeanException
- The constructor of the MBean has thrown an exceptionNotCompliantMBeanException
- This class is not a JMX compliant MBean- See Also:
-
createMBean
ObjectInstance createMBean(String className, ObjectName name, ObjectName loaderName, Object[] params, String[] signature) throws ReflectionException, InstanceAlreadyExistsException, MBeanRegistrationException, MBeanException, NotCompliantMBeanException, InstanceNotFoundException 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 with 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 must provide its own name by implementing the
MBeanRegistration
interface and returning the name from thepreRegister
method.If this method successfully creates an MBean, a notification is sent as described above.
- Specified by:
createMBean
in interfaceMBeanServerConnection
- Parameters:
className
- The class name of the MBean to be instantiated.name
- The object name of the MBean. May be null.loaderName
- The object name of the class loader to be used.params
- An array containing the parameters of the constructor to be invoked.signature
- An array containing the signature of the constructor to be invoked.- Returns:
- An
ObjectInstance
, containing theObjectName
and the Java class name of the newly instantiated MBean. If the containedObjectName
isn
, the contained Java class name is
.getMBeanInfo(n)
.getClassName() - Throws:
RuntimeOperationsException
- Wraps ajava.lang.IllegalArgumentException
: The className passed in parameter is null, theObjectName
passed in parameter contains a pattern or noObjectName
is specified for the MBean.RuntimeMBeanException
- The MBean's constructor or itspreRegister
orpostRegister
method threw aRuntimeException
. If thepostRegister
(MBeanRegistration
interface) method of the MBean throws aRuntimeException
, thecreateMBean
method will throw aRuntimeMBeanException
, although the MBean creation and registration succeeded. In such a case, the MBean will be actually registered even though thecreateMBean
method threw an exception. Note thatRuntimeMBeanException
can also be thrown bypreRegister
, in which case the MBean will not be registered.RuntimeErrorException
- If thepostRegister
method (MBeanRegistration
interface) method of the MBean throws anError
, thecreateMBean
method will throw aRuntimeErrorException
, although the MBean creation and registration succeeded. In such a case, the MBean will be actually registered even though thecreateMBean
method threw an exception. Note thatRuntimeErrorException
can also be thrown bypreRegister
, in which case the MBean will not be registered.ReflectionException
- Wraps ajava.lang.ClassNotFoundException
or ajava.lang.Exception
that occurred when trying to invoke the MBean's constructor.InstanceAlreadyExistsException
- The MBean is already under the control of the MBean server.MBeanRegistrationException
- ThepreRegister
(MBeanRegistration
interface) method of the MBean has thrown an exception. The MBean will not be registered.MBeanException
- The constructor of the MBean has thrown an exceptionNotCompliantMBeanException
- This class is not a JMX compliant MBeanInstanceNotFoundException
- The specified class loader is not registered in the MBean server.- See Also:
-
registerMBean
ObjectInstance registerMBean(Object object, ObjectName name) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException Registers a pre-existing object as an MBean with the MBean server. If the object name given is null, the MBean must provide its own name by implementing the
MBeanRegistration
interface and returning the name from thepreRegister
method.If this method successfully registers an MBean, a notification is sent as described above.
- Parameters:
object
- The MBean to be registered as an MBean.name
- The object name of the MBean. May be null.- Returns:
- An
ObjectInstance
, containing theObjectName
and the Java class name of the newly registered MBean. If the containedObjectName
isn
, the contained Java class name is
.getMBeanInfo(n)
.getClassName() - Throws:
InstanceAlreadyExistsException
- The MBean is already under the control of the MBean server.MBeanRegistrationException
- ThepreRegister
(MBeanRegistration
interface) method of the MBean has thrown an exception. The MBean will not be registered.RuntimeMBeanException
- If thepostRegister
(MBeanRegistration
interface) method of the MBean throws aRuntimeException
, theregisterMBean
method will throw aRuntimeMBeanException
, although the MBean registration succeeded. In such a case, the MBean will be actually registered even though theregisterMBean
method threw an exception. Note thatRuntimeMBeanException
can also be thrown bypreRegister
, in which case the MBean will not be registered.RuntimeErrorException
- If thepostRegister
(MBeanRegistration
interface) method of the MBean throws anError
, theregisterMBean
method will throw aRuntimeErrorException
, although the MBean registration succeeded. In such a case, the MBean will be actually registered even though theregisterMBean
method threw an exception. Note thatRuntimeErrorException
can also be thrown bypreRegister
, in which case the MBean will not be registered.NotCompliantMBeanException
- This object is not a JMX compliant MBeanRuntimeOperationsException
- Wraps ajava.lang.IllegalArgumentException
: The object passed in parameter is null or no object name is specified.- See Also:
-
unregisterMBean
Unregisters 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.If this method successfully unregisters an MBean, a notification is sent as described above.
- Specified by:
unregisterMBean
in interfaceMBeanServerConnection
- Parameters:
name
- The object name of the MBean to be unregistered.- Throws:
RuntimeOperationsException
- Wraps ajava.lang.IllegalArgumentException
: The object name in parameter is null or the MBean you are when trying to unregister is theMBeanServerDelegate
MBean.RuntimeMBeanException
- If thepostDeregister
(MBeanRegistration
interface) method of the MBean throws aRuntimeException
, theunregisterMBean
method will throw aRuntimeMBeanException
, although the MBean unregistration succeeded. In such a case, the MBean will be actually unregistered even though theunregisterMBean
method threw an exception. Note thatRuntimeMBeanException
can also be thrown bypreDeregister
, in which case the MBean will remain registered.RuntimeErrorException
- If thepostDeregister
(MBeanRegistration
interface) method of the MBean throws anError
, theunregisterMBean
method will throw aRuntimeErrorException
, although the MBean unregistration succeeded. In such a case, the MBean will be actually unregistered even though theunregisterMBean
method threw an exception. Note thatRuntimeMBeanException
can also be thrown bypreDeregister
, in which case the MBean will remain registered.InstanceNotFoundException
- The MBean specified is not registered in the MBean server.MBeanRegistrationException
- The preDeregister (MBeanRegistration
interface) method of the MBean has thrown an exception.- See Also:
-
getObjectInstance
Description copied from interface:MBeanServerConnection
Gets theObjectInstance
for a given MBean registered with the MBean server.- Specified by:
getObjectInstance
in interfaceMBeanServerConnection
- Parameters:
name
- The object name of the MBean.- Returns:
- The
ObjectInstance
associated with the MBean specified by name. The containedObjectName
isname
and the contained class name is
.getMBeanInfo(name)
.getClassName() - Throws:
InstanceNotFoundException
- The MBean specified is not registered in the MBean server.
-
queryMBeans
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 theObjectName
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 ofObjectInstance
objects (containing theObjectName
and the Java Class name) for the selected MBeans.- Specified by:
queryMBeans
in interfaceMBeanServerConnection
- Parameters:
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.query
- The query expression to be applied for selecting MBeans. If null no query expression will be applied for selecting MBeans.- Returns:
- A set containing the
ObjectInstance
objects for the selected MBeans. If no MBean satisfies the query an empty list is returned.
-
queryNames
-
getClassLoaderRepository()
to obtain the class loader repository and use it to deserialize.