org.mortbay.util.jmx
Class ModelMBeanImpl

java.lang.Object
  |
  +--org.mortbay.util.jmx.ModelMBeanImpl
All Implemented Interfaces:
javax.management.DynamicMBean, javax.management.MBeanRegistration, javax.management.modelmbean.ModelMBean, javax.management.modelmbean.ModelMBeanNotificationBroadcaster, javax.management.NotificationBroadcaster, javax.management.PersistentMBean
Direct Known Subclasses:
CodeMBean, LifeCycleMBean, LogMBean

public class ModelMBeanImpl
extends java.lang.Object
implements javax.management.modelmbean.ModelMBean, javax.management.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.6.2.2 $
Author:
Greg Wilkins (gregw)

Field Summary
static int IMPACT_ACTION
           
static int IMPACT_ACTION_INFO
           
static int IMPACT_INFO
           
static int IMPACT_UNKOWN
           
static java.lang.String INT
           
static java.lang.String[] NO_PARAMS
           
static java.lang.String OBJECT
           
static boolean ON_MBEAN
           
static boolean ON_OBJECT
           
static boolean READ_ONLY
           
static boolean READ_WRITE
           
static java.lang.String STRING
           
 
Constructor Summary
ModelMBeanImpl()
          MBean Constructor.
ModelMBeanImpl(java.lang.Object proxyObject)
          Proxy MBean Constructor.
 
Method Summary
 void addAttributeChangeNotificationListener(javax.management.NotificationListener listener, java.lang.String name, java.lang.Object handback)
           
 void addNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
           
 void defineAttribute(javax.management.modelmbean.ModelMBeanAttributeInfo attrInfo)
          Define an attribute.
 void defineAttribute(java.lang.String name)
          Define an attribute on the managed object.
 void defineAttribute(java.lang.String name, boolean writable)
          Define an attribute on the managed object.
 void defineAttribute(java.lang.String name, boolean writable, boolean onMBean)
          Define an attribute on the managed object.
 void defineOperation(javax.management.modelmbean.ModelMBeanOperationInfo opInfo)
          Define an operation.
 void defineOperation(java.lang.String name, int impact)
          Define an operation on the managed object.
 void defineOperation(java.lang.String name, java.lang.String[] signature, int impact)
          Define an operation on the managed object.
 void defineOperation(java.lang.String name, java.lang.String[] signature, int impact, boolean onMBean)
          Define an operation on the managed object.
 java.lang.Object getAttribute(java.lang.String name)
           
 javax.management.AttributeList getAttributes(java.lang.String[] names)
           
 java.lang.String getBaseObjectName()
           
static java.lang.String getDefaultDomain()
           
 java.lang.Object getManagedResource()
           
 javax.management.MBeanInfo getMBeanInfo()
           
 javax.management.MBeanServer getMBeanServer()
           
 javax.management.MBeanNotificationInfo[] getNotificationInfo()
           
 javax.management.ObjectName getObjectName()
           
 java.lang.Object invoke(java.lang.String name, java.lang.Object[] params, java.lang.String[] signature)
           
 void load()
           
static javax.management.modelmbean.ModelMBean mbeanFor(java.lang.Object o)
          Create MBean for Object.
 void postDeregister()
          Post Deregister.
 void postRegister(java.lang.Boolean ok)
           
 void preDeregister()
           
 javax.management.ObjectName preRegister(javax.management.MBeanServer server, javax.management.ObjectName oName)
          Pre registration notification.
 void removeAttributeChangeNotificationListener(javax.management.NotificationListener listener, java.lang.String name)
           
 void removeNotificationListener(javax.management.NotificationListener listener)
           
 void sendAttributeChangeNotification(javax.management.Attribute oldAttr, javax.management.Attribute newAttr)
           
 void sendAttributeChangeNotification(javax.management.AttributeChangeNotification notify)
           
 void sendNotification(javax.management.Notification notify)
           
 void sendNotification(java.lang.String notify)
           
 void setAttribute(javax.management.Attribute attr)
           
 javax.management.AttributeList setAttributes(javax.management.AttributeList attrs)
           
 void setBaseObjectName(java.lang.String s)
           
static void setDefaultDomain(java.lang.String d)
           
 void setManagedResource(java.lang.Object proxyObject, java.lang.String type)
           
 void setModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo info)
          Not Supported.
 void store()
           
 javax.management.ObjectName uniqueObjectName(javax.management.MBeanServer server, java.lang.Object object, java.lang.String objectName)
           
 javax.management.ObjectName uniqueObjectName(javax.management.MBeanServer server, java.lang.String objectName)
          Add an id clause to a JMX object name.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IMPACT_ACTION

public static final int IMPACT_ACTION
See Also:
Constant Field Values

IMPACT_ACTION_INFO

public static final int IMPACT_ACTION_INFO
See Also:
Constant Field Values

IMPACT_INFO

public static final int IMPACT_INFO
See Also:
Constant Field Values

IMPACT_UNKOWN

public static final int IMPACT_UNKOWN
See Also:
Constant Field Values

STRING

public static final java.lang.String STRING
See Also:
Constant Field Values

OBJECT

public static final java.lang.String OBJECT
See Also:
Constant Field Values

INT

public static final java.lang.String INT
See Also:
Constant Field Values

NO_PARAMS

public static final java.lang.String[] NO_PARAMS

READ_WRITE

public static final boolean READ_WRITE
See Also:
Constant Field Values

READ_ONLY

public static final boolean READ_ONLY
See Also:
Constant Field Values

ON_MBEAN

public static final boolean ON_MBEAN
See Also:
Constant Field Values

ON_OBJECT

public static final boolean ON_OBJECT
See Also:
Constant Field Values
Constructor Detail

ModelMBeanImpl

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


ModelMBeanImpl

public ModelMBeanImpl(java.lang.Object proxyObject)
Proxy MBean Constructor.

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

mbeanFor

public static javax.management.modelmbean.ModelMBean mbeanFor(java.lang.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.

getDefaultDomain

public static java.lang.String getDefaultDomain()

setDefaultDomain

public static void setDefaultDomain(java.lang.String d)

getMBeanServer

public javax.management.MBeanServer getMBeanServer()

getObjectName

public javax.management.ObjectName getObjectName()

getManagedResource

public java.lang.Object getManagedResource()

setManagedResource

public void setManagedResource(java.lang.Object proxyObject,
                               java.lang.String type)
                        throws javax.management.MBeanException,
                               javax.management.RuntimeOperationsException,
                               javax.management.InstanceNotFoundException,
                               javax.management.modelmbean.InvalidTargetObjectTypeException
Specified by:
setManagedResource in interface javax.management.modelmbean.ModelMBean
javax.management.MBeanException
javax.management.RuntimeOperationsException
javax.management.InstanceNotFoundException
javax.management.modelmbean.InvalidTargetObjectTypeException

setModelMBeanInfo

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

Specified by:
setModelMBeanInfo in interface javax.management.modelmbean.ModelMBean
javax.management.MBeanException
javax.management.RuntimeOperationsException

defineAttribute

public void defineAttribute(java.lang.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(java.lang.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(java.lang.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(javax.management.modelmbean.ModelMBeanAttributeInfo attrInfo)
Define an attribute. Explicit definition of an attribute. Reflection is used to locate the actual getter and setter methods.

Parameters:
attrInfo - ModelMBeanAttributeInfo.

defineOperation

public void defineOperation(java.lang.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(java.lang.String name,
                            java.lang.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(java.lang.String name,
                            java.lang.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(javax.management.modelmbean.ModelMBeanOperationInfo opInfo)
Define an operation. Explicit definition of an operation. Reflection is used to locate method called.

Parameters:
opInfo -

getMBeanInfo

public javax.management.MBeanInfo getMBeanInfo()
Specified by:
getMBeanInfo in interface javax.management.DynamicMBean

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
                              throws javax.management.AttributeNotFoundException,
                                     javax.management.MBeanException,
                                     javax.management.ReflectionException
Specified by:
getAttribute in interface javax.management.DynamicMBean
javax.management.AttributeNotFoundException
javax.management.MBeanException
javax.management.ReflectionException

getAttributes

public javax.management.AttributeList getAttributes(java.lang.String[] names)
Specified by:
getAttributes in interface javax.management.DynamicMBean

setAttribute

public void setAttribute(javax.management.Attribute attr)
                  throws javax.management.AttributeNotFoundException,
                         javax.management.InvalidAttributeValueException,
                         javax.management.MBeanException,
                         javax.management.ReflectionException
Specified by:
setAttribute in interface javax.management.DynamicMBean
javax.management.AttributeNotFoundException
javax.management.InvalidAttributeValueException
javax.management.MBeanException
javax.management.ReflectionException

setAttributes

public javax.management.AttributeList setAttributes(javax.management.AttributeList attrs)
Specified by:
setAttributes in interface javax.management.DynamicMBean

invoke

public java.lang.Object invoke(java.lang.String name,
                               java.lang.Object[] params,
                               java.lang.String[] signature)
                        throws javax.management.MBeanException,
                               javax.management.ReflectionException
Specified by:
invoke in interface javax.management.DynamicMBean
javax.management.MBeanException
javax.management.ReflectionException

load

public void load()
          throws javax.management.MBeanException,
                 javax.management.RuntimeOperationsException,
                 javax.management.InstanceNotFoundException
Specified by:
load in interface javax.management.PersistentMBean
javax.management.MBeanException
javax.management.RuntimeOperationsException
javax.management.InstanceNotFoundException

store

public void store()
           throws javax.management.MBeanException,
                  javax.management.RuntimeOperationsException,
                  javax.management.InstanceNotFoundException
Specified by:
store in interface javax.management.PersistentMBean
javax.management.MBeanException
javax.management.RuntimeOperationsException
javax.management.InstanceNotFoundException

addNotificationListener

public void addNotificationListener(javax.management.NotificationListener listener,
                                    javax.management.NotificationFilter filter,
                                    java.lang.Object handback)
                             throws java.lang.IllegalArgumentException
Specified by:
addNotificationListener in interface javax.management.NotificationBroadcaster
java.lang.IllegalArgumentException

getNotificationInfo

public javax.management.MBeanNotificationInfo[] getNotificationInfo()
Specified by:
getNotificationInfo in interface javax.management.NotificationBroadcaster

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener)
                                throws javax.management.ListenerNotFoundException
Specified by:
removeNotificationListener in interface javax.management.NotificationBroadcaster
javax.management.ListenerNotFoundException

addAttributeChangeNotificationListener

public void addAttributeChangeNotificationListener(javax.management.NotificationListener listener,
                                                   java.lang.String name,
                                                   java.lang.Object handback)
                                            throws javax.management.MBeanException,
                                                   javax.management.RuntimeOperationsException,
                                                   java.lang.IllegalArgumentException
Specified by:
addAttributeChangeNotificationListener in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
javax.management.MBeanException
javax.management.RuntimeOperationsException
java.lang.IllegalArgumentException

removeAttributeChangeNotificationListener

public void removeAttributeChangeNotificationListener(javax.management.NotificationListener listener,
                                                      java.lang.String name)
                                               throws javax.management.MBeanException,
                                                      javax.management.RuntimeOperationsException,
                                                      javax.management.ListenerNotFoundException
Specified by:
removeAttributeChangeNotificationListener in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
javax.management.MBeanException
javax.management.RuntimeOperationsException
javax.management.ListenerNotFoundException

sendAttributeChangeNotification

public void sendAttributeChangeNotification(javax.management.Attribute oldAttr,
                                            javax.management.Attribute newAttr)
                                     throws javax.management.MBeanException,
                                            javax.management.RuntimeOperationsException
Specified by:
sendAttributeChangeNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
javax.management.MBeanException
javax.management.RuntimeOperationsException

sendAttributeChangeNotification

public void sendAttributeChangeNotification(javax.management.AttributeChangeNotification notify)
                                     throws javax.management.MBeanException,
                                            javax.management.RuntimeOperationsException
Specified by:
sendAttributeChangeNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
javax.management.MBeanException
javax.management.RuntimeOperationsException

sendNotification

public void sendNotification(java.lang.String notify)
                      throws javax.management.MBeanException,
                             javax.management.RuntimeOperationsException
Specified by:
sendNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
javax.management.MBeanException
javax.management.RuntimeOperationsException

sendNotification

public void sendNotification(javax.management.Notification notify)
                      throws javax.management.MBeanException,
                             javax.management.RuntimeOperationsException
Specified by:
sendNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
javax.management.MBeanException
javax.management.RuntimeOperationsException

setBaseObjectName

public void setBaseObjectName(java.lang.String s)

getBaseObjectName

public java.lang.String getBaseObjectName()

preRegister

public javax.management.ObjectName preRegister(javax.management.MBeanServer server,
                                               javax.management.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.

Specified by:
preRegister in interface javax.management.MBeanRegistration
Parameters:
server -
oName -
Returns:
The ObjectName to use.

postRegister

public void postRegister(java.lang.Boolean ok)
Specified by:
postRegister in interface javax.management.MBeanRegistration

preDeregister

public void preDeregister()
Specified by:
preDeregister in interface javax.management.MBeanRegistration

postDeregister

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

Specified by:
postDeregister in interface javax.management.MBeanRegistration

uniqueObjectName

public javax.management.ObjectName uniqueObjectName(javax.management.MBeanServer server,
                                                    java.lang.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 javax.management.ObjectName uniqueObjectName(javax.management.MBeanServer server,
                                                    java.lang.Object object,
                                                    java.lang.String objectName)


Copyright ? 2000 Mortbay Consulting Pty. Ltd. All Rights Reserved.