org.openqa.jetty.util.jmx
Class ModelMBeanImpl

java.lang.Object
  extended by org.openqa.jetty.util.jmx.ModelMBeanImpl
All Implemented Interfaces:
DynamicMBean, MBeanRegistration, ModelMBean, ModelMBeanNotificationBroadcaster, NotificationBroadcaster, PersistentMBean
Direct Known Subclasses:
ConfigurationMBean, LifeCycleMBean

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
protected  ModelMBeanInfoSupport _beanInfo
           
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
           
 
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, 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.
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(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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, 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 String STRING
See Also:
Constant Field Values

OBJECT

public static final String OBJECT
See Also:
Constant Field Values

INT

public static final String INT
See Also:
Constant Field Values

NO_PARAMS

public static final 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

_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

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.

getDefaultDomain

public static String getDefaultDomain()

setDefaultDomain

public static void setDefaultDomain(String d)

getMBeanServer

public MBeanServer getMBeanServer()

getObjectName

public ObjectName getObjectName()

getManagedResource

public Object getManagedResource()

setManagedResource

public void setManagedResource(Object proxyObject,
                               String type)
                        throws MBeanException,
                               RuntimeOperationsException,
                               InstanceNotFoundException,
                               InvalidTargetObjectTypeException
Specified by:
setManagedResource in interface ModelMBean
Throws:
MBeanException
RuntimeOperationsException
InstanceNotFoundException
InvalidTargetObjectTypeException

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(ModelMBeanInfo info)
                       throws MBeanException,
                              RuntimeOperationsException
Not Supported. Use RequiredModelMBean for this style of MBean creation.

Specified by:
setModelMBeanInfo in interface ModelMBean
Throws:
MBeanException
RuntimeOperationsException

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.

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 -

getMBeanInfo

public MBeanInfo getMBeanInfo()
Specified by:
getMBeanInfo in interface DynamicMBean

getAttribute

public Object getAttribute(String name)
                    throws AttributeNotFoundException,
                           MBeanException,
                           ReflectionException
Specified by:
getAttribute in interface DynamicMBean
Throws:
AttributeNotFoundException
MBeanException
ReflectionException

getAttributes

public AttributeList getAttributes(String[] names)
Specified by:
getAttributes in interface DynamicMBean

setAttribute

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

setAttributes

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

invoke

public Object invoke(String name,
                     Object[] params,
                     String[] signature)
              throws MBeanException,
                     ReflectionException
Specified by:
invoke in interface DynamicMBean
Throws:
MBeanException
ReflectionException

load

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

store

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

addNotificationListener

public void addNotificationListener(NotificationListener listener,
                                    NotificationFilter filter,
                                    Object handback)
                             throws IllegalArgumentException
Specified by:
addNotificationListener in interface NotificationBroadcaster
Throws:
IllegalArgumentException

getNotificationInfo

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

removeNotificationListener

public void removeNotificationListener(NotificationListener listener)
                                throws ListenerNotFoundException
Specified by:
removeNotificationListener in interface NotificationBroadcaster
Throws:
ListenerNotFoundException

addAttributeChangeNotificationListener

public void addAttributeChangeNotificationListener(NotificationListener listener,
                                                   String name,
                                                   Object handback)
                                            throws MBeanException,
                                                   RuntimeOperationsException,
                                                   IllegalArgumentException
Specified by:
addAttributeChangeNotificationListener in interface ModelMBeanNotificationBroadcaster
Throws:
MBeanException
RuntimeOperationsException
IllegalArgumentException

removeAttributeChangeNotificationListener

public void removeAttributeChangeNotificationListener(NotificationListener listener,
                                                      String name)
                                               throws MBeanException,
                                                      RuntimeOperationsException,
                                                      ListenerNotFoundException
Specified by:
removeAttributeChangeNotificationListener in interface ModelMBeanNotificationBroadcaster
Throws:
MBeanException
RuntimeOperationsException
ListenerNotFoundException

sendAttributeChangeNotification

public void sendAttributeChangeNotification(Attribute oldAttr,
                                            Attribute newAttr)
                                     throws MBeanException,
                                            RuntimeOperationsException
Specified by:
sendAttributeChangeNotification in interface ModelMBeanNotificationBroadcaster
Throws:
MBeanException
RuntimeOperationsException

sendAttributeChangeNotification

public void sendAttributeChangeNotification(AttributeChangeNotification notify)
                                     throws MBeanException,
                                            RuntimeOperationsException
Specified by:
sendAttributeChangeNotification in interface ModelMBeanNotificationBroadcaster
Throws:
MBeanException
RuntimeOperationsException

sendNotification

public void sendNotification(String notify)
                      throws MBeanException,
                             RuntimeOperationsException
Specified by:
sendNotification in interface ModelMBeanNotificationBroadcaster
Throws:
MBeanException
RuntimeOperationsException

sendNotification

public void sendNotification(Notification notify)
                      throws MBeanException,
                             RuntimeOperationsException
Specified by:
sendNotification in interface ModelMBeanNotificationBroadcaster
Throws:
MBeanException
RuntimeOperationsException

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

setBaseObjectName

public void setBaseObjectName(String s)

getBaseObjectName

public String getBaseObjectName()

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.

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

postRegister

public void postRegister(Boolean ok)
Specified by:
postRegister in interface MBeanRegistration

preDeregister

public void preDeregister()
Specified by:
preDeregister in interface MBeanRegistration

postDeregister

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

Specified by:
postDeregister in interface MBeanRegistration

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)

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.

destroyComponentMBeans

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

Parameters:
map -


Copyright © 2012. All Rights Reserved.