org.apache.commons.modeler
Class BaseModelMBean

java.lang.Object
  |
  +--org.apache.commons.modeler.BaseModelMBean
All Implemented Interfaces:
javax.management.DynamicMBean, javax.management.modelmbean.ModelMBean, javax.management.modelmbean.ModelMBeanNotificationBroadcaster, javax.management.NotificationBroadcaster, javax.management.PersistentMBean

public class BaseModelMBean
extends java.lang.Object
implements javax.management.modelmbean.ModelMBean

Basic implementation of the ModelMBean interface, which supports the minimal requirements of the interface contract as follows:

Version:
$Revision: 1.1.1.1 $ $Date: 2002/04/30 20:58:51 $
Author:
Craig R. McClanahan

Field Summary
protected  BaseNotificationBroadcaster attributeBroadcaster
          Notification broadcaster for attribute changes.
protected  BaseNotificationBroadcaster generalBroadcaster
          Notification broadcaster for general notifications.
protected  javax.management.modelmbean.ModelMBeanInfo info
          The ModelMBeanInfo object that controls our activity.
protected  java.lang.Object resource
          The managed resource this MBean is associated with (if any).
 
Constructor Summary
BaseModelMBean()
          Construct a ModelMBean with default ModelMBeanInfo information.
BaseModelMBean(javax.management.modelmbean.ModelMBeanInfo info)
          Construct a ModelMBean associated with the specified ModelMBeanInfo information.
 
Method Summary
 void addAttributeChangeNotificationListener(javax.management.NotificationListener listener, java.lang.String name, java.lang.Object handback)
          Add an attribute change notification event listener to this MBean.
 void addNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
          Add a notification event listener to this MBean.
protected  javax.management.modelmbean.ModelMBeanInfo createDefaultModelMBeanInfo()
          Create and return a default ModelMBeanInfo object.
 java.lang.Object getAttribute(java.lang.String name)
          Obtain and return the value of a specific attribute of this MBean.
 javax.management.AttributeList getAttributes(java.lang.String[] names)
          Obtain and return the values of several attributes of this MBean.
 java.lang.Object getManagedResource()
          Get the instance handle of the object against which we execute all methods in this ModelMBean management interface.
 javax.management.MBeanInfo getMBeanInfo()
          Return the MBeanInfo object for this MBean.
 javax.management.MBeanNotificationInfo[] getNotificationInfo()
          Return an MBeanNotificationInfo object describing the notifications sent by this MBean.
 java.lang.Object invoke(java.lang.String name, java.lang.Object[] params, java.lang.String[] signature)
          Invoke a particular method on this MBean, and return any returned value.
protected  boolean isModelMBeanInfoValid(javax.management.modelmbean.ModelMBeanInfo info)
          Is the specified ModelMBeanInfo instance valid?
 void load()
          Instantiates this MBean instance from data found in the persistent store.
 void removeAttributeChangeNotificationListener(javax.management.NotificationListener listener, java.lang.String name)
          Remove an attribute change notification event listener from this MBean.
 void removeAttributeChangeNotificationListener(javax.management.NotificationListener listener, java.lang.String attributeName, java.lang.Object handback)
          Remove an attribute change notification event listener from this MBean.
 void removeNotificationListener(javax.management.NotificationListener listener)
          Remove a notification event listener from this MBean.
 void removeNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)
          Remove a notification event listener from this MBean.
 void removeNotificationListener(javax.management.NotificationListener listener, java.lang.Object handback)
          Remove a notification event listener from this MBean.
 void sendAttributeChangeNotification(javax.management.Attribute oldValue, javax.management.Attribute newValue)
          Send an AttributeChangeNotification to all registered listeners.
 void sendAttributeChangeNotification(javax.management.AttributeChangeNotification notification)
          Send an AttributeChangeNotification to all registered listeners.
 void sendNotification(javax.management.Notification notification)
          Send a Notification to all registered listeners as a jmx.modelmbean.general notification.
 void sendNotification(java.lang.String message)
          Send a Notification which contains the specified string as a jmx.modelmbean.generic notification.
 void setAttribute(javax.management.Attribute attribute)
          Set the value of a specific attribute of this MBean.
 javax.management.AttributeList setAttributes(javax.management.AttributeList attributes)
          Set the values of several attributes of this MBean.
 void setManagedResource(java.lang.Object resource, java.lang.String type)
          Set the instance handle of the object against which we will execute all methods in this ModelMBean management interface.
 void setModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo info)
          Initialize the ModelMBeanInfo associated with this ModelMBean.
 void store()
          Capture the current state of this MBean instance and write it out to the persistent store.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

attributeBroadcaster

