Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## javax.management
Class StandardMBean

    java.lang.Object
      |
      +--javax.management.StandardMBean

All Implemented Interfaces:
  DynamicMBean, MBeanRegistration

public class StandardMBean
extends java.lang.Object
implements DynamicMBean, MBeanRegistration

An MBean whose management interface is determined by reflection on a Java interface.

This class brings more flexibility to the notion of Management Interface in the use of Standard MBeans. Straightforward use of the patterns for Standard MBeans described in the JMX Specification means that there is a fixed relationship between the implementation class of an MBean and its management interface (i.e., if the implementation class is Thing, the management interface must be ThingMBean). This class makes it possible to keep the convenience of specifying the management interface with a Java interface, without requiring that there be any naming relationship between the implementation and interface classes.

By making a DynamicMBean out of an MBean, this class makes it possible to select any interface implemented by the MBean as its management interface, provided that it complies with JMX patterns (i.e., attributes defined by getter/setter etc...).

This class also provides hooks that make it possible to supply custom descriptions and names for the `MBeanInfo` returned by the DynamicMBean interface.

Using this class, an MBean can be created with any implementation class name Impl and with a management interface defined (as for current Standard MBeans) by any interface Intf, in one of two general ways:

- Using the public constructor `StandardMBean(impl,interface)`:

           MBeanServer mbs;
           ...
           Impl impl = new Impl(...);
           StandardMBean mbean = new StandardMBean(impl, Intf.class);
           mbs.registerMBean(mbean, objectName);

- Subclassing StandardMBean:

           public class Impl extends StandardMBean implements Intf {
              public Impl() {
                super(Intf.class);
             }
             // implement methods of Intf
           }

           [...]

           MBeanServer mbs;
           ....
           Impl impl = new Impl();
           mbs.registerMBean(impl, objectName);

In either case, the class Impl must implement the interface Intf.

Standard MBeans based on the naming relationship between implementation and interface classes are of course still available.

Since:
  JMX 1.2
Author:
  Young Yang

Constructor Summary
`protected` | `StandardMBean(java.lang.Class mbeanInterface)` Make a DynamicMBean out of this, using the specified mbeanInterface class.
`` | `StandardMBean(java.lang.Object implementation, java.lang.Class mbeanInterface)` Make a DynamicMBean out of the object implementation, using the specified mbeanInterface class.

