org.apache.tomcat.util.modeler

Class BaseModelMBean

public class BaseModelMBean extends Object implements DynamicMBean, MBeanRegistration, ModelMBeanNotificationBroadcaster

Basic implementation of the DynamicMBean 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. Limitations:

Author: Craig R. McClanahan Costin Manolache

Field Summary
protected BaseNotificationBroadcasterattributeBroadcaster
Notification broadcaster for attribute changes.
protected BaseNotificationBroadcastergeneralBroadcaster
Notification broadcaster for general notifications.
protected ManagedBeanmanagedBean
Metadata for the mbean instance.
protected ObjectNameoname
protected Objectresource
The managed resource this MBean is associated with (if any).
protected StringresourceType
Constructor Summary
protected BaseModelMBean()
Construct a ModelMBean with default ModelMBeanInfo information.
Method Summary
voidaddAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback)
Add an attribute change notification event listener to this MBean.
voidaddNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
Add a notification event listener to this MBean.
ObjectgetAttribute(String name)
Obtain and return the value of a specific attribute of this MBean.
AttributeListgetAttributes(String[] names)
Obtain and return the values of several attributes of this MBean.
StringgetClassName()
ObjectNamegetJmxName()
ObjectgetManagedResource()
Get the instance handle of the object against which we execute all methods in this ModelMBean management interface.
MBeanInfogetMBeanInfo()
Return the MBeanInfo object for this MBean.
StringgetModelerType()
Set the type of the mbean.
MBeanNotificationInfo[]getNotificationInfo()
Return an MBeanNotificationInfo object describing the notifications sent by this MBean.
StringgetObjectName()
Objectinvoke(String name, Object[] params, String[] signature)
Invoke a particular method on this MBean, and return any returned value.
voidpostDeregister()
voidpostRegister(Boolean registrationDone)
voidpreDeregister()
ObjectNamepreRegister(MBeanServer server, ObjectName name)
Is the specified ModelMBeanInfo instance valid?
voidremoveAttributeChangeNotificationListener(NotificationListener listener, String name)
Remove an attribute change notification event listener from this MBean.
voidremoveAttributeChangeNotificationListener(NotificationListener listener, String attributeName, Object handback)
Remove an attribute change notification event listener from this MBean.
voidremoveNotificationListener(NotificationListener listener)
Remove a notification event listener from this MBean.
voidremoveNotificationListener(NotificationListener listener, Object handback)
Remove a notification event listener from this MBean.
voidremoveNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
Remove a notification event listener from this MBean.
voidsendAttributeChangeNotification(AttributeChangeNotification notification)
Send an AttributeChangeNotification to all registered listeners.
voidsendAttributeChangeNotification(Attribute oldValue, Attribute newValue)
Send an AttributeChangeNotification to all registered listeners.
voidsendNotification(Notification notification)
Send a Notification to all registered listeners as a jmx.modelmbean.general notification.
voidsendNotification(String message)
Send a Notification which contains the specified string as a jmx.modelmbean.generic notification.
voidsetAttribute(Attribute attribute)
Set the value of a specific attribute of this MBean.
AttributeListsetAttributes(AttributeList attributes)
Set the values of several attributes of this MBean.
voidsetManagedBean(ManagedBean managedBean)
voidsetManagedResource(Object resource, String type)
Set the instance handle of the object against which we will execute all methods in this ModelMBean management interface.
StringtoString()

Field Detail

attributeBroadcaster

protected BaseNotificationBroadcaster attributeBroadcaster
Notification broadcaster for attribute changes.

generalBroadcaster

protected BaseNotificationBroadcaster generalBroadcaster
Notification broadcaster for general notifications.

managedBean

protected ManagedBean managedBean
Metadata for the mbean instance.

oname

protected ObjectName oname

resource

protected Object resource
The managed resource this MBean is associated with (if any).

resourceType

protected String resourceType

Constructor Detail

BaseModelMBean

protected BaseModelMBean()
Construct a ModelMBean with default ModelMBeanInfo information.

Throws: MBeanException if the initializer of an object throws an exception RuntimeOperationsException if an IllegalArgumentException occurs

Method Detail

addAttributeChangeNotificationListener

public void addAttributeChangeNotificationListener(NotificationListener listener, String name, Object handback)
Add an attribute change notification event listener to this MBean.

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: IllegalArgumentException if the listener parameter is null

addNotificationListener

public void addNotificationListener(NotificationListener listener, NotificationFilter filter, Object handback)
Add a notification event listener to this MBean.

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: IllegalArgumentException if the listener parameter is null

getAttribute