protected BaseNotificationBroadcaster attributeBroadcaster
Notification broadcaster for attribute changes.

generalBroadcaster

protected BaseNotificationBroadcaster generalBroadcaster
Notification broadcaster for general notifications.

info

protected javax.management.modelmbean.ModelMBeanInfo info
The ModelMBeanInfo object that controls our activity.

resource

protected java.lang.Object resource
The managed resource this MBean is associated with (if any).
Constructor Detail

BaseModelMBean

public BaseModelMBean()
               throws javax.management.MBeanException,
                      javax.management.RuntimeOperationsException
Construct a ModelMBean with default ModelMBeanInfo information.
Throws:
javax.management.MBeanException - if the initializer of an object throws an exception
javax.management.RuntimeOperationsException - if an IllegalArgumentException occurs

BaseModelMBean

public BaseModelMBean(javax.management.modelmbean.ModelMBeanInfo info)
               throws javax.management.MBeanException,
                      javax.management.RuntimeOperationsException
Construct a ModelMBean associated with the specified ModelMBeanInfo information.
Parameters:
info - ModelMBeanInfo for this MBean
Throws:
javax.management.MBeanException - if the initializer of an object throws an exception
javax.management.RuntimeOperationsException - if an IllegalArgumentException occurs
Method Detail

getAttribute

public java.lang.Object getAttribute(java.lang.String name)
                              throws javax.management.AttributeNotFoundException,
                                     javax.management.MBeanException,
                                     javax.management.ReflectionException
Obtain and return the value of a specific attribute of this MBean.
Specified by:
getAttribute in interface javax.management.DynamicMBean
Parameters:
name - Name of the requested attribute
Throws:
javax.management.AttributeNotFoundException - if this attribute is not supported by this MBean
javax.management.MBeanException - if the initializer of an object throws an exception
javax.management.ReflectionException - if a Java reflection exception occurs when invoking the getter

getAttributes

public javax.management.AttributeList getAttributes(java.lang.String[] names)
Obtain and return the values of several attributes of this MBean.
Specified by:
getAttributes in interface javax.management.DynamicMBean
Parameters:
names - Names of the requested attributes

getMBeanInfo

public javax.management.MBeanInfo getMBeanInfo()
Return the MBeanInfo object for this MBean.
Specified by:
getMBeanInfo 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
Invoke a particular method on this MBean, and return any returned value.

IMPLEMENTATION NOTE - This implementation will attempt to invoke this method on the MBean itself, or (if not available) on the managed resource object associated with this MBean.

Specified by:
invoke in interface javax.management.DynamicMBean
Parameters:
name - Name of the operation to be invoked
params - Array containing the method parameters of this operation
signature - Array containing the class names representing the signature of this operation
Throws:
javax.management.MBeanException - if the initializer of an object throws an exception
ReflectioNException - if a Java reflection exception occurs when invoking a method

setAttribute

public void setAttribute(javax.management.Attribute attribute)
                  throws javax.management.AttributeNotFoundException,
                         javax.management.MBeanException,
                         javax.management.ReflectionException
Set the value of a specific attribute of this MBean.
Specified by:
setAttribute in interface javax.management.DynamicMBean
Parameters:
attribute - The identification of the attribute to be set and the new value
Throws:
javax.management.AttributeNotFoundException - if this attribute is not supported by this MBean
javax.management.MBeanException - if the initializer of an object throws an exception
javax.management.ReflectionException - if a Java reflection exception occurs when invoking the getter

setAttributes

public javax.management.AttributeList setAttributes(javax.management.AttributeList attributes)
Set the values of several attributes of this MBean.
Specified by:
setAttributes in interface javax.management.DynamicMBean
Parameters:
attributes - THe names and values to be set
Returns:
The list of attributes that were set and their new values

getManagedResource

public java.lang.Object getManagedResource()
                                    throws javax.management.InstanceNotFoundException,
                                           javax.management.modelmbean.InvalidTargetObjectTypeException,
                                           javax.management.MBeanException,
                                           javax.management.RuntimeOperationsException
Get the instance handle of the object against which we execute all methods in this ModelMBean management interface.
Throws:
javax.management.InstanceNotFoundException - if the managed resource object cannot be found
javax.management.MBeanException - if the initializer of the object throws an exception
javax.management.RuntimeOperationsException - if the managed resource or the resource type is null or invalid

setManagedResource

public void setManagedResource(java.lang.Object resource,
                               java.lang.String type)
                        throws javax.management.InstanceNotFoundException,
                               javax.management.modelmbean.InvalidTargetObjectTypeException,
                               javax.management.MBeanException,
                               javax.management.RuntimeOperationsException
