mx4j

Class AbstractDynamicMBean

public abstract class AbstractDynamicMBean extends Object implements DynamicMBean

Utility class that allow the user to easily write DynamicMBeans.
By extending this class, the developer does not have to implement the methods of the DynamicMBean interface, but has instead to provide only the metadata (by overriding few methods) and the implementation (by implementing the methods) of the MBean itself.
The methods to override that provides metadata information are usually the following: For example, the following MBean only has one manageable attribute:
 public class SimpleDynamic extends AbstractDynamicMBean
 {
    protected MBeanAttributeInfo[] createMBeanAttributeInfo()
    {
       return new MBeanAttributeInfo[]
       {
          new MBeanAttributeInfo("Name", String.class.getName(), "The name", true, true, false)
       };
    }
 

protected String getMBeanDescription() { return "A simple DynamicMBean"; }

public String getName() { ... }

public void setName(String name) { ... } }

It is responsibility of the developer to specify the metadata and implement the methods specified by the metadata, that will be invoked via reflection by the AbstractDynamicMBean class. For this reason, the methods belonging to the MBean implementation (in the case above getName() and setName(...)) must be public.

Version: $Revision: 1.7 $

Constructor Summary
protected AbstractDynamicMBean()
Only subclasses can create a new instance of an AbstractDynamicMBean.
Method Summary
protected MBeanAttributeInfo[]createMBeanAttributeInfo()
To be overridden to return metadata information about manageable attributes.
protected MBeanConstructorInfo[]createMBeanConstructorInfo()
To be overridden to return metadata information about manageable constructors.
protected MBeanInfocreateMBeanInfo()
Creates the MBeanInfo for this instance, calling in succession factory methods that the user can override.
protected MBeanNotificationInfo[]createMBeanNotificationInfo()
To be overridden to return metadata information about manageable notifications.
protected MBeanOperationInfo[]createMBeanOperationInfo()
To be overridden to return metadata information about manageable operations.
protected MethodfindMethod(Class cls, String name, Class[] params)
Returns the (public) method with the given name and signature on the given class.
ObjectgetAttribute(String attribute)
Returns the value of the manageable attribute, as specified by the DynamicMBean interface.
AttributeListgetAttributes(String[] attributes)
Returns the manageable attributes, as specified by the DynamicMBean interface.
protected StringgetMBeanClassName()
To be overridden to return metadata information about the class name of this MBean; by default returns this class' name.
protected StringgetMBeanDescription()
To be overridden to return metadata information about the description of this MBean.
MBeanInfogetMBeanInfo()
Returns the MBeaInfo, as specified by the DynamicMBean interface; the default implementation caches the value returned by AbstractDynamicMBean (that is thus called only once).
protected ObjectgetResource()
Returns the resource object on which invoke attribute's getters, attribute's setters and operation's methods
Objectinvoke(String method, Object[] arguments, String[] params)
Returns the value of the manageable operation as specified by the DynamicMBean interface
protected Objectinvoke(String name, Class[] params, Object[] args)
protected Objectinvoke(Object resource, String name, Class[] params, Object[] args)
Looks up the method to call on given resource and invokes it.
protected ObjectinvokeMethod(Method method, Object resource, Object[] args)
Invokes the given method on the given resource object with the given arguments.
voidsetAttribute(Attribute attribute)
Sets the value of the manageable attribute, as specified by the DynamicMBean interface.
AttributeListsetAttributes(AttributeList attributes)
Sets the manageable attributes, as specified by the DynamicMBean interface.
protected voidsetMBeanInfo(MBeanInfo info)
Sets the MBeanInfo object cached by this instance.
voidsetResource(Object resource)
Specifies the resource object on which invoke attribute's getters, attribute's setters and operation's methods.

Constructor Detail

AbstractDynamicMBean

protected AbstractDynamicMBean()
Only subclasses can create a new instance of an AbstractDynamicMBean.

See Also: AbstractDynamicMBean

