org.mortbay.util.jmx

Class ModelMBeanImpl

public class ModelMBeanImpl extends Object implements ModelMBean, MBeanRegistration

Model MBean Implementation. This implementation of the JMX Model MBean API is designed to allow easy creation of Model MBeans. From minimal descriptions of operations and attributes, reflection is used to determine the full signature and ResourceBundles are used to determine other meta data. This class is normally used in one of the following patterns:

Version: $Revision: 1.18 $

Author: Greg Wilkins (gregw)

Field Summary
static intIMPACT_ACTION
static intIMPACT_ACTION_INFO
static intIMPACT_INFO
static intIMPACT_UNKOWN
static StringINT
static String[]NO_PARAMS
static StringOBJECT
static booleanON_MBEAN
static booleanON_OBJECT
static booleanREAD_ONLY
static booleanREAD_WRITE
static StringSTRING
protected ModelMBeanInfoSupport_beanInfo
Constructor Summary
ModelMBeanImpl()
MBean Constructor.
ModelMBeanImpl(Object proxyObject)
Proxy MBean Constructor.
Method Summary
voidaddAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback)
voidaddNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
voiddefineAttribute(String name)
Define an attribute on the managed object.
voiddefineAttribute(String name, boolean writable)
Define an attribute on the managed object.
voiddefineAttribute(String name, boolean writable, boolean onMBean)
Define an attribute on the managed object.
voiddefineAttribute(ModelMBeanAttributeInfo attrInfo)
Define an attribute.
protected voiddefineManagedResource()
Define the Managed Resource.
voiddefineOperation(String name, int impact)
Define an operation on the managed object.
voiddefineOperation(String name, String[] signature, int impact)
Define an operation on the managed object.
voiddefineOperation(String name, String[] signature, int impact, boolean onMBean)
Define an operation on the managed object.
voiddefineOperation(ModelMBeanOperationInfo opInfo)
Define an operation.
protected voiddestroyComponentMBeans(Map map)
Unregister mbeans for already registered components
ObjectgetAttribute(String name)
AttributeListgetAttributes(String[] names)
StringgetBaseObjectName()
protected ObjectName[]getComponentMBeans(Object[] components, Map map)
Get Component MBeans.
static StringgetDefaultDomain()
ObjectgetManagedResource()
MBeanInfogetMBeanInfo()
MBeanServergetMBeanServer()
MBeanNotificationInfo[]getNotificationInfo()
ObjectNamegetObjectName()
Objectinvoke(String name, Object[] params, String[] signature)
voidload()
static ModelMBeanmbeanFor(Object o)
Create MBean for Object.
protected ObjectNamenewObjectName(MBeanServer server)
Create a new ObjectName.
voidpostDeregister()
Post Deregister.
voidpostRegister(Boolean ok)
voidpreDeregister()
ObjectNamepreRegister(MBeanServer server, ObjectName oName)
Pre registration notification.
voidremoveAttributeChangeNotificationListener(NotificationListener listener, String name)
voidremoveNotificationListener(NotificationListener listener)
voidsendAttributeChangeNotification(Attribute oldAttr, Attribute newAttr)
voidsendAttributeChangeNotification(AttributeChangeNotification notify)
voidsendNotification(String notify)
voidsendNotification(Notification notify)
voidsetAttribute(Attribute attr)
AttributeListsetAttributes(AttributeList attrs)
voidsetBaseObjectName(String s)
static voidsetDefaultDomain(String d)
voidsetManagedResource(Object proxyObject, String type)
voidsetModelMBeanInfo(ModelMBeanInfo info)
Not Supported.
voidstore()
ObjectNameuniqueObjectName(MBeanServer server, String objectName)
Add an id clause to a JMX object name.
ObjectNameuniqueObjectName(MBeanServer server, Object object, String objectName)

Field Detail

IMPACT_ACTION

public static final int IMPACT_ACTION

IMPACT_ACTION_INFO

public static final int IMPACT_ACTION_INFO

IMPACT_INFO

public static final int IMPACT_INFO

IMPACT_UNKOWN

public static final int IMPACT_UNKOWN

INT

public static final String INT

NO_PARAMS

public static final String[] NO_PARAMS

OBJECT

public static final String OBJECT

ON_MBEAN

public static final boolean ON_MBEAN

ON_OBJECT

public static final boolean ON_OBJECT

READ_ONLY

public static final boolean READ_ONLY

READ_WRITE

public static final boolean READ_WRITE

STRING

public static final String STRING

_beanInfo

protected ModelMBeanInfoSupport _beanInfo

Constructor Detail

ModelMBeanImpl

public ModelMBeanImpl()
MBean Constructor. No proxy object is defined. Attributes and operations are defined on this instance.

ModelMBeanImpl

public ModelMBeanImpl(Object proxyObject)
Proxy MBean Constructor.

Parameters: proxyObject The actual object on which attributes and operations are to be defined and called.

Method Detail

addAttributeChangeNotificationListener

public void addAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback)

addNotificationListener

public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)

defineAttribute

public void defineAttribute(String name)
Define an attribute on the managed object. The meta data is defined by looking for standard getter and setter methods. Descriptions are obtained with a call to findDescription with the attribute name.

Parameters: name The name of the attribute. Normal java bean capitlization is enforced on this name.

defineAttribute

public void defineAttribute(String name, boolean writable)
Define an attribute on the managed object. The meta data is defined by looking for standard getter and setter methods. Descriptions are obtained with a call to findDescription with the attribute name.

Parameters: name The name of the attribute. Normal java bean capitlization is enforced on this name. writable If false, do not look for a setter.

defineAttribute

public void defineAttribute(String name, boolean writable, boolean onMBean)
Define an attribute on the managed object. The meta data is defined by looking for standard getter and setter methods. Descriptions are obtained with a call to findDescription with the attribute name.

