Package org.apache.tomcat.util.modeler
Class BaseModelMBean
- java.lang.Object
-
- org.apache.tomcat.util.modeler.BaseModelMBean
-
- All Implemented Interfaces:
DynamicMBean
,MBeanRegistration
,ModelMBeanNotificationBroadcaster
,NotificationBroadcaster
- Direct Known Subclasses:
BaseCatalinaMBean
,DataSourceUserDatabaseMBean
,GroupMBean
,NamingResourcesMBean
,RequestGroupInfo
,RoleMBean
,SparseUserDatabaseMBean
,UpgradeGroupInfo
,UserMBean
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:
- Only managed resources of type
objectReference
are supported. - Caching of attribute values and operation results is not supported.
All calls to
invoke()
are immediately executed. - 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
- Author:
- Craig R. McClanahan, Costin Manolache
-
-
Field Summary
Fields Modifier and Type Field Description protected BaseNotificationBroadcaster
attributeBroadcaster
Notification broadcaster for attribute changes.protected BaseNotificationBroadcaster
generalBroadcaster
Notification broadcaster for general notifications.protected ManagedBean
managedBean
Metadata for the mbean instance.protected ObjectName
oname
protected Object
resource
The managed resource this MBean is associated with (if any).protected String
resourceType
-
Constructor Summary
Constructors Constructor Description BaseModelMBean()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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.Object
getAttribute(String name)
Obtain and return the value of a specific attribute of this MBean.AttributeList
getAttributes(String[] names)
Obtain and return the values of several attributes of this MBean.String
getClassName()
ObjectName
getJmxName()
Object
getManagedResource()
Get the instance handle of the object against which we execute all methods in this ModelMBean management interface.MBeanInfo
getMBeanInfo()
Return theMBeanInfo
object for this MBean.String
getModelerType()
MBeanNotificationInfo[]
getNotificationInfo()
Return anMBeanNotificationInfo
object describing the notifications sent by this MBean.String
getObjectName()
Object
invoke(String name, Object[] params, String[] signature)
Invoke a particular method on this MBean, and return any returned value.void
postDeregister()
void
postRegister(Boolean registrationDone)
void
preDeregister()
ObjectName
preRegister(MBeanServer server, ObjectName name)
void
removeAttributeChangeNotificationListener(NotificationListener listener, String name)
Remove an attribute change notification event listener from this MBean.void
removeNotificationListener(NotificationListener listener)
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.AttributeList
setAttributes(AttributeList attributes)
Set the values of several attributes of this MBean.void
setManagedBean(ManagedBean managedBean)
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.String
toString()
-
-
-
Field Detail
-
oname
protected ObjectName oname
-
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.
-
resource
protected Object resource
The managed resource this MBean is associated with (if any).
-
resourceType
protected String resourceType
-
-
Method Detail
-
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
public AttributeList getAttributes(String[] names)
Obtain and return the values of several attributes of this MBean.- Specified by:
getAttributes
in interfaceDynamicMBean
- Parameters:
names
- Names of the requested attributes
-
setManagedBean
public void setManagedBean(ManagedBean managedBean)
-
getMBeanInfo
public MBeanInfo 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- Throws:
MBeanException
- if the initializer of an object throws an exceptionReflectionException
- if a Java reflection exception occurs when invoking a method
-
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
-
setAttributes
public AttributeList setAttributes(AttributeList attributes)
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, RuntimeOperationsException
Get the instance handle of the object against which we execute all methods in this ModelMBean management interface.- Returns:
- the backend managed object
- Throws:
InstanceNotFoundException
- if the managed resource object cannot be foundInvalidTargetObjectTypeException
- if the managed resource object is of the wrong typeMBeanException
- if the initializer of the object throws an exceptionRuntimeOperationsException
- if the managed resource or the resource type isnull
or invalid
-
setManagedResource
public void setManagedResource(Object resource, String type) throws InstanceNotFoundException, MBeanException, RuntimeOperationsException
Set the instance handle of the object against which we will execute all methods in this ModelMBean management interface. The caller can provide the mbean instance or the object name to the resource, if needed.- 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 foundMBeanException
- if the initializer of the object throws an exceptionRuntimeOperationsException
- if the managed resource or the resource type isnull
or invalid
-
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
-
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
public void sendNotification(String message) throws MBeanException, RuntimeOperationsException
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
public MBeanNotificationInfo[] 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
-
getModelerType
public String getModelerType()
-
getClassName
public String getClassName()
-
getJmxName
public ObjectName getJmxName()
-
getObjectName
public String getObjectName()
-
preRegister
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception
- Specified by:
preRegister
in interfaceMBeanRegistration
- Throws:
Exception
-
postRegister
public void postRegister(Boolean registrationDone)
- Specified by:
postRegister
in interfaceMBeanRegistration
-
preDeregister
public void preDeregister() throws Exception
- Specified by:
preDeregister
in interfaceMBeanRegistration
- Throws:
Exception
-
postDeregister
public void postDeregister()
- Specified by:
postDeregister
in interfaceMBeanRegistration
-
-