Method Detail

createMBeanAttributeInfo

protected MBeanAttributeInfo[] createMBeanAttributeInfo()
To be overridden to return metadata information about manageable attributes.

createMBeanConstructorInfo

protected MBeanConstructorInfo[] createMBeanConstructorInfo()
To be overridden to return metadata information about manageable constructors.

createMBeanInfo

protected MBeanInfo createMBeanInfo()
Creates the MBeanInfo for this instance, calling in succession factory methods that the user can override. Information to create MBeanInfo are taken calling the following methods:

createMBeanNotificationInfo

protected MBeanNotificationInfo[] createMBeanNotificationInfo()
To be overridden to return metadata information about manageable notifications.

createMBeanOperationInfo

protected MBeanOperationInfo[] createMBeanOperationInfo()
To be overridden to return metadata information about manageable operations.

findMethod

protected Method findMethod(Class cls, String name, Class[] params)
Returns the (public) method with the given name and signature on the given class.
Override to return non-public methods, or to map methods to other classes, or to map methods with different signatures

See Also: (String, Class[], Object[]) AbstractDynamicMBean

getAttribute

public Object getAttribute(String attribute)
Returns the value of the manageable attribute, as specified by the DynamicMBean interface.

See Also: AbstractDynamicMBean

getAttributes

public AttributeList getAttributes(String[] attributes)
Returns the manageable attributes, as specified by the DynamicMBean interface.

getMBeanClassName

protected String getMBeanClassName()
To be overridden to return metadata information about the class name of this MBean; by default returns this class' name.

getMBeanDescription

protected String getMBeanDescription()
To be overridden to return metadata information about the description of this MBean.

getMBeanInfo

public MBeanInfo getMBeanInfo()
Returns the MBeaInfo, as specified by the DynamicMBean interface; the default implementation caches the value returned by AbstractDynamicMBean (that is thus called only once).

See Also: AbstractDynamicMBean AbstractDynamicMBean

getResource

protected Object getResource()
Returns the resource object on which invoke attribute's getters, attribute's setters and operation's methods

See Also: AbstractDynamicMBean

invoke

public Object invoke(String method, Object[] arguments, String[] params)
Returns the value of the manageable operation as specified by the DynamicMBean interface

See Also: AbstractDynamicMBean

invoke

protected Object invoke(String name, Class[] params, Object[] args)

Deprecated: Replaced by (Object,String,Class[],Object[]).
The resource passed is the resource as set by AbstractDynamicMBean or - if it is null - 'this' instance.
This method is deprecated because it is not thread safe.

invoke

protected Object invoke(Object resource, String name, Class[] params, Object[] args)
Looks up the method to call on given resource and invokes it. The default implementation requires that the methods that implement attribute and operation behavior on the resource object are public, but it is possible to override this behavior, and call also private methods.

See Also: AbstractDynamicMBean AbstractDynamicMBean

invokeMethod

protected Object invokeMethod(Method method, Object resource, Object[] args)
Invokes the given method on the given resource object with the given arguments.
Override to map methods to other objects, or to map methods with different arguments

See Also: (String, Class[], Object[]) AbstractDynamicMBean

setAttribute

public void setAttribute(Attribute attribute)
Sets the value of the manageable attribute, as specified by the DynamicMBean interface.

See Also: AbstractDynamicMBean

setAttributes

public AttributeList setAttributes(AttributeList attributes)
Sets the manageable attributes, as specified by the DynamicMBean interface.

setMBeanInfo

protected void setMBeanInfo(MBeanInfo info)
Sets the MBeanInfo object cached by this instance.
The given MBeanInfo is not cloned.

See Also: AbstractDynamicMBean

setResource

public void setResource(Object resource)
Specifies the resource object on which invoke attribute's getters, attribute's setters and operation's methods.

See Also: AbstractDynamicMBean

Copyright © 2001-2005 The MX4J Contributors. All Rights Reserved.