org.mortbay.util.jmx

Class ModelMBeanImpl

Implemented Interfaces:
MBeanRegistration, ModelMBean
Known Direct Subclasses:
ConfigurationMBean, LifeCycleMBean

public class ModelMBeanImpl
extends java.lang.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 int
IMPACT_ACTION
static int
IMPACT_ACTION_INFO
static int
IMPACT_INFO
static int
IMPACT_UNKOWN
static String
INT
static String[]
NO_PARAMS
static String
OBJECT
static boolean
ON_MBEAN
static boolean
ON_OBJECT
static boolean
READ_ONLY
static boolean
READ_WRITE
static String
STRING
protected ModelMBeanInfoSupport
_beanInfo

Constructor Summary

ModelMBeanImpl()
MBean Constructor.
ModelMBeanImpl(Object proxyObject)
Proxy MBean Constructor.

Method Summary

void
addAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback)
void
addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
void
defineAttribute(ModelMBeanAttributeInfo attrInfo)
Define an attribute.
void
defineAttribute(String name)
Define an attribute on the managed object.
void
defineAttribute(String name, boolean writable)
Define an attribute on the managed object.
void
defineAttribute(String name, boolean writable, boolean onMBean)
Define an attribute on the managed object.
protected void
defineManagedResource()
Define the Managed Resource.
void
defineOperation(ModelMBeanOperationInfo opInfo)
Define an operation.
void
defineOperation(String name, String[] signature, int impact)
Define an operation on the managed object.
void
defineOperation(String name, String[] signature, int impact, boolean onMBean)
Define an operation on the managed object.
void
defineOperation(String name, int impact)
Define an operation on the managed object.
protected void
destroyComponentMBeans(Map map)
Unregister mbeans for already registered components
Object
getAttribute(String name)
AttributeList
getAttributes(String[] names)
String
getBaseObjectName()
protected ObjectName[]
getComponentMBeans(Object[] components, Map map)
Get Component MBeans.
static String
getDefaultDomain()
MBeanInfo
getMBeanInfo()
MBeanServer
getMBeanServer()
Object
getManagedResource()
MBeanNotificationInfo[]
getNotificationInfo()
ObjectName
getObjectName()
Object
invoke(String name, Object[] params, String[] signature)
void
load()
static ModelMBean
mbeanFor(Object o)
Create MBean for Object.
protected ObjectName
newObjectName(MBeanServer server)
Create a new ObjectName.
void
postDeregister()
Post Deregister.
void
postRegister(Boolean ok)
void
preDeregister()
ObjectName
preRegister(MBeanServer server, ObjectName oName)
Pre registration notification.
void
removeAttributeChangeNotificationListener(NotificationListener listener, String name)
void
removeNotificationListener(NotificationListener listener)
void
sendAttributeChangeNotification(Attribute oldAttr, Attribute newAttr)
void
sendAttributeChangeNotification(AttributeChangeNotification notify)
void
sendNotification(Notification notify)
void
sendNotification(String notify)
void
setAttribute(Attribute attr)
AttributeList
setAttributes(AttributeList attrs)
void
setBaseObjectName(String s)
static void
setDefaultDomain(String d)
void
setManagedResource(Object proxyObject, String type)
void
setModelMBeanInfo(ModelMBeanInfo info)
Not Supported.
void
store()
ObjectName
uniqueObjectName(MBeanServer server, Object object, String objectName)
ObjectName
uniqueObjectName(MBeanServer server, String objectName)
Add an id clause to a JMX object name.

Field Details

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
Field Value:
true

ON_OBJECT

public static final boolean ON_OBJECT
Field Value:
false

READ_ONLY

public static final boolean READ_ONLY
Field Value:
false

READ_WRITE

public static final boolean READ_WRITE
Field Value:
true

STRING

public static final String STRING

_beanInfo

protected ModelMBeanInfoSupport _beanInfo

Constructor Details

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 Details

addAttributeChangeNotificationListener

public void addAttributeChangeNotificationListener(NotificationListener listener,
                                                   String name,
                                                   Object handback)
            throws MBeanException,
                   RuntimeOperationsException,
                   IllegalArgumentException

addNotificationListener

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

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.

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 - .

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(ModelMBeanOperationInfo opInfo)
Define an operation. Explicit definition of an operation. Reflection is used to locate method called.
Parameters:
opInfo -

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

destroyComponentMBeans

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

getAttribute

public Object getAttribute(String name)
            throws AttributeNotFoundException,
                   MBeanException,
                   ReflectionException

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

getMBeanInfo

public MBeanInfo getMBeanInfo()

getMBeanServer

public MBeanServer getMBeanServer()

getManagedResource

public Object getManagedResource()

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()

getObjectName

public ObjectName getObjectName()

invoke

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

load

public void load()
            throws MBeanException,
                   RuntimeOperationsException,
                   InstanceNotFoundException

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:
  • com.acme.MyClassMBean
  • com.acme.jmx.MyClassMBean
  • com.acme.util.BaseClassMBean
  • com.acme.util.jmx.BaseClassMBean
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)
            throws MBeanException,
                   RuntimeOperationsException,
                   ListenerNotFoundException

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)
            throws ListenerNotFoundException

sendAttributeChangeNotification

public void sendAttributeChangeNotification(Attribute oldAttr,
                                            Attribute newAttr)
            throws MBeanException,
                   RuntimeOperationsException

sendAttributeChangeNotification

public void sendAttributeChangeNotification(AttributeChangeNotification notify)
            throws MBeanException,
                   RuntimeOperationsException

sendNotification

public void sendNotification(Notification notify)
            throws MBeanException,
                   RuntimeOperationsException

sendNotification

public void sendNotification(String notify)
            throws MBeanException,
                   RuntimeOperationsException

setAttribute

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

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)
            throws MBeanException,
                   RuntimeOperationsException,
                   InstanceNotFoundException,
                   InvalidTargetObjectTypeException

setModelMBeanInfo

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

store

public void store()
            throws MBeanException,
                   RuntimeOperationsException,
                   InstanceNotFoundException

uniqueObjectName

public ObjectName uniqueObjectName(MBeanServer server,
                                   Object object,
                                   String objectName)

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.

Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.