Method Summary
`protected void` | `cacheMBeanInfo(MBeanInfo info)` Customization hook: cache the MBeanInfo built for this object.
`java.lang.Object` | `getAttribute(java.lang.String attribute)` Obtains the value of a specific attribute of the Dynamic MBean.
`AttributeList` | `getAttributes(java.lang.String[] attributes)` Enables the values of several attributes of the Dynamic MBean.
`protected MBeanInfo` | `getCachedMBeanInfo()` Customization hook: Return the MBeanInfo cached for this object.
`protected java.lang.String` | `getClassName(MBeanInfo info)` Customization hook: Get the className that will be used in the MBeanInfo returned by this MBean.
`protected MBeanConstructorInfo[]` | `getConstructors(MBeanConstructorInfo[] ctors, java.lang.Object impl)` Customization hook: Get the MBeanConstructorInfo[] that will be used in the MBeanInfo returned by this MBean.
`protected java.lang.String` | `getDescription(MBeanAttributeInfo info)` Customization hook: Get the description that will be used in the MBeanAttributeInfo returned by this MBean.
`protected java.lang.String` | `getDescription(MBeanConstructorInfo info)` Customization hook: Get the description that will be used in the MBeanConstructorInfo returned by this MBean.
`protected java.lang.String` | `getDescription(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence)` Customization hook: Get the description that will be used for the sequence MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
`protected java.lang.String` | `getDescription(MBeanFeatureInfo info)` Customization hook: Get the description that will be used in the MBeanFeatureInfo returned by this MBean.
`protected java.lang.String` | `getDescription(MBeanInfo info)` Customization hook: Get the description that will be used in the MBeanInfo returned by this MBean.
`protected java.lang.String` | `getDescription(MBeanOperationInfo info)` Customization hook: Get the description that will be used in the MBeanOperationInfo returned by this MBean.
`protected java.lang.String` | `getDescription(MBeanOperationInfo op, MBeanParameterInfo param, int sequence)` Customization hook: Get the description that will be used for the sequence MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
`protected int` | `getImpact(MBeanOperationInfo info)` Customization hook: Get the impact flag of the operation that will be used in the MBeanOperationInfo returned by this MBean.
`java.lang.Object` | `getImplementation()` Get the implementation of this MBean.
`java.lang.Class` | `getImplementationClass()` Get the class of the implementation of this MBean.
`MBeanInfo` | `getMBeanInfo()` Provides the exposed attributes and actions of the Dynamic MBean using an MBeanInfo object.
`java.lang.Class` | `getMBeanInterface()` Get the Management Interface of this MBean.
`MBeanMetaData` | `getMetaData()`
`protected MBeanNotificationInfo[]` | `getNotifications(MBeanInfo info)` Customization hook: Get the MBeanNotificationInfo[] that will be used in the MBeanInfo returned by this MBean.
`protected java.lang.String` | `getParameterName(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence)` Customization hook: Get the name that will be used for the sequence MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
`protected java.lang.String` | `getParameterName(MBeanOperationInfo op, MBeanParameterInfo param, int sequence)` Customization hook: Get the name that will be used for the sequence MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
`java.lang.Object` | `invoke(java.lang.String actionName, java.lang.Object[] params, java.lang.String[] signature)` Allows an action to be invoked on the Dynamic MBean.
`void` | `postDeregister()` Allows the MBean to perform any operations needed after having been de-registered in the MBean server.
`void` | `postRegister(java.lang.Boolean registrationDone)` Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.
`void` | `preDeregister()` Allows the MBean to perform any operations it needs before being de-registered by the MBean server.
`ObjectName` | `preRegister(MBeanServer server, ObjectName name)` Allows the MBean to perform any operations it needs before being registered in the MBean server.
`void` | `setAttribute(Attribute attribute)` Sets the value of a specific attribute of the Dynamic MBean
`AttributeList` | `setAttributes(AttributeList attributes)` Sets the values of several attributes of the Dynamic MBean
`void` | `setImplementation(java.lang.Object implementation)` Replace the implementation object wrapped in this object.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Constructor Detail

### StandardMBean

    public StandardMBean(java.lang.Object implementation,
                         java.lang.Class mbeanInterface)
                  throws NotCompliantMBeanException

  Make a DynamicMBean out of the object implementation, using the specified mbeanInterface class.

Parameters:
  `implementation` - The implementation of this MBean.
  `mbeanInterface` - The Management Interface exported by this MBean's implementation. If `null`, then this object will use standard JMX design pattern to determine the management interface associated with the given implementation.
Throws:
  `java.lang.IllegalArgumentException` - if the given implementation is null.
  `NotCompliantMBeanException` - if the mbeanInterface does not follow JMX design patterns for Management Interfaces, or if the given implementation does not implement the specified interface.

### StandardMBean

    protected StandardMBean(java.lang.Class mbeanInterface)
                     throws NotCompliantMBeanException

  Make a DynamicMBean out of this, using the specified mbeanInterface class.

  Call `this(this,mbeanInterface)`. This constructor is reserved to subclasses.

Parameters:
  `mbeanInterface` - The Management Interface exported by this MBean.
Throws:
  `NotCompliantMBeanException` - if the mbeanInterface does not follow JMX design patterns for Management Interfaces, or if this does not implement the specified interface.

Method Detail

### setImplementation

    public void setImplementation(java.lang.Object implementation)
                           throws NotCompliantMBeanException

  Replace the implementation object wrapped in this object.

  Parameters:
    `implementation` - The new implementation of this MBean. The `implementation` object must implement the MBean interface that was supplied when this `StandardMBean` was constructed.
  Throws:
    `java.lang.IllegalArgumentException` - if the given implementation is null.
    `NotCompliantMBeanException` - if the given implementation does not implement the MBean interface that was supplied at construction.
  See Also:
    `getImplementation()`

### getMBeanInterface

    public final java.lang.Class getMBeanInterface()

  Get the Management Interface of this MBean.

  Returns:
    The management interface of this MBean.

### getImplementationClass

    public java.lang.Class getImplementationClass()

  Get the class of the implementation of this MBean.

  Returns:
    The class of the implementation of this MBean.

### getImplementation

    public java.lang.Object getImplementation()

  Get the implementation of this MBean.

  Returns:
    The implementation of this MBean.
  See Also:
    `setImplementation(java.lang.Object)`