public Object getAttribute(String name)
Obtain and return the value of a specific attribute of this MBean.

Parameters: name Name of the requested attribute

Throws: AttributeNotFoundException if this attribute is not supported by this MBean MBeanException if the initializer of an object throws an exception ReflectionException if a Java reflection exception occurs when invoking the getter

getAttributes

public AttributeList getAttributes(String[] names)
Obtain and return the values of several attributes of this MBean.

Parameters: names Names of the requested attributes

getClassName

public String getClassName()

getJmxName

public ObjectName getJmxName()

getManagedResource

public Object getManagedResource()
Get 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 found MBeanException if the initializer of the object throws an exception RuntimeOperationsException if the managed resource or the resource type is null or invalid

getMBeanInfo

public MBeanInfo getMBeanInfo()
Return the MBeanInfo object for this MBean.

getModelerType

public String getModelerType()
Set the type of the mbean. This is used as a key to locate the description in the Registry.

getNotificationInfo

public MBeanNotificationInfo[] getNotificationInfo()
Return an MBeanNotificationInfo object describing the notifications sent by this MBean.

getObjectName

public String getObjectName()

invoke

public Object invoke(String name, Object[] params, String[] signature)
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.

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: MBeanException if the initializer of an object throws an exception ReflectioNException if a Java reflection exception occurs when invoking a method

postDeregister

public void postDeregister()

postRegister

public void postRegister(Boolean registrationDone)

preDeregister

public void preDeregister()

preRegister

public ObjectName preRegister(MBeanServer server, ObjectName name)
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

removeAttributeChangeNotificationListener

public void removeAttributeChangeNotificationListener(NotificationListener listener, String name)
Remove an attribute change notification event listener from this MBean.

Parameters: listener The listener to be removed name 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)
Remove an attribute change notification event listener from this MBean.

Parameters: listener The listener to be removed attributeName The attribute name for which no more events are required 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)
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)

Throws: ListenerNotFoundException if this listener is not registered in the MBean

removeNotificationListener

public void removeNotificationListener(NotificationListener listener, Object handback)
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)
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, or null for no filtering handback 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)
Send an AttributeChangeNotification to all registered listeners.

Parameters: notification The AttributeChangeNotification that will be passed

Throws: MBeanException if an object initializer throws an exception RuntimeOperationsException wraps IllegalArgumentException when the specified notification is null or invalid

sendAttributeChangeNotification

public void sendAttributeChangeNotification(Attribute oldValue, Attribute newValue)
Send an AttributeChangeNotification to all registered listeners.

Parameters: oldValue The original value of the Attribute newValue The new value of the Attribute

Throws: MBeanException if an object initializer throws an exception RuntimeOperationsException wraps IllegalArgumentException when the specified notification is null or invalid

sendNotification

public void sendNotification(Notification notification)
Send a Notification to all registered listeners as a jmx.modelmbean.general notification.

Parameters: notification The Notification that will be passed

Throws: MBeanException if an object initializer throws an exception RuntimeOperationsException wraps IllegalArgumentException when the specified notification is null or invalid

sendNotification

public void sendNotification(String message)
Send a Notification which contains the specified string as a jmx.modelmbean.generic notification.

Parameters: message The message string to be passed

Throws: MBeanException if an object initializer throws an exception RuntimeOperationsException wraps IllegalArgumentException when the specified notification is null or invalid

setAttribute

public void setAttribute(Attribute attribute)
Set the value of a specific attribute of this MBean.

Parameters: attribute The identification of the attribute to be set and the new value

Throws: AttributeNotFoundException if this attribute is not supported by this MBean MBeanException if the initializer of an object throws an exception ReflectionException if a Java reflection exception occurs when invoking the getter

setAttributes

public AttributeList setAttributes(AttributeList attributes)
Set the values of several attributes of this MBean.

Parameters: attributes THe names and values to be set

Returns: The list of attributes that were set and their new values

setManagedBean

public void setManagedBean(ManagedBean managedBean)

setManagedResource

public 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. 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. The caller can provide the mbean instance or the object name to the resource, if needed.

Parameters: resource The resource object to be managed type The type of reference for the managed resource ("ObjectReference", "Handle", "IOR", "EJBHandle", or "RMIReference")

Throws: InstanceNotFoundException if the managed resource object cannot be found InvalidTargetObjectTypeException if this ModelMBean is asked to handle a reference type it cannot deal with MBeanException if the initializer of the object throws an exception RuntimeOperationsException if the managed resource or the resource type is null or invalid

toString

public String toString()
Copyright © 2000-2011 Apache Software Foundation. All Rights Reserved.