Set the instance handle of the object against which we will execute all methods in this ModelMBean management interface.
Specified by:
setManagedResource in interface javax.management.modelmbean.ModelMBean
Parameters:
resource - The resource object to be managed
type - The type of reference for the managed resource ("ObjectReference", "Handle", "IOR", "EJBHandle", or "RMIReference")
Throws:
javax.management.InstanceNotFoundException - if the managed resource object cannot be found
javax.management.modelmbean.InvalidTargetObjectTypeException - if this ModelMBean is asked to handle a reference type it cannot deal with
javax.management.MBeanException - if the initializer of the object throws an exception
javax.management.RuntimeOperationsException - if the managed resource or the resource type is null or invalid

setModelMBeanInfo

public void setModelMBeanInfo(javax.management.modelmbean.ModelMBeanInfo info)
                       throws javax.management.MBeanException,
                              javax.management.RuntimeOperationsException
Initialize the ModelMBeanInfo associated with this ModelMBean. After the information and associated descriptors have been customized, the ModelMBean should be registered with the associated MBeanServer.
Specified by:
setModelMBeanInfo in interface javax.management.modelmbean.ModelMBean
Parameters:
info - The ModelMBeanInfo object to be used by this ModelMBean
Throws:
javax.management.MBeanException - If an exception occurs recording this ModelMBeanInfo information
RuntimeOperations - if the specified parameter is null or invalid

addAttributeChangeNotificationListener

public void addAttributeChangeNotificationListener(javax.management.NotificationListener listener,
                                                   java.lang.String name,
                                                   java.lang.Object handback)
                                            throws java.lang.IllegalArgumentException
Add an attribute change notification event listener to this MBean.
Specified by:
addAttributeChangeNotificationListener in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
Parameters:
listener - Listener that will receive event notifications
name - Name of the attribute of interest, or null to indicate interest in all attributes
handback - Handback object to be sent along with event notifications
Throws:
java.lang.IllegalArgumentException - if the listener parameter is null

removeAttributeChangeNotificationListener

public void removeAttributeChangeNotificationListener(javax.management.NotificationListener listener,
                                                      java.lang.String name)
                                               throws javax.management.ListenerNotFoundException
Remove an attribute change notification event listener from this MBean.
Specified by:
removeAttributeChangeNotificationListener in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
Parameters:
listener - The listener to be removed
name - The attribute name for which no more events are required
Throws:
javax.management.ListenerNotFoundException - if this listener is not registered in the MBean

removeAttributeChangeNotificationListener

public void removeAttributeChangeNotificationListener(javax.management.NotificationListener listener,
                                                      java.lang.String attributeName,
                                                      java.lang.Object handback)
                                               throws javax.management.ListenerNotFoundException
Remove an attribute change notification event listener from this MBean.
Specified by:
removeAttributeChangeNotificationListener in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
Parameters:
listener - The listener to be removed
name - The attribute name for which no more events are required
handback - Handback object to be sent along with event notifications
Throws:
javax.management.ListenerNotFoundException - if this listener is not registered in the MBean

sendAttributeChangeNotification

public void sendAttributeChangeNotification(javax.management.AttributeChangeNotification notification)
                                     throws javax.management.MBeanException,
                                            javax.management.RuntimeOperationsException
Send an AttributeChangeNotification to all registered listeners.
Specified by:
sendAttributeChangeNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
Parameters:
notification - The AttributeChangeNotification that will be passed
Throws:
javax.management.MBeanException - if an object initializer throws an exception
javax.management.RuntimeOperationsException - wraps IllegalArgumentException when the specified notification is null or invalid

sendAttributeChangeNotification

public void sendAttributeChangeNotification(javax.management.Attribute oldValue,
                                            javax.management.Attribute newValue)
                                     throws javax.management.MBeanException,
                                            javax.management.RuntimeOperationsException
Send an AttributeChangeNotification to all registered listeners.
Specified by:
sendAttributeChangeNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
Parameters:
oldValue - The original value of the Attribute
newValue - The new value of the Attribute
Throws:
javax.management.MBeanException - if an object initializer throws an exception
javax.management.RuntimeOperationsException - wraps IllegalArgumentException when the specified notification is null or invalid

sendNotification

public void sendNotification(javax.management.Notification notification)
                      throws javax.management.MBeanException,
                             javax.management.RuntimeOperationsException
Send a Notification to all registered listeners as a jmx.modelmbean.general notification.
Specified by:
sendNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
Parameters:
notification - The Notification that will be passed
Throws:
javax.management.MBeanException - if an object initializer throws an exception
javax.management.RuntimeOperationsException - wraps IllegalArgumentException when the specified notification is null or invalid

sendNotification

public void sendNotification(java.lang.String message)
                      throws javax.management.MBeanException,
                             javax.management.RuntimeOperationsException
