Class BaseModelMBean
- All Implemented Interfaces:
DynamicMBean
,MBeanRegistration
,ModelMBean
,ModelMBeanNotificationBroadcaster
,NotificationBroadcaster
,PersistentMBean
- Direct Known Subclasses:
JndiJmx
,MBeanProxy
Basic implementation of the ModelMBean
interface, which
supports the minimal requirements of the interface contract.
This can be used directly to wrap an existing java bean, or inside an mlet or anywhere an MBean would be used. The String parameter passed to the constructor will be used to construct an instance of the real object that we wrap. Limitations:
- Only managed resources of type
objectReference
are supportd. - Caching of attribute values and operation results is not supported.
All calls to
invoke()
are immediately executed. - Logging (under control of descriptors) is not supported.
- Persistence of MBean attributes and operations is not supported.
- All classes referenced as attribute types, operation parameters, or
operation return values must be one of the following:
- One of the Java primitive types (boolean, byte, char, double, float, integer, long, short). Corresponding value will be wrapped in the appropriate wrapper class automatically.
- Operations that return no value should declare a return type of
void
.
- Attribute caching is not supported
- Version:
- $Revision: 480402 $ $Date: 2006-11-29 04:43:23 +0000 (Wed, 29 Nov 2006) $
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected BaseNotificationBroadcaster
Notification broadcaster for attribute changes.protected HashMap
Attribute values.protected BaseNotificationBroadcaster
Notification broadcaster for general notifications.private Hashtable
protected ModelMBeanInfo
TheModelMBeanInfo
object that controls our activity.private Hashtable
private static org.apache.commons.logging.Log
(package private) static final Object[]
(package private) static final Class[]
protected ObjectName
protected Registry
Registry we are associated withprotected Object
The managed resource this MBean is associated with (if any).protected String
private Hashtable
protected ModelerSource
Source object used to read this mbean. -
Constructor Summary
ConstructorsConstructorDescriptionConstruct aModelMBean
with defaultModelMBeanInfo
information.BaseModelMBean
(String type) Construct a ModelMBean of a specified type.BaseModelMBean
(String type, ModelerSource source) BaseModelMBean
(ModelMBeanInfo info) Construct aModelMBean
associated with the specifiedModelMBeanInfo
information. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addAttributeChangeNotificationListener
(NotificationListener listener, String name, Object handback) Add an attribute change notification event listener to this MBean.void
addNotificationListener
(NotificationListener listener, NotificationFilter filter, Object handback) Add a notification event listener to this MBean.protected ModelMBeanInfo
Create and return a defaultModelMBeanInfo
object.protected void
Set the type of the mbean.getAttribute
(String name) Obtain and return the value of a specific attribute of this MBean.private Class
getAttributeClass
(String signature) getAttributes
(String[] names) Obtain and return the values of several attributes of this MBean.Get the instance handle of the object against which we execute all methods in this ModelMBean management interface.Return theMBeanInfo
object for this MBean.Return anMBeanNotificationInfo
object describing the notifications sent by this MBean.protected void
initModelInfo
(String type) Set the type of the mbean.Invoke a particular method on this MBean, and return any returned value.protected boolean
Is the specifiedModelMBeanInfo
instance valid?void
load()
Instantiates this MBean instance from data found in the persistent store.void
void
postRegister
(Boolean registrationDone) void
preRegister
(MBeanServer server, ObjectName name) void
removeAttributeChangeNotificationListener
(NotificationListener listener, String name) Remove an attribute change notification event listener from this MBean.void
removeAttributeChangeNotificationListener
(NotificationListener listener, String attributeName, Object handback) Remove an attribute change notification event listener from this MBean.void
Remove a notification event listener from this MBean.void
removeNotificationListener
(NotificationListener listener, Object handback) Remove a notification event listener from this MBean.void
removeNotificationListener
(NotificationListener listener, NotificationFilter filter, Object handback) Remove a notification event listener from this MBean.void
sendAttributeChangeNotification
(AttributeChangeNotification notification) Send anAttributeChangeNotification
to all registered listeners.void
sendAttributeChangeNotification
(Attribute oldValue, Attribute newValue) Send anAttributeChangeNotification
to all registered listeners.void
sendNotification
(String message) Send aNotification
which contains the specified string as ajmx.modelmbean.generic
notification.void
sendNotification
(Notification notification) Send aNotification
to all registered listeners as ajmx.modelmbean.general
notification.void
setAttribute
(Attribute attribute) Set the value of a specific attribute of this MBean.setAttributes
(AttributeList attributes) Set the values of several attributes of this MBean.void
setManagedResource
(Object resource, String type) Set the instance handle of the object against which we will execute all methods in this ModelMBean management interface.void
setModeledType
(String type) Set the type of the mbean.void
Initialize theModelMBeanInfo
associated with thisModelMBean
.void
setRegistry
(Registry registry) void
store()
Capture the current state of this MBean instance and write it out to the persistent store.toString()
-
Field Details
-
log
private static org.apache.commons.logging.Log log -
attributeBroadcaster
Notification broadcaster for attribute changes. -
registry
Registry we are associated with -
generalBroadcaster
Notification broadcaster for general notifications. -
oname
-
info
TheModelMBeanInfo
object that controls our activity. -
resource
The managed resource this MBean is associated with (if any). -
resourceType
-
source
Source object used to read this mbean. Can be used to persist the mbean -
attributes
Attribute values. XXX That can be stored in the value Field -
NO_ARGS_PARAM
-
NO_ARGS_PARAM_SIG
-
getAttMap
-
setAttMap
-
invokeAttMap
-
-
Constructor Details
-
BaseModelMBean
Construct aModelMBean
with defaultModelMBeanInfo
information.- Throws:
MBeanException
- if the initializer of an object throws an exceptionRuntimeOperationsException
- if an IllegalArgumentException occurs
-
BaseModelMBean
Construct aModelMBean
associated with the specifiedModelMBeanInfo
information.- Parameters:
info
- ModelMBeanInfo for this MBean- Throws:
MBeanException
- if the initializer of an object throws an exceptionRuntimeOperationsException
- if an IllegalArgumentException occurs
-
BaseModelMBean
Construct a ModelMBean of a specified type. The type can be a class name or the key used in one of the descriptors. If no descriptor is available, we'll first try to locate one in the same package with the class, then use introspection. The mbean resource will be created.- Parameters:
type
- Class name or the type key used in the descriptor.- Throws:
MBeanException
RuntimeOperationsException
-
BaseModelMBean
public BaseModelMBean(String type, ModelerSource source) throws MBeanException, RuntimeOperationsException
-
-
Method Details
-
getAttribute
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException Obtain and return the value of a specific attribute of this MBean.- Specified by:
getAttribute
in interfaceDynamicMBean
- Parameters:
name
- Name of the requested attribute- Throws:
AttributeNotFoundException
- if this attribute is not supported by this MBeanMBeanException
- if the initializer of an object throws an exceptionReflectionException
- if a Java reflection exception occurs when invoking the getter
-
getAttributes
Obtain and return the values of several attributes of this MBean.- Specified by:
getAttributes
in interfaceDynamicMBean
- Parameters:
names
- Names of the requested attributes
-
getMBeanInfo
Return theMBeanInfo
object for this MBean.- Specified by:
getMBeanInfo
in interfaceDynamicMBean
-
invoke
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, 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 interfaceDynamicMBean
- Parameters:
name
- Name of the operation to be invokedparams
- Array containing the method parameters of this operationsignature
- Array containing the class names representing the signature of this operation
-
getAttributeClass
- Throws:
ReflectionException
-
setAttribute
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, MBeanException, ReflectionException Set the value of a specific attribute of this MBean.- Specified by:
setAttribute
in interfaceDynamicMBean
- Parameters:
attribute
- The identification of the attribute to be set and the new value- Throws:
AttributeNotFoundException
- if this attribute is not supported by this MBeanMBeanException
- if the initializer of an object throws an exceptionReflectionException
- if a Java reflection exception occurs when invoking the getter
-
toString
-
setAttributes
Set the values of several attributes of this MBean.- Specified by:
setAttributes
in interfaceDynamicMBean
- Parameters:
attributes
- THe names and values to be set- Returns:
- The list of attributes that were set and their new values
-
getManagedResource
public Object getManagedResource() throws InstanceNotFoundException, InvalidTargetObjectTypeException, MBeanException, RuntimeOperationsExceptionGet the instance handle of the object against which we execute all methods in this ModelMBean management interface.- Throws:
InstanceNotFoundException
- if the managed resource object cannot be foundMBeanException
- if the initializer of the object throws an exceptionRuntimeOperationsException
- if the managed resource or the resource type isnull
or invalidInvalidTargetObjectTypeException
-
setManagedResource
public void setManagedResource(Object resource, String type) throws InstanceNotFoundException, InvalidTargetObjectTypeException, MBeanException, RuntimeOperationsException Set the instance handle of the object against which we will execute all methods in this ModelMBean management interface. This method will detect and call "setModelMbean" method. A resource can implement this method to get a reference to the model mbean. The reference can be used to send notification and access the registry.- Specified by:
setManagedResource
in interfaceModelMBean
- Parameters:
resource
- The resource object to be managedtype
- The type of reference for the managed resource ("ObjectReference", "Handle", "IOR", "EJBHandle", or "RMIReference")- Throws:
InstanceNotFoundException
- if the managed resource object cannot be foundInvalidTargetObjectTypeException
- if this ModelMBean is asked to handle a reference type it cannot deal withMBeanException
- if the initializer of the object throws an exceptionRuntimeOperationsException
- if the managed resource or the resource type isnull
or invalid
-
setModelMBeanInfo
public void setModelMBeanInfo(ModelMBeanInfo info) throws MBeanException, RuntimeOperationsException Initialize theModelMBeanInfo
associated with thisModelMBean
. After the information and associated descriptors have been customized, theModelMBean
should be registered with the associatedMBeanServer
. Currently the model can be set after registration. This behavior is deprecated and won't be supported in future versions.- Specified by:
setModelMBeanInfo
in interfaceModelMBean
- Parameters:
info
- The ModelMBeanInfo object to be used by this ModelMBean
-
addAttributeChangeNotificationListener
public void addAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback) throws IllegalArgumentException Add an attribute change notification event listener to this MBean.- Specified by:
addAttributeChangeNotificationListener
in interfaceModelMBeanNotificationBroadcaster
- Parameters:
listener
- Listener that will receive event notificationsname
- Name of the attribute of interest, ornull
to indicate interest in all attributeshandback
- Handback object to be sent along with event notifications- Throws:
IllegalArgumentException
- if the listener parameter is null
-
removeAttributeChangeNotificationListener
public void removeAttributeChangeNotificationListener(NotificationListener listener, String name) throws ListenerNotFoundException Remove an attribute change notification event listener from this MBean.- Specified by:
removeAttributeChangeNotificationListener
in interfaceModelMBeanNotificationBroadcaster
- Parameters:
listener
- The listener to be removedname
- The attribute name for which no more events are required- Throws:
ListenerNotFoundException
- if this listener is not registered in the MBean
-
removeAttributeChangeNotificationListener
public void removeAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback) throws ListenerNotFoundException Remove an attribute change notification event listener from this MBean.- Parameters:
listener
- The listener to be removedattributeName
- The attribute name for which no more events are requiredhandback
- Handback object to be sent along with event notifications- Throws:
ListenerNotFoundException
- if this listener is not registered in the MBean
-
sendAttributeChangeNotification
public void sendAttributeChangeNotification(AttributeChangeNotification notification) throws MBeanException, RuntimeOperationsException Send anAttributeChangeNotification
to all registered listeners.- Specified by:
sendAttributeChangeNotification
in interfaceModelMBeanNotificationBroadcaster
- Parameters:
notification
- TheAttributeChangeNotification
that will be passed- Throws:
MBeanException
- if an object initializer throws an exceptionRuntimeOperationsException
- wraps IllegalArgumentException when the specified notification isnull
or invalid
-
sendAttributeChangeNotification
public void sendAttributeChangeNotification(Attribute oldValue, Attribute newValue) throws MBeanException, RuntimeOperationsException Send anAttributeChangeNotification
to all registered listeners.- Specified by:
sendAttributeChangeNotification
in interfaceModelMBeanNotificationBroadcaster
- Parameters:
oldValue
- The original value of theAttribute
newValue
- The new value of theAttribute
- Throws:
MBeanException
- if an object initializer throws an exceptionRuntimeOperationsException
- wraps IllegalArgumentException when the specified notification isnull
or invalid
-
sendNotification
public void sendNotification(Notification notification) throws MBeanException, RuntimeOperationsException Send aNotification
to all registered listeners as ajmx.modelmbean.general
notification.- Specified by:
sendNotification
in interfaceModelMBeanNotificationBroadcaster
- Parameters:
notification
- TheNotification
that will be passed- Throws:
MBeanException
- if an object initializer throws an exceptionRuntimeOperationsException
- wraps IllegalArgumentException when the specified notification isnull
or invalid
-
sendNotification
Send aNotification
which contains the specified string as ajmx.modelmbean.generic
notification.- Specified by:
sendNotification
in interfaceModelMBeanNotificationBroadcaster
- Parameters:
message
- The message string to be passed- Throws:
MBeanException
- if an object initializer throws an exceptionRuntimeOperationsException
- wraps IllegalArgumentException when the specified notification isnull
or invalid
-
addNotificationListener
public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws IllegalArgumentException Add a notification event listener to this MBean.- Specified by:
addNotificationListener
in interfaceNotificationBroadcaster
- Parameters:
listener
- Listener that will receive event notificationsfilter
- Filter object used to filter event notifications actually delivered, ornull
for no filteringhandback
- Handback object to be sent along with event notifications- Throws:
IllegalArgumentException
- if the listener parameter is null
-
getNotificationInfo
Return anMBeanNotificationInfo
object describing the notifications sent by this MBean.- Specified by:
getNotificationInfo
in interfaceNotificationBroadcaster
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener) throws ListenerNotFoundException Remove a notification event listener from this MBean.- Specified by:
removeNotificationListener
in interfaceNotificationBroadcaster
- Parameters:
listener
- The listener to be removed (any and all registrations for this listener will be eliminated)- Throws:
ListenerNotFoundException
- if this listener is not registered in the MBean
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener, Object handback) throws ListenerNotFoundException Remove a notification event listener from this MBean.- 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:
ListenerNotFoundException
- if this listener is not registered in the MBean
-
removeNotificationListener
public void removeNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback) throws ListenerNotFoundException Remove a notification event listener from this MBean.- 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, ornull
for no filteringhandback
- Handback object to be sent along with event notifications- Throws:
ListenerNotFoundException
- if this listener is not registered in the MBean
-
load
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 theMBeanServer
.IMPLEMENTATION NOTE - This implementation does not support persistence.
- Specified by:
load
in interfacePersistentMBean
- Throws:
InstanceNotFoundException
- if the managed resource object cannot be foundMBeanException
- if the initializer of the object throws an exceptionRuntimeOperationsException
- if an exception is reported by the persistence mechanism
-
store
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 interfacePersistentMBean
- Throws:
InstanceNotFoundException
- if the managed resource object cannot be foundMBeanException
- if the initializer of the object throws an exception, or persistence is not supportedRuntimeOperationsException
- if an exception is reported by the persistence mechanism
-
setModeledType
Set the type of the mbean. This is used as a key to locate the description in the Registry.- Parameters:
type
- the type of classname of the modeled object
-
initModelInfo
Set the type of the mbean. This is used as a key to locate the description in the Registry.- Parameters:
type
- the type of classname of the modeled object
-
createResource
protected void createResource()Set the type of the mbean. This is used as a key to locate the description in the Registry. -
getModelerType
-
getClassName
-
getJmxName
-
getObjectName
-
setRegistry
-
getRegistry
-
createDefaultModelMBeanInfo
Create and return a defaultModelMBeanInfo
object. -
isModelMBeanInfoValid
Is the specifiedModelMBeanInfo
instance valid?IMPLEMENTATION NOTE - This implementation does not check anything, but this method can be overridden as required.
- Parameters:
info
- TheModelMBeanInfo object to check
-
preRegister
- Specified by:
preRegister
in interfaceMBeanRegistration
- Throws:
Exception
-
postRegister
- Specified by:
postRegister
in interfaceMBeanRegistration
-
preDeregister
- Specified by:
preDeregister
in interfaceMBeanRegistration
- Throws:
Exception
-
postDeregister
public void postDeregister()- Specified by:
postDeregister
in interfaceMBeanRegistration
-