### getAttribute

    public java.lang.Object getAttribute(java.lang.String attribute)
                                  throws AttributeNotFoundException,
                                         MBeanException,
                                         ReflectionException

  Description copied from interface: `DynamicMBean`
  Obtains the value of a specific attribute of the Dynamic MBean.

  Specified by:
    `getAttribute` in interface `DynamicMBean`
  Parameters:
    `attribute` - The name of the attribute to be retrieved
  Returns:
    The value of the attribute retrieved.
  Throws:
    `AttributeNotFoundException`
    `ReflectionException` - Wraps a `java.lang.Exception` thrown while trying to invoke the getter.
    `MBeanException` - Wraps a `java.lang.Exception` thrown by the MBean's getter.

### setAttribute

    public void setAttribute(Attribute attribute)
                      throws AttributeNotFoundException,
                             InvalidAttributeValueException,
                             MBeanException,
                             ReflectionException

  Description copied from interface: `DynamicMBean`
  Sets the value of a specific attribute of the Dynamic MBean

  Specified by:
    `setAttribute` in interface `DynamicMBean`
  Parameters:
    `attribute` - The identification of the attribute to be set and the value it is to be set to.
  Throws:
    `InvalidAttributeValueException`
    `ReflectionException` - Wraps a `java.lang.Exception` thrown while trying to invoke the MBean's setter.
    `AttributeNotFoundException`
    `MBeanException` - Wraps a `java.lang.Exception` thrown by the MBean's setter.

### getAttributes

    public AttributeList getAttributes(java.lang.String[] attributes)

  Description copied from interface: `DynamicMBean`
  Enables the values of several attributes of the Dynamic MBean.

  Specified by:
    `getAttributes` in interface `DynamicMBean`
  Parameters:
    `attributes` - A list of the attributes to be retrieved.
  Returns:
    The list of attributes retrieved.

### setAttributes

    public AttributeList setAttributes(AttributeList attributes)

  Description copied from interface: `DynamicMBean`
  Sets the values of several attributes of the Dynamic MBean

  Specified by:
    `setAttributes` in interface `DynamicMBean`
  Parameters:
    `attributes` - A list of attributes: The identification of the attributes to be set and the values they are to be set to.
  Returns:
    The list of attributes that were set, with their new values.

### invoke

    public java.lang.Object invoke(java.lang.String actionName,
                                   java.lang.Object[] params,
                                   java.lang.String[] signature)
                            throws MBeanException,
                                   ReflectionException

  Description copied from interface: `DynamicMBean`
  Allows an action to be invoked on the Dynamic MBean.

  Specified by:
    `invoke` in interface `DynamicMBean`
  Parameters:
    `actionName` - The name of the action to be invoked.
    `params` - An array containing the parameters to be set when the action is invoked.
    `signature` - An array containing the signature of the action. The class objects will be loaded through the same class loader as the one used for loading the MBean on which the action is invoked.
  Returns:
    The object returned by the action, which represents the result of invoking the action on the MBean specified.
  Throws:
    `ReflectionException` - Wraps a `java.lang.Exception` thrown while trying to invoke the method
    `MBeanException` - Wraps a `java.lang.Exception` thrown by the MBean's invoked method.

### getMBeanInfo

    public MBeanInfo getMBeanInfo()

  Description copied from interface: `DynamicMBean`
  Provides the exposed attributes and actions of the Dynamic MBean using an MBeanInfo object.

  Specified by:
    `getMBeanInfo` in interface `DynamicMBean`
  Returns:
    An instance of `MBeanInfo` allowing all attributes and actions exposed by this Dynamic MBean to be retrieved.

### getCachedMBeanInfo

    protected MBeanInfo getCachedMBeanInfo()

  Customization hook: Return the MBeanInfo cached for this object.

  Subclasses may redefine this method in order to implement their own caching policy. The default implementation stores one `MBeanInfo` object per instance.

  Returns:
    The cached MBeanInfo, or null if no MBeanInfo is cached.
  See Also:
    `cacheMBeanInfo(MBeanInfo)`

