|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.management.StandardMBean
public class StandardMBean
Provides a dynamic management bean by using reflection on an interface and an implementing class. By default, a bean instance is paired up with its interface based on specific naming conventions (if the implementation is called X, the interface must be XMBean). Using this class removes the need to use a specific naming system to match up the two. Instead, an instance of this bean is created either via explicit construction or subclassing, and this provides access to the attributes, constructors and operations of the implementation via reflection. Various hooks are provided in order to allow customization of this process.
Constructor Summary | |
---|---|
protected |
StandardMBean(Class<?> iface)
Constructs a new StandardMBean using the specified
interface and this as the instance. |
|
StandardMBean(T impl,
Class<T> iface)
Constructs a new StandardMBean using the specified
interface and the supplied instance as the implementation. |
Method Summary | |
---|---|
protected void |
cacheMBeanInfo(MBeanInfo info)
Caches the MBeanInfo instance for this object. |
Object |
getAttribute(String name)
Obtains the value of the specified attribute of the management bean. |
AttributeList |
getAttributes(String[] names)
Obtains the values of each of the specified attributes of the management bean. |
protected MBeanInfo |
getCachedMBeanInfo()
Returns the cached MBeanInfo instance for this object. |
protected String |
getClassName(MBeanInfo info)
Returns the class name that will be used in the MBeanInfo
instance. |
protected MBeanConstructorInfo[] |
getConstructors(MBeanConstructorInfo[] constructors,
Object impl)
Returns information on the constructors that will be used in the MBeanInfo instance. |
protected String |
getDescription(MBeanAttributeInfo info)
Returns the description of the attribute that will be used in the supplied MBeanAttributeInfo instance. |
protected String |
getDescription(MBeanConstructorInfo info)
Returns the description of the constructor that will be used in the supplied MBeanConstructorInfo instance. |
protected String |
getDescription(MBeanConstructorInfo info,
MBeanParameterInfo param,
int n)
Returns the description of the nth parameter of the constructor that will be used in the supplied MBeanParameterInfo
instance. |
protected String |
getDescription(MBeanFeatureInfo info)
Returns the description of the supplied feature that will be used in the supplied MBeanFeatureInfo
instance. |
protected String |
getDescription(MBeanInfo info)
Returns the description of the bean that will be used in the supplied MBeanInfo instance. |
protected String |
getDescription(MBeanOperationInfo info)
Returns the description of the operation that will be used in the supplied MBeanOperationInfo instance. |
protected String |
getDescription(MBeanOperationInfo info,
MBeanParameterInfo param,
int n)
Returns the description of the nth parameter of the operation that will be used in the supplied MBeanParameterInfo
instance. |
protected int |
getImpact(MBeanOperationInfo info)
Returns the impact of the operation that will be used in the supplied MBeanOperationInfo instance. |
Object |
getImplementation()
Returns the instance that implements this bean. |
Class<?> |
getImplementationClass()
Returns the class of the instance that implements this bean. |
MBeanInfo |
getMBeanInfo()
Returns an information object which lists the attributes and actions associated with the management bean. |
Class<?> |
getMBeanInterface()
Returns the interface for this management bean. |
protected String |
getParameterName(MBeanConstructorInfo info,
MBeanParameterInfo param,
int n)
Returns the name of the nth parameter of the constructor that will be used in the supplied MBeanParameterInfo
instance. |
protected String |
getParameterName(MBeanOperationInfo info,
MBeanParameterInfo param,
int n)
Returns the name of the nth parameter of the operation that will be used in the supplied MBeanParameterInfo
instance. |
Object |
invoke(String name,
Object[] params,
String[] signature)
Invokes the specified action on the management bean using the supplied parameters. |
void |
setAttribute(Attribute attribute)
Sets the value of the specified attribute of the management bean. |
AttributeList |
setAttributes(AttributeList attributes)
Sets the value of each of the specified attributes to that supplied by the Attribute object. |
void |
setImplementation(Object impl)
Replaces the implementation of the interface used by this instance with the one specified. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
protected StandardMBean(Class<?> iface) throws NotCompliantMBeanException
StandardMBean
using the specified
interface and this
as the instance. This should
be used to create an instance via subclassing.
iface
- the interface this bean implements, or null
if the interface should be determined using the naming
convention (class X has interface XMBean).
NotCompliantMBeanException
- if this class doesn't implement
the interface or a method appears
in the interface that doesn't comply
with the naming conventions.public StandardMBean(T impl, Class<T> iface) throws NotCompliantMBeanException
StandardMBean
using the specified
interface and the supplied instance as the implementation.
impl
- the implementation.iface
- the interface the bean implements, or null
if the interface should be determined using the naming
convention (class X has interface XMBean).
IllegalArgumentException
- if impl
is null
.
NotCompliantMBeanException
- if impl
doesn't implement
the interface or a method appears
in the interface that doesn't comply
with the naming conventions.Method Detail |
---|
protected void cacheMBeanInfo(MBeanInfo info)
MBeanInfo
instance for this object. This is a
customization hook, so that subclasses can choose the caching policy
used. The default implementation caches the value in the instance
itself. Subclasses may override this so as to not cache the data
at all, or so as to use a cache shared between multiple beans.
info
- the MBeanInfo
instance to cache, or null
if there is no new value to cache. When the value is not
null
, the cache should replace the current value
with the value supplied here.getCachedMBeanInfo()
public Object getAttribute(String name) throws AttributeNotFoundException, MBeanException, ReflectionException
getAttribute
in interface DynamicMBean
name
- the name of the attribute to retrieve.
AttributeNotFoundException
- if the name does not
correspond to an attribute
of the bean.
MBeanException
- if retrieving the attribute causes
the bean to throw an exception (which
becomes the cause of this exception).
ReflectionException
- if an exception occurred in trying
to use the reflection interface
to lookup the attribute. The
thrown exception is the cause of
this exception.#setAttribute(String)
public AttributeList getAttributes(String[] names)
getAttributes
in interface DynamicMBean
names
- the names of the attributes to retrieve.
setAttributes(AttributeList)
protected MBeanInfo getCachedMBeanInfo()
MBeanInfo
instance for this object. This is a
customization hook, so that subclasses can choose the caching policy
used. The default implementation caches the value in the instance
itself, and returns this value on calls to this method.
MBeanInfo
instance, or null
if no value is cached.cacheMBeanInfo(javax.management.MBeanInfo)
protected String getClassName(MBeanInfo info)
MBeanInfo
instance. This is a customization hook, so that subclasses can
provide a custom class name. By default, this returns the class
name from the supplied MBeanInfo
instance.
info
- the MBeanInfo
instance constructed via
reflection.
protected MBeanConstructorInfo[] getConstructors(MBeanConstructorInfo[] constructors, Object impl)
MBeanInfo
instance. This is a customization hook,
so that subclasses can provide their own information on the
bean's constructors, if necessary. By default, this method
returns null
unless the implementation supplied
is either null
or this
. This default
implementation prevents the use of
MBeanServer.createMBean(java.lang.String, javax.management.ObjectName)
in cases where the bean is
not created as a subclass of StandardMBean
.
constructors
- the constructor information created via
reflection.impl
- the implementation, or null
if this
should be ignored.
protected String getDescription(MBeanAttributeInfo info)
MBeanAttributeInfo
instance. This is a
customization hook, so that subclasses can provide a custom
description. By default, this calls
getDescription(MBeanFeatureInfo)
with the supplied
MBeanAttributeInfo
instance.
info
- the MBeanAttributeInfo
instance constructed
via reflection.
protected String getDescription(MBeanConstructorInfo info)
MBeanConstructorInfo
instance. This is a
customization hook, so that subclasses can provide a custom
description. By default, this calls
getDescription(MBeanFeatureInfo)
with the supplied
MBeanConstructorInfo
instance.
info
- the MBeanConstructorInfo
instance constructed
via reflection.
protected String getDescription(MBeanConstructorInfo info, MBeanParameterInfo param, int n)
MBeanParameterInfo
instance. This is a customization hook, so that subclasses
can provide a custom description. By default, this calls
param.getDescription()
.
info
- the MBeanConstructorInfo
instance constructed
via reflection.param
- the MBeanParameterInfo
instance constructed
via reflection.n
- the number of the parameter, in order to link it to the
information on the constructor.
protected String getDescription(MBeanFeatureInfo info)
MBeanFeatureInfo
instance. This is a customization hook, so that subclasses
can provide a custom description. By default, this calls
info.getDescription()
. This method is also called
by default for the more specific description methods for attributes,
constructors and operations.
info
- the MBeanFeatureInfo
instance constructed
via reflection.
protected String getDescription(MBeanInfo info)
MBeanInfo
instance. This is a customization
hook, so that subclasses can provide a custom description. By
default, this calls info.getDescription()
.
info
- the MBeanInfo
instance constructed
via reflection.
protected String getDescription(MBeanOperationInfo info)
MBeanOperationInfo
instance. This is a
customization hook, so that subclasses can provide a custom
description. By default, this calls
getDescription(MBeanFeatureInfo)
with the supplied
MBeanOperationInfo
instance.
info
- the MBeanOperationInfo
instance constructed
via reflection.
protected String getDescription(MBeanOperationInfo info, MBeanParameterInfo param, int n)
MBeanParameterInfo
instance. This is a customization hook, so that subclasses
can provide a custom description. By default, this calls
param.getDescription()
.
info
- the MBeanOperationInfo
instance constructed
via reflection.param
- the MBeanParameterInfo
instance constructed
via reflection.n
- the number of the parameter, in order to link it to the
information on the operation.
protected int getImpact(MBeanOperationInfo info)
MBeanOperationInfo
instance. This is a
customization hook, so that subclasses can provide a custom
impact flag. By default, this returns
info.getImpact()
.
info
- the MBeanOperationInfo
instance constructed
via reflection.
public Object getImplementation()
public Class<?> getImplementationClass()
public MBeanInfo getMBeanInfo()
Returns an information object which lists the attributes and actions associated with the management bean. This implementation proceeds as follows:
getCachedMBeanInfo()
is called to obtain
the cached instance. If this returns a non-null value,
this value is returned.getDescription(MBeanAttributeInfo)
is called.getDescription(MBeanConstructorInfo)
is called,
along with getDescription(MBeanConstructorInfo,
MBeanParameterInfo, int)
and
getParameterName(MBeanConstructorInfo,
MBeanParameterInfo, int)
for each parameter.getConstructors(MBeanConstructorInfo[], Object)
.getDescription(MBeanOperationInfo)
and
getImpact(MBeanOperationInfo)
are called,
along with getDescription(MBeanOperationInfo,
MBeanParameterInfo, int)
and
getParameterName(MBeanOperationInfo,
MBeanParameterInfo, int)
for each parameter.getClassName(MBeanInfo)
and
getDescription(MBeanInfo)
are called to customise
the basic information about the class.cacheMBeanInfo(MBeanInfo)
is called
with the created instance before it is returned.
getMBeanInfo
in interface DynamicMBean
public final Class<?> getMBeanInterface()
protected String getParameterName(MBeanConstructorInfo info, MBeanParameterInfo param, int n)
MBeanParameterInfo
instance. This is a customization hook, so that subclasses
can provide a custom name. By default, this calls
param.getName()
.
info
- the MBeanConstructorInfo
instance constructed
via reflection.param
- the MBeanParameterInfo
instance constructed
via reflection.n
- the number of the parameter, in order to link it to the
information on the constructor.
protected String getParameterName(MBeanOperationInfo info, MBeanParameterInfo param, int n)
MBeanParameterInfo
instance. This is a customization hook, so that subclasses
can provide a custom name. By default, this calls
param.getName()
.
info
- the MBeanOperationInfo
instance constructed
via reflection.param
- the MBeanParameterInfo
instance constructed
via reflection.n
- the number of the parameter, in order to link it to the
information on the operation.
public Object invoke(String name, Object[] params, String[] signature) throws MBeanException, ReflectionException
String
array, which lists the classes
corresponding to each parameter. The class loader used to
load these classes is the same as that used for loading the
management bean itself.
invoke
in interface DynamicMBean
name
- the name of the action to invoke.params
- the parameters used to call the action.signature
- the signature of the action.
MBeanException
- if the action throws an exception. The
thrown exception is the cause of this
exception.
ReflectionException
- if an exception occurred in trying
to use the reflection interface
to invoke the action. The
thrown exception is the cause of
this exception.public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException
setAttribute
in interface DynamicMBean
attribute
- the attribute to set.
AttributeNotFoundException
- if the attribute does not
correspond to an attribute
of the bean.
InvalidAttributeValueException
- if the value is invalid
for this particular
attribute of the bean.
MBeanException
- if setting the attribute causes
the bean to throw an exception (which
becomes the cause of this exception).
ReflectionException
- if an exception occurred in trying
to use the reflection interface
to lookup the attribute. The
thrown exception is the cause of
this exception.getAttribute(String)
public AttributeList setAttributes(AttributeList attributes)
Attribute
object.
The returned list contains the attributes that were
set and their new values.
setAttributes
in interface DynamicMBean
attributes
- the attributes to set.
#getAttributes(AttributeList)
public void setImplementation(Object impl) throws NotCompliantMBeanException
IllegalArgumentException
- if impl
is null
.
NotCompliantMBeanException
- if impl
doesn't implement
the interface or a method appears
in the interface that doesn't comply
with the naming conventions.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |