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:
- As a base class for a real MBean that contains the actual
attributes and operations of the MBean. Such an Object is only
usable in a JMX environment.
- As a proxy MBean to another non-JMX object. The attributes and
operations of the proxied object are defined in the MBean. This
pattern is used when an existing non-JMX objects API is to be
exposed as an MBean.
- As a base class for a proxy MBean. The attributes and oepration
of the MBean are implemented by the derived class but delegate to
one or more other objects. This pattern is used if existing objects
are to be managed by JMX, but a new management API needs to be
defined.
Version: $Revision: 1.18 $
Author: Greg Wilkins (gregw)
Method Summary |
void | addAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback) |
void | addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) |
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.
|
void | defineAttribute(ModelMBeanAttributeInfo attrInfo) Define an attribute.
|
protected void | defineManagedResource() Define the Managed Resource.
|
void | defineOperation(String name, int impact) Define an operation on the managed object.
|
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(ModelMBeanOperationInfo opInfo) Define an operation.
|
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() |
Object | getManagedResource() |
MBeanInfo | getMBeanInfo() |
MBeanServer | getMBeanServer() |
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(String notify) |
void | sendNotification(Notification 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, String objectName) Add an id clause to a JMX object name.
|
ObjectName | uniqueObjectName(MBeanServer server, Object object, String objectName) |
public static final int IMPACT_ACTION
public static final int IMPACT_ACTION_INFO
public static final int IMPACT_INFO
public static final int IMPACT_UNKOWN
public static final String INT
public static final String[] NO_PARAMS
public static final String OBJECT
public static final boolean ON_MBEAN
public static final boolean ON_OBJECT
public static final boolean READ_ONLY
public static final boolean READ_WRITE
public static final String STRING
protected ModelMBeanInfoSupport _beanInfo
public ModelMBeanImpl()
MBean Constructor.
No proxy object is defined. Attributes and operations are
defined on this instance.
public ModelMBeanImpl(Object proxyObject)
Proxy MBean Constructor.
Parameters: proxyObject The actual object on which attributes and
operations are to be defined and called.
public void addAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback)
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
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.
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.
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 .
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.
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.
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
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
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
public void defineOperation(ModelMBeanOperationInfo opInfo)
Define an operation.
Explicit definition of an operation. Reflection is used to
locate method called.
Parameters: opInfo
protected void destroyComponentMBeans(Map map)
Unregister mbeans for already registered components
Parameters: map
public Object getAttribute(String name)
public AttributeList getAttributes(String[] names)
public String getBaseObjectName()
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.
public static String getDefaultDomain()
public Object getManagedResource()
public MBeanInfo getMBeanInfo()
public MBeanServer getMBeanServer()
public MBeanNotificationInfo[] getNotificationInfo()
public ObjectName getObjectName()
public Object invoke(String name, Object[] params, String[] signature)
public void load()
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.
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
public void postDeregister()
Post Deregister.
This implementation destroys this MBean and it cannot be used again.
public void postRegister(Boolean ok)
public void preDeregister()
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.
public void removeAttributeChangeNotificationListener(NotificationListener listener, String name)
public void removeNotificationListener(NotificationListener listener)
public void sendAttributeChangeNotification(Attribute oldAttr, Attribute newAttr)
public void sendAttributeChangeNotification(AttributeChangeNotification notify)
public void sendNotification(String notify)
public void sendNotification(Notification notify)
public void setAttribute(Attribute attr)
public AttributeList setAttributes(AttributeList attrs)
public void setBaseObjectName(String s)
public static void setDefaultDomain(String d)
public void setManagedResource(Object proxyObject, String type)
public void setModelMBeanInfo(ModelMBeanInfo info)
Not Supported.
Use RequiredModelMBean for this style of MBean creation.
public void store()
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.
public ObjectName uniqueObjectName(MBeanServer server, Object object, String objectName)
Copyright © 2004 Mortbay Consulting Pty. Ltd. All Rights Reserved.