Send a Notification which contains the specified string as a jmx.modelmbean.generic notification.
Specified by:
sendNotification in interface javax.management.modelmbean.ModelMBeanNotificationBroadcaster
Parameters:
message - The message string to be passed
Throws:
javax.management.MBeanException - if an object initializer throws an exception
javax.management.RuntimeOperationsException - wraps IllegalArgumentException when the specified notification is null or invalid

addNotificationListener

public void addNotificationListener(javax.management.NotificationListener listener,
                                    javax.management.NotificationFilter filter,
                                    java.lang.Object handback)
                             throws java.lang.IllegalArgumentException
Add a notification event listener to this MBean.
Specified by:
addNotificationListener in interface javax.management.NotificationBroadcaster
Parameters:
listener - Listener that will receive event notifications
filter - Filter object used to filter event notifications actually delivered, or null for no filtering
handback - Handback object to be sent along with event notifications
Throws:
java.lang.IllegalArgumentException - if the listener parameter is null

getNotificationInfo

public javax.management.MBeanNotificationInfo[] getNotificationInfo()
Return an MBeanNotificationInfo object describing the notifications sent by this MBean.
Specified by:
getNotificationInfo in interface javax.management.NotificationBroadcaster

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener)
                                throws javax.management.ListenerNotFoundException
Remove a notification event listener from this MBean.
Specified by:
removeNotificationListener in interface javax.management.NotificationBroadcaster
Parameters:
listener - The listener to be removed (any and all registrations for this listener will be eliminated)
Throws:
javax.management.ListenerNotFoundException - if this listener is not registered in the MBean

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener,
                                       java.lang.Object handback)
                                throws javax.management.ListenerNotFoundException
Remove a notification event listener from this MBean.
Specified by:
removeNotificationListener in interface javax.management.NotificationBroadcaster
Parameters:
listener - The listener to be removed (any and all registrations for this listener will be eliminated)
handback - Handback object to be sent along with event notifications
Throws:
javax.management.ListenerNotFoundException - if this listener is not registered in the MBean

removeNotificationListener

public void removeNotificationListener(javax.management.NotificationListener listener,
                                       javax.management.NotificationFilter filter,
                                       java.lang.Object handback)
                                throws javax.management.ListenerNotFoundException
Remove a notification event listener from this MBean.
Specified by:
removeNotificationListener in interface javax.management.NotificationBroadcaster
Parameters:
listener - The listener to be removed (any and all registrations for this listener will be eliminated)
filter - Filter object used to filter event notifications actually delivered, or null for no filtering
handback - Handback object to be sent along with event notifications
Throws:
javax.management.ListenerNotFoundException - if this listener is not registered in the MBean

load

public void load()
          throws javax.management.InstanceNotFoundException,
                 javax.management.MBeanException,
                 javax.management.RuntimeOperationsException
Instantiates this MBean instance from data found in the persistent store. The data loaded could include attribute and operation values. This method should be called during construction or initialization of the instance, and before the MBean is registered with the MBeanServer.

IMPLEMENTATION NOTE - This implementation does not support persistence.

Specified by:
load in interface javax.management.PersistentMBean
Throws:
javax.management.InstanceNotFoundException - if the managed resource object cannot be found
javax.management.MBeanException - if the initializer of the object throws an exception
javax.management.RuntimeOperationsException - if an exception is reported by the persistence mechanism

store

public void store()
           throws javax.management.InstanceNotFoundException,
                  javax.management.MBeanException,
                  javax.management.RuntimeOperationsException
Capture the current state of this MBean instance and write it out to the persistent store. The state stored could include attribute and operation values. If one of these methods of persistence is not supported, a "service not found" exception will be thrown.

IMPLEMENTATION NOTE - This implementation does not support persistence.

Specified by:
store in interface javax.management.PersistentMBean
Throws:
javax.management.InstanceNotFoundException - if the managed resource object cannot be found
javax.management.MBeanException - if the initializer of the object throws an exception, or persistence is not supported
javax.management.RuntimeOperationsException - if an exception is reported by the persistence mechanism

createDefaultModelMBeanInfo

protected javax.management.modelmbean.ModelMBeanInfo createDefaultModelMBeanInfo()
Create and return a default ModelMBeanInfo object.

isModelMBeanInfoValid

protected boolean isModelMBeanInfoValid(javax.management.modelmbean.ModelMBeanInfo info)
Is the specified ModelMBeanInfo instance valid?

IMPLEMENTATION NOTE - This implementation does not check anything, but this method can be overridden as required.

Parameters:
info - The ModelMBeanInfo object to check


Copyright (c) 2001-2002 - Apache Software Foundation