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
NO_ARGS_PARAM
(package private) static final Object[] NO_ARGS_PARAM
NO_ARGS_PARAM_SIG
(package private) static final Class[] NO_ARGS_PARAM_SIG
attributes
protected HashMap attributes
Attribute values. XXX That can be stored in the value Field
getAttMap
private Hashtable getAttMap
info
protected ModelMBeanInfo info
The ModelMBeanInfo
object that controls our activity.
invokeAttMap
private Hashtable invokeAttMap
log
private static Log log
oname
protected ObjectName oname
registry
protected Registry registry
Registry we are associated with
resource
protected Object resource
The managed resource this MBean is associated with (if any).
resourceType
protected String resourceType
setAttMap
private Hashtable setAttMap
source
protected ModelerSource source
Source object used to read this mbean. Can be used to
persist the mbean
addAttributeChangeNotificationListener
public void addAttributeChangeNotificationListener(NotificationListener listener,
String name,
Object handback)
throws IllegalArgumentException
Add an attribute change notification event listener to this MBean.
listener
- Listener that will receive event notificationsname
- Name of the attribute of interest, or null
to indicate interest in all attributeshandback
- Handback object to be sent along with event
notifications
addNotificationListener
public void addNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
throws IllegalArgumentException
Add a notification event listener to this MBean.
listener
- Listener that will receive event notificationsfilter
- Filter object used to filter event notifications
actually delivered, or null
for no filteringhandback
- Handback object to be sent along with event
notifications
createDefaultModelMBeanInfo
protected ModelMBeanInfo createDefaultModelMBeanInfo()
Create and return a default ModelMBeanInfo
object.
createResource
protected void createResource()
Set the type of the mbean. This is used as a key to locate
the description in the Registry.
getAttribute
public Object getAttribute(String name)
throws AttributeNotFoundException,
MBeanException,
ReflectionException
Obtain and return the value of a specific attribute of this MBean.
name
- Name of the requested attribute
getAttributeClass
private Class getAttributeClass(String signature)
throws ReflectionException
getAttributes
public AttributeList getAttributes(names[] )
Obtain and return the values of several attributes of this MBean.
getClassName
public String getClassName()
getMBeanInfo
public MBeanInfo getMBeanInfo()
Return the MBeanInfo
object for this MBean.
getManagedResource
public Object getManagedResource()
throws InstanceNotFoundException,
InvalidTargetObjectTypeException,
MBeanException,
RuntimeOperationsException
Get the instance handle of the object against which we execute
all methods in this ModelMBean management interface.
getModelerType
public String getModelerType()
getNotificationInfo
public MBeanNotificationInfo[] getNotificationInfo()
Return an MBeanNotificationInfo
object describing the
notifications sent by this MBean.
getObjectName
public ObjectName getObjectName()
getRegistry
public Registry getRegistry()
initModelInfo
protected void initModelInfo(String type)
Set the type of the mbean. This is used as a key to locate
the description in the Registry.
type
- the type of classname of the modeled object
invoke
public Object invoke(String name,
params[] ,
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.
name
- Name of the operation to be invoked
isModelMBeanInfoValid
protected boolean isModelMBeanInfoValid(ModelMBeanInfo info)
Is the specified
ModelMBeanInfo
instance valid?
IMPLEMENTATION NOTE - This implementation
does not check anything, but this method can be overridden
as required.
info
- The ModelMBeanInfo object to check
load
public void load()
throws InstanceNotFoundException,
MBeanException,
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.
postDeregister
public void postDeregister()
postRegister
public void postRegister(Boolean registrationDone)
preDeregister
public void preDeregister()
throws Exception
preRegister
public ObjectName preRegister(MBeanServer server,
ObjectName name)
throws Exception
removeAttributeChangeNotificationListener
public void removeAttributeChangeNotificationListener(NotificationListener listener,
String name)
throws ListenerNotFoundException
Remove an attribute change notification event listener from
this MBean.
listener
- The listener to be removedname
- The attribute name for which no more events are required
removeAttributeChangeNotificationListener
public void removeAttributeChangeNotificationListener(NotificationListener listener,
String attributeName,
Object handback)
throws ListenerNotFoundException
Remove an attribute change notification event listener from
this MBean.
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
removeNotificationListener
public void removeNotificationListener(NotificationListener listener)
throws ListenerNotFoundException
Remove a notification event listener from this MBean.
listener
- The listener to be removed (any and all registrations
for this listener will be eliminated)
removeNotificationListener
public void removeNotificationListener(NotificationListener listener,
NotificationFilter filter,
Object handback)
throws ListenerNotFoundException
Remove a notification event listener from this MBean.
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 filteringhandback
- Handback object to be sent along with event
notifications
removeNotificationListener
public void removeNotificationListener(NotificationListener listener,
Object handback)
throws ListenerNotFoundException
Remove a notification event listener from this MBean.
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
sendAttributeChangeNotification
public void sendAttributeChangeNotification(Attribute oldValue,
Attribute newValue)
throws MBeanException,
RuntimeOperationsException
Send an AttributeChangeNotification
to all registered
listeners.
oldValue
- The original value of the Attribute
newValue
- The new value of the Attribute
sendAttributeChangeNotification
public void sendAttributeChangeNotification(AttributeChangeNotification notification)
throws MBeanException,
RuntimeOperationsException
Send an AttributeChangeNotification
to all registered
listeners.
notification
- The AttributeChangeNotification
that will be passed
sendNotification
public void sendNotification(Notification notification)
throws MBeanException,
RuntimeOperationsException
Send a Notification
to all registered listeners as a
jmx.modelmbean.general
notification.
notification
- The Notification
that will be passed
sendNotification
public void sendNotification(String message)
throws MBeanException,
RuntimeOperationsException
Send a Notification
which contains the specified string
as a jmx.modelmbean.generic
notification.
message
- The message string to be passed
setAttribute
public void setAttribute(Attribute attribute)
throws AttributeNotFoundException,
MBeanException,
ReflectionException
Set the value of a specific attribute of this MBean.
attribute
- The identification of the attribute to be set
and the new value
setAttributes
public AttributeList setAttributes(AttributeList attributes)
Set the values of several attributes of this MBean.
attributes
- THe names and values to be set
- The list of attributes that were set and their new values
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.
resource
- The resource object to be managedtype
- The type of reference for the managed resource
("ObjectReference", "Handle", "IOR", "EJBHandle", or
"RMIReference")
setModelMBeanInfo
public void setModelMBeanInfo(ModelMBeanInfo info)
throws MBeanException,
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
.
Currently the model can be set after registration. This behavior is
deprecated and won't be supported in future versions.
info
- The ModelMBeanInfo object to be used by this ModelMBean
setModeledType
public void setModeledType(String type)
Set the type of the mbean. This is used as a key to locate
the description in the Registry.
type
- the type of classname of the modeled object
setRegistry
public void setRegistry(Registry registry)
store
public void store()
throws InstanceNotFoundException,
MBeanException,
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.
toString
public String toString()