### cacheMBeanInfo

    protected void cacheMBeanInfo(MBeanInfo info)

  Customization hook: cache the MBeanInfo built for this object.

  Subclasses may redefine this method in order to implement their own caching policy. The default implementation stores `info` in this instance. A subclass can define other policies, such as not saving `info` (so it is reconstructed every time `getMBeanInfo()` is called) or sharing a unique `MBeanInfo` object when several `StandardMBean` instances have equal `MBeanInfo` values.

  Parameters:
    `info` - the new `MBeanInfo` to cache. Any previously cached value is discarded. This parameter may be null, in which case there is no new cached value.

### getClassName

    protected java.lang.String getClassName(MBeanInfo info)

  Customization hook: Get the className that will be used in the MBeanInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom class name. The default implementation returns `info.getClassName()`.

  Parameters:
    `info` - The default MBeanInfo derived by reflection.
  Returns:
    the class name for the new MBeanInfo.

### getDescription

    protected java.lang.String getDescription(MBeanInfo info)

  Customization hook: Get the description that will be used in the MBeanInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom MBean description. The default implementation returns `info.getDescription()`.

  Parameters:
    `info` - The default MBeanInfo derived by reflection.
  Returns:
    the description for the new MBeanInfo.

### getDescription

    protected java.lang.String getDescription(MBeanFeatureInfo info)

  Customization hook: Get the description that will be used in the MBeanFeatureInfo returned by this MBean.

  Subclasses may redefine this method in order to supply their custom description. The default implementation returns `info.getDescription()`.

  This method is called by `getDescription(MBeanAttributeInfo)`, `getDescription(MBeanOperationInfo)`, `getDescription(MBeanConstructorInfo)`.

  Parameters:
    `info` - The default MBeanFeatureInfo derived by reflection.
  Returns:
    the description for the given MBeanFeatureInfo.

### getDescription

    protected java.lang.String getDescription(MBeanAttributeInfo info)

  Customization hook: Get the description that will be used in the MBeanAttributeInfo returned by this MBean.

  Subclasses may redefine this method in order to supply their custom description. The default implementation returns `getDescription((MBeanFeatureInfo) info)`.

  Parameters:
    `info` - The default MBeanAttributeInfo derived by reflection.
  Returns:
    the description for the given MBeanAttributeInfo.

### getDescription

    protected java.lang.String getDescription(MBeanConstructorInfo info)

  Customization hook: Get the description that will be used in the MBeanConstructorInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom description. The default implementation returns `getDescription((MBeanFeatureInfo) info)`.

  Parameters:
    `info` - The default MBeanConstructorInfo derived by reflection.
  Returns:
    the description for the given MBeanConstructorInfo.

### getDescription

    protected java.lang.String getDescription(MBeanConstructorInfo ctor,
                                              MBeanParameterInfo param,
                                              int sequence)

  Customization hook: Get the description that will be used for the sequence MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom description. The default implementation returns `param.getDescription()`.

  Parameters:
    `ctor` - The default MBeanConstructorInfo derived by reflection.
    `param` - The default MBeanParameterInfo derived by reflection.
    `sequence` - The sequence number of the parameter considered ("0" for the first parameter, "1" for the second parameter, etc...).
  Returns:
    the description for the given MBeanParameterInfo.

### getParameterName

    protected java.lang.String getParameterName(MBeanConstructorInfo ctor,
                                                MBeanParameterInfo param,
                                                int sequence)

  Customization hook: Get the name that will be used for the sequence MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom parameter name. The default implementation returns `param.getName()`.

  Parameters:
    `ctor` - The default MBeanConstructorInfo derived by reflection.
    `param` - The default MBeanParameterInfo derived by reflection.
    `sequence` - The sequence number of the parameter considered ("0" for the first parameter, "1" for the second parameter, etc...).
  Returns:
    the name for the given MBeanParameterInfo.

### getDescription

    protected java.lang.String getDescription(MBeanOperationInfo info)

  Customization hook: Get the description that will be used in the MBeanOperationInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom description. The default implementation returns `getDescription((MBeanFeatureInfo) info)`.

  Parameters:
    `info` - The default MBeanOperationInfo derived by reflection.
  Returns:
    the description for the given MBeanOperationInfo.

### getImpact

    protected int getImpact(MBeanOperationInfo info)

  Customization hook: Get the impact flag of the operation that will be used in the MBeanOperationInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom impact flag. The default implementation returns `info.getImpact()`.

  Parameters:
    `info` - The default MBeanOperationInfo derived by reflection.
  Returns:
    the impact flag for the given MBeanOperationInfo.

