Sonic Management API

javax.management
Class StandardMBean

java.lang.Object
  extended by javax.management.StandardMBean
All Implemented Interfaces:
DynamicMBean

public class StandardMBean
extends java.lang.Object
implements DynamicMBean

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:

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

Constructor Summary
StandardMBean(java.lang.Object implementation, java.lang.Class mbeanInterface)
          Make a DynamicMBean out of the object implementation, using the specified mbeanInterface class.
 
Method Summary
 java.lang.Object getAttribute(java.lang.String attribute)
          Obtain the value of a specific attribute of the Dynamic MBean.
 AttributeList getAttributes(java.lang.String[] attributes)
          Get the values of several attributes of the Dynamic 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()
          Get the MBeanInfo for this MBean.
 java.lang.Class getMBeanInterface()
          Get the Management Interface of 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 setAttribute(Attribute attribute)
          Set 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
equals, 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.
Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String attribute)
                              throws AttributeNotFoundException,
                                     MBeanException,
                                     ReflectionException
Description copied from interface: DynamicMBean
Obtain 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
MBeanException - Wraps a java.lang.Exception thrown by the MBean's getter.
ReflectionException - Wraps a java.lang.Exception thrown while trying to invoke the getter.
See Also:
DynamicMBean.setAttribute(javax.management.Attribute)

getAttributes

public AttributeList getAttributes(java.lang.String[] attributes)
Description copied from interface: DynamicMBean
Get 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.
See Also:
DynamicMBean.setAttributes(javax.management.AttributeList)

getImplementation

public java.lang.Object getImplementation()
Get the implementation of this MBean.

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

getImplementationClass

public java.lang.Class getImplementationClass()
Get the class of the implementation of this MBean.

Returns:
The class of the implementation of this MBean.

getMBeanInfo

public MBeanInfo getMBeanInfo()
Get the MBeanInfo for this MBean.

This method implements DynamicMBean.getMBeanInfo().

This method first calls getCachedMBeanInfo() in order to retrieve the cached MBeanInfo for this MBean, if any. If the MBeanInfo returned by getCachedMBeanInfo() is not null, then it is returned.
Otherwise, this method builds a default MBeanInfo for this MBean, using the Management Interface specified for this MBean.

While building the MBeanInfo, this method calls the customization hooks that make it possible for subclasses to supply their custom descriptions, parameter names, etc...
Finally, it calls cacheMBeanInfo() in order to cache the new MBeanInfo.

Specified by:
getMBeanInfo in interface DynamicMBean
Returns:
The cached MBeanInfo for that MBean, if not null, or a newly built MBeanInfo if none was cached.

getMBeanInterface

public final java.lang.Class getMBeanInterface()
Get the Management Interface of this MBean.

Returns:
The management interface of this MBean.

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:
MBeanException - Wraps a java.lang.Exception thrown by the MBean's invoked method.
ReflectionException - Wraps a java.lang.Exception thrown while trying to invoke the method

setAttribute

public void setAttribute(Attribute attribute)
                  throws AttributeNotFoundException,
                         InvalidAttributeValueException,
                         MBeanException,
                         ReflectionException
Description copied from interface: DynamicMBean
Set 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:
AttributeNotFoundException
InvalidAttributeValueException
MBeanException - Wraps a java.lang.Exception thrown by the MBean's setter.
ReflectionException - Wraps a java.lang.Exception thrown while trying to invoke the MBean's setter.
See Also:
DynamicMBean.getAttribute(java.lang.String)

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.
See Also:
DynamicMBean.getAttributes(java.lang.String[])

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()

Sonic Management API

Copyright © 2001-2010 Progress Software Corporation. All Rights Reserved.
HTML formatted on 07-Mar-2010.