Parameters: name The name of the attribute. Normal java bean capitlization is enforced on this name. writable If false, do not look for a setter. onMBean .

defineAttribute

public void defineAttribute(ModelMBeanAttributeInfo attrInfo)
Define an attribute. Explicit definition of an attribute. Reflection is used to locate the actual getter and setter methods.

Parameters: attrInfo ModelMBeanAttributeInfo.

defineManagedResource

protected void defineManagedResource()
Define the Managed Resource. This method is called the first time setManagedResource is called with a non-null object. It should be implemented by a derived ModelMBean to define the attributes and operations after an initial object has been set.

defineOperation

public void defineOperation(String name, int impact)
Define an operation on the managed object. Defines an operation with no parameters. Refection is used to determine the return type and the description is found with a call to findDescription on "name()".

Parameters: name Name of the method call impact Impact as defined in MBeanOperationInfo

defineOperation

public void defineOperation(String name, String[] signature, int impact)
Define an operation on the managed object. Defines an operation with parameters. Refection is used to determine find the method and it's return type. The description of the method is found with a call to findDescription on "name(signature)". The name and description of each parameter is found with a call to findDescription with "name(partialSignature", the returned description is for the last parameter of the partial signature and is assumed to start with the parameter name, followed by a colon.

Parameters: name The name of the method call. signature The types of the operation parameters. impact Impact as defined in MBeanOperationInfo

defineOperation

public void defineOperation(String name, String[] signature, int impact, boolean onMBean)
Define an operation on the managed object. Defines an operation with parameters. Refection is used to determine find the method and it's return type. The description of the method is found with a call to findDescription on "name(signature)". The name and description of each parameter is found with a call to findDescription with "name(partialSignature", the returned description is for the last parameter of the partial signature and is assumed to start with the parameter name, followed by a colon.

Parameters: name The name of the method call. signature The types of the operation parameters. impact Impact as defined in MBeanOperationInfo onMBean true if the operation is defined on the mbean

defineOperation

public void defineOperation(ModelMBeanOperationInfo opInfo)
Define an operation. Explicit definition of an operation. Reflection is used to locate method called.

Parameters: opInfo

destroyComponentMBeans

protected void destroyComponentMBeans(Map map)
Unregister mbeans for already registered components

Parameters: map

getAttribute

public Object getAttribute(String name)

getAttributes

public AttributeList getAttributes(String[] names)

getBaseObjectName

public String getBaseObjectName()

getComponentMBeans

protected ObjectName[] getComponentMBeans(Object[] components, Map map)
Get Component MBeans. Creates, registers and deregisters MBeans for an array of components. On each call the passed map is used to determine components that have already been registers and those that need to be deregistered.

Parameters: components the components. map A map of previously registered components to object name. If null is passed, a default map for the mbean is used.

Returns: An array of ObjectNames for each component.

getDefaultDomain

public static String getDefaultDomain()

getManagedResource

public Object getManagedResource()

getMBeanInfo

public MBeanInfo getMBeanInfo()

getMBeanServer

public MBeanServer getMBeanServer()

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()

getObjectName

public ObjectName getObjectName()

invoke

public Object invoke(String name, Object[] params, String[] signature)

load

public void load()

mbeanFor

public static ModelMBean mbeanFor(Object o)
Create MBean for Object. Attempts to create an MBean for the object by searching the package and class name space. For example an object of the type
   class com.acme.MyClass extends com.acme.util.BaseClass
 
Then this method would look for the following classes:

Parameters: o The object

Returns: A new instance of an MBean for the object or null.

newObjectName

protected ObjectName newObjectName(MBeanServer server)
Create a new ObjectName. Return a new object name. The default implementation is the results of uniqueObjectName(baseObjectName), if baseObjectName is not set, then the results of uniqueObjectName(defaultDomain+":");

Returns: The Object name

postDeregister

public void postDeregister()
Post Deregister. This implementation destroys this MBean and it cannot be used again.

postRegister

public void postRegister(Boolean ok)

preDeregister

public void preDeregister()

preRegister

public ObjectName preRegister(MBeanServer server, ObjectName oName)
Pre registration notification. If this method is specialized by a derived class that may set the objectName, then it should call this implementation with the new objectName.

Parameters: server oName

Returns: The ObjectName to use.

removeAttributeChangeNotificationListener

public void removeAttributeChangeNotificationListener(NotificationListener listener, String name)

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)

sendAttributeChangeNotification

public void sendAttributeChangeNotification(Attribute oldAttr, Attribute newAttr)

sendAttributeChangeNotification

public void sendAttributeChangeNotification(AttributeChangeNotification notify)

sendNotification

public void sendNotification(String notify)

sendNotification

public void sendNotification(Notification notify)

setAttribute

public void setAttribute(Attribute attr)

setAttributes

public AttributeList setAttributes(AttributeList attrs)

setBaseObjectName

public void setBaseObjectName(String s)

setDefaultDomain

public static void setDefaultDomain(String d)

setManagedResource

public void setManagedResource(Object proxyObject, String type)

setModelMBeanInfo

public void setModelMBeanInfo(ModelMBeanInfo info)
Not Supported. Use RequiredModelMBean for this style of MBean creation.

store

public void store()

uniqueObjectName

public ObjectName uniqueObjectName(MBeanServer server, String objectName)
Add an id clause to a JMX object name. Used to make unique objectnames when there are no other distinguishing attributes. If the passed object name ends with '=', just a unique ID is added. Otherwise and classname= clause is added.

Parameters: objectName

Returns: objectName with id= class.

uniqueObjectName

public ObjectName uniqueObjectName(MBeanServer server, Object object, String objectName)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.