### getParameterName

    protected java.lang.String getParameterName(MBeanOperationInfo op,
                                                MBeanParameterInfo param,
                                                int sequence)

  Customization hook: Get the name that will be used for the sequence MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom parameter name. The default implementation returns `param.getName()`.

  Parameters:
    `op` - The default MBeanOperationInfo derived by reflection.
    `param` - The default MBeanParameterInfo derived by reflection.
    `sequence` - The sequence number of the parameter considered ("0" for the first parameter, "1" for the second parameter, etc...).
  Returns:
    the name to use for the given MBeanParameterInfo.

### getDescription

    protected java.lang.String getDescription(MBeanOperationInfo op,
                                              MBeanParameterInfo param,
                                              int sequence)

  Customization hook: Get the description that will be used for the sequence MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom description. The default implementation returns `param.getDescription()`.

  Parameters:
    `op` - The default MBeanOperationInfo derived by reflection.
    `param` - The default MBeanParameterInfo derived by reflection.
    `sequence` - The sequence number of the parameter considered ("0" for the first parameter, "1" for the second parameter, etc...).
  Returns:
    the description for the given MBeanParameterInfo.

### getConstructors

    protected MBeanConstructorInfo[] getConstructors(MBeanConstructorInfo[] ctors,
                                                     java.lang.Object impl)

  Customization hook: Get the MBeanConstructorInfo[] that will be used in the MBeanInfo returned by this MBean.
  By default, this method returns `null` if the wrapped implementation is not this. Indeed, if the wrapped implementation is not this object itself, it will not be possible to recreate a wrapped implementation by calling the implementation constructors through `MBeanServer.createMBean(...)`.
  Otherwise, if the wrapped implementation is this, ctors is returned.
  Subclasses may redefine this method in order to modify this behaviour, if needed.

  Parameters:
    `ctors` - The default MBeanConstructorInfo[] derived by reflection.
    `impl` - The wrapped implementation. If `null` is passed, the wrapped implementation is ignored and ctors is returned.
  Returns:
    the MBeanConstructorInfo[] for the new MBeanInfo.

### getNotifications

    protected MBeanNotificationInfo[] getNotifications(MBeanInfo info)

  Customization hook: Get the MBeanNotificationInfo[] that will be used in the MBeanInfo returned by this MBean.
  Subclasses may redefine this method in order to supply their custom notifications.

  Parameters:
    `info` - The default MBeanInfo derived by reflection.
  Returns:
    the MBeanNotificationInfo[] for the new MBeanInfo.

### getMetaData

    public MBeanMetaData getMetaData()

### preRegister

    public ObjectName preRegister(MBeanServer server,
                                  ObjectName name)
                           throws java.lang.Exception

  Description copied from interface: `MBeanRegistration`
  Allows the MBean to perform any operations it needs before being registered in the MBean server. If the name of the MBean is not specified, the MBean can provide a name for its registration. If any exception is raised, the MBean will not be registered in the MBean server.

  Specified by:
    `preRegister` in interface `MBeanRegistration`
  Parameters:
    `server` - The MBean server in which the MBean will be registered.
    `name` - The object name of the MBean.
  Returns:
    The name of the MBean registered.
  Throws:
    `java.lang.Exception` - This exception should be caught by the MBean server and re-thrown as an `MBeanRegistrationException`.

### postRegister

    public void postRegister(java.lang.Boolean registrationDone)

  Description copied from interface: `MBeanRegistration`
  Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed.

  Specified by:
    `postRegister` in interface `MBeanRegistration`
  Parameters:
    `registrationDone` - Indicates whether or not the MBean has been successfully registered in the MBean server. The value false means that the registration phase has failed.

### preDeregister

    public void preDeregister()
                       throws java.lang.Exception

  Description copied from interface: `MBeanRegistration`
  Allows the MBean to perform any operations it needs before being de-registered by the MBean server.

  Specified by:
    `preDeregister` in interface `MBeanRegistration`
  Throws:
    `java.lang.Exception` - This exception should be caught by the MBean server and re-thrown as an `MBeanRegistrationException`.

### postDeregister

    public void postDeregister()

  Description copied from interface: `MBeanRegistration`
  Allows the MBean to perform any operations needed after having been de-registered in the MBean server.

  Specified by:
    `postDeregister` in interface `MBeanRegistration`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD