Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.mortbay.util.jmx
Class ModelMBeanImpl  view ModelMBeanImpl download ModelMBeanImpl.java

java.lang.Object
  extended byorg.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, TestModelMBean

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

Field Summary
private static java.lang.String __defaultDomain
           
private static java.util.HashMap __objectId
           
private  java.util.ArrayList _attributes
           
private  java.lang.String _baseObjectName
           
protected  javax.management.modelmbean.ModelMBeanInfoSupport _beanInfo
           
private  java.util.Map _components
           
private  boolean _dirty
           
private  java.util.HashMap _getter
           
private  javax.management.MBeanServer _mBeanServer
           
private  java.util.HashMap _method
           
private  java.util.ArrayList _notifications
           
private  java.lang.Object _object
           
private  javax.management.ObjectName _objectName
           
private  java.util.ArrayList _operations
           
private  java.util.HashMap _setter
           
static int IMPACT_ACTION
           
static int IMPACT_ACTION_INFO
           
static int IMPACT_INFO
           
static int IMPACT_UNKOWN
           
static java.lang.String INT
           
private static org.apache.commons.logging.Log log
           
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.
protected  void defineManagedResource()
          Define the Managed Resource.
 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.
private  java.lang.String findDescription(java.lang.String key)
           
 java.lang.Object getAttribute(java.lang.String name)
          Returns the value of the attribute with the name matching the passed string.
 javax.management.AttributeList getAttributes(java.lang.String[] names)
          Returns the values of the attributes with names matching the passed string array.
 java.lang.String getBaseObjectName()
           
protected  javax.management.ObjectName[] getComponentMBeans(java.lang.Object[] components, java.util.Map map)
          Get Component MBeans.
static java.lang.String getDefaultDomain()
           
 java.lang.Object getManagedResource()
           
 javax.management.MBeanInfo getMBeanInfo()
          Returns the management interface that describes this dynamic resource.
 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)
          Invokes a resource operation.
 void load()
           
static javax.management.modelmbean.ModelMBean mbeanFor(java.lang.Object o)
          Create MBean for Object.
protected  javax.management.ObjectName newObjectName(javax.management.MBeanServer server)
          Create a new ObjectName.
 void postDeregister()
          Post Deregister.
 void postRegister(java.lang.Boolean ok)
          This method is called by the MBeanServer after registration takes place or when registration fails.
 void preDeregister()
          This method is called by the MBeanServer before deregistration takes place.
 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)
          Sets the value of an attribute.
 javax.management.AttributeList setAttributes(javax.management.AttributeList attrs)
          Sets the values of the attributes passed as an AttributeList of name and new value pairs.
 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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static org.apache.commons.logging.Log log

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

__objectId

private static java.util.HashMap __objectId

__defaultDomain

private static java.lang.String __defaultDomain

_beanInfo

protected javax.management.modelmbean.ModelMBeanInfoSupport _beanInfo

_mBeanServer

private javax.management.MBeanServer _mBeanServer

_object

private java.lang.Object _object

_objectName

private javax.management.ObjectName _objectName

_dirty

private boolean _dirty

_getter

private java.util.HashMap _getter

_setter

private java.util.HashMap _setter

_method

private java.util.HashMap _method

_attributes

private java.util.ArrayList _attributes

_operations

private java.util.ArrayList _operations

_notifications

private java.util.ArrayList _notifications

_baseObjectName

private java.lang.String _baseObjectName

_components

private java.util.Map _components
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.

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:
  • com.acme.MyClassMBean
  • com.acme.jmx.MyClassMBean
  • com.acme.util.BaseClassMBean
  • com.acme.util.jmx.BaseClassMBean


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

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.


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

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.


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.


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.


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.


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


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.


defineOperation

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


getMBeanInfo

public javax.management.MBeanInfo getMBeanInfo()
Description copied from interface: javax.management.DynamicMBean
Returns the management interface that describes this dynamic resource. It is the responsibility of the implementation to make sure the description is accurate.

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
Description copied from interface: javax.management.DynamicMBean
Returns the value of the attribute with the name matching the passed string.

Specified by:
getAttribute in interface javax.management.DynamicMBean

getAttributes

public javax.management.AttributeList getAttributes(java.lang.String[] names)
Description copied from interface: javax.management.DynamicMBean
Returns the values of the attributes with names matching the passed string array.

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
Description copied from interface: javax.management.DynamicMBean
Sets the value of an attribute. The attribute and new value are passed in the name value pair Attribute.

Specified by:
setAttribute in interface javax.management.DynamicMBean

setAttributes

public javax.management.AttributeList setAttributes(javax.management.AttributeList attrs)
Description copied from interface: javax.management.DynamicMBean
Sets the values of the attributes passed as an AttributeList of name and new value pairs.

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
Description copied from interface: javax.management.DynamicMBean
Invokes a resource operation.

Specified by:
invoke in interface javax.management.DynamicMBean

load

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

store

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

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

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

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

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

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

sendAttributeChangeNotification

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

sendNotification

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

sendNotification

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

findDescription

private java.lang.String findDescription(java.lang.String key)

newObjectName

protected javax.management.ObjectName newObjectName(javax.management.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+":");


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

postRegister

public void postRegister(java.lang.Boolean ok)
Description copied from interface: javax.management.MBeanRegistration
This method is called by the MBeanServer after registration takes place or when registration fails.

Specified by:
postRegister in interface javax.management.MBeanRegistration

preDeregister

public void preDeregister()
Description copied from interface: javax.management.MBeanRegistration
This method is called by the MBeanServer before deregistration takes place.

The MBean can throw an exception, this will stop the deregistration. The exception is forwarded to the invoker wrapped in an MBeanRegistrationException.

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.


uniqueObjectName

public javax.management.ObjectName uniqueObjectName(javax.management.MBeanServer server,
                                                    java.lang.Object object,
                                                    java.lang.String objectName)

getComponentMBeans

protected javax.management.ObjectName[] getComponentMBeans(java.lang.Object[] components,
                                                           java.util.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.