An MBean whose management interface is determined by reflection on a Java interface.
This class brings more flexibility to the notion of Management Interface in the use of Standard MBeans. Straightforward use of the patterns for Standard MBeans described in the JMX Specification means that there is a fixed relationship between the implementation class of an MBean and its management interface (i.e., if the implementation class is Thing, the management interface must be ThingMBean). This class makes it possible to keep the convenience of specifying the management interface with a Java interface, without requiring that there be any naming relationship between the implementation and interface classes.
By making a DynamicMBean out of an MBean, this class makes it possible to select any interface implemented by the MBean as its management interface, provided that it complies with JMX patterns (i.e., attributes defined by getter/setter etc...).
This class also provides hooks that make it possible to supply
custom descriptions and names for the MBeanInfo
returned by
the DynamicMBean interface.
Using this class, an MBean can be created with any implementation class name Impl and with a management interface defined (as for current Standard MBeans) by any interface Intf, in one of two general ways:
StandardMBean(impl,interface)
:
MBeanServer mbs; ... Impl impl = new Impl(...); StandardMBean mbean = new StandardMBean(impl, Intf.class, false); mbs.registerMBean(mbean, objectName);
public class Impl extends StandardMBean implements Intf { public Impl() { super(Intf.class, false); } // implement methods of Intf } [...] MBeanServer mbs; .... Impl impl = new Impl(); mbs.registerMBean(impl, objectName);
In either case, the class Impl must implement the interface Intf.
Standard MBeans based on the naming relationship between implementation and interface classes are of course still available.
This class may also be used to construct MXBeans. The usage
is exactly the same as for Standard MBeans except that in the
examples above, the false
parameter to the constructor or
super(...)
invocation is instead true
.
Modifier and Type | Class and Description |
---|---|
private static class |
Modifier and Type | Field and Description |
---|---|
private volatile MBeanInfo | cachedMBeanInfo
The cached MBeanInfo. |
private static final DescriptorCache | |
private volatile MBeanSupport | mbean
The DynamicMBean that wraps the MXBean or Standard MBean implementation. |
private static final Map | mbeanInfoSafeMap
Cached results of previous calls to immutableInfo. |
Access | Constructor and Description |
---|---|
public < Allows the compiler to check
that T>implementation does indeed implement the class
described by mbeanInterface . The compiler can only
check this if mbeanInterface is a class literal such
as MyMBean.class . | StandardMBean(T
The implementation of this MBean. implementation, Class<T> The Management Interface exported by this
MBean's implementation. If mbeanInterface)null , then this
object will use standard JMX design pattern to determine
the management interface associated with the given
implementation.Make a DynamicMBean out of the object implementation, using the specified mbeanInterface class. |
protected | StandardMBean(Class<?>
The Management Interface exported by this
MBean. mbeanInterface)Make a DynamicMBean out of this, using the specified mbeanInterface class. |
public < Allows the compiler to check
that T>implementation does indeed implement the class
described by mbeanInterface . The compiler can only
check this if mbeanInterface is a class literal such
as MyMBean.class . | StandardMBean(T
The implementation of this MBean. implementation, Class<T> The Management Interface exported by this
MBean's implementation. If mbeanInterface, boolean null , then this
object will use standard JMX design pattern to determine
the management interface associated with the given
implementation.If true, the isMXBean)mbeanInterface parameter
names an MXBean interface and the resultant MBean is an MXBean.Make a DynamicMBean out of the object implementation, using the specified mbeanInterface class, and choosing whether the resultant MBean is an MXBean. |
protected | StandardMBean(Class<?>
The Management Interface exported by this
MBean. mbeanInterface, boolean If true, the isMXBean)mbeanInterface parameter
names an MXBean interface and the resultant MBean is an MXBean.Make a DynamicMBean out of this, using the specified mbeanInterface class, and choosing whether the resulting MBean is an MXBean. |
Modifier and Type | Method and Description |
---|---|
protected void | cacheMBeanInfo(MBeanInfo
the new info)MBeanInfo to cache. Any
previously cached value is discarded. This parameter may be
null, in which case there is no new cached value.Customization hook: cache the MBeanInfo built for this object. |
private <T> void | construct(T
The implementation of this MBean.
If implementation, Class<T> null , and null implementation is allowed,
then the implementation is assumed to be this.The Management Interface exported by this
MBean's implementation. If mbeanInterface, boolean null , then this
object will use standard JMX design pattern to determine
the management interface associated with the given
implementation.true if a null
implementation is allowed. If null implementation is allowed,
and a null implementation is passed, then the implementation
is assumed to be this.Make a DynamicMBean out of implementation, using the specified mbeanInterface class. |
private static MBeanParameterInfo | |
private static MBeanConstructorInfo | |
private static MBeanOperationInfo | |
private static MBeanAttributeInfo | |
private static <T> boolean | |
public Object | getAttribute(String
The name of the attribute to be retrieved attribute)Implements javax. Obtain the value of a specific attribute of the Dynamic MBean. |
public AttributeList | getAttributes(String[]
A list of the attributes to be retrieved. attributes)Implements javax. Get the values of several attributes of the Dynamic MBean. |
private MBeanAttributeInfo[] | |
protected MBeanInfo | Returns: The cached MBeanInfo, or null if no MBeanInfo is cached.Customization hook: Return the MBeanInfo cached for this object. |
protected String | Returns: the class name for the new MBeanInfo.The default MBeanInfo derived by reflection. info)Customization hook: Get the className that will be used in the MBeanInfo returned by this MBean. |
protected MBeanConstructorInfo[] | Returns: the MBeanConstructorInfo[] for the new MBeanInfo.The default MBeanConstructorInfo[] derived by reflection. ctors, Object The wrapped implementation. If impl)null is
passed, the wrapped implementation is ignored and
ctors is returned.Customization hook: Get the MBeanConstructorInfo[] that will be used in the MBeanInfo returned by this MBean. |
private MBeanConstructorInfo[] | |
protected String | Returns: the description for the new MBeanInfo.The default MBeanInfo derived by reflection. info)Customization hook: Get the description that will be used in the MBeanInfo returned by this MBean. |
protected String | Returns: the description for the given MBeanFeatureInfo.The default MBeanFeatureInfo derived by reflection. info)Customization hook: Get the description that will be used in the MBeanFeatureInfo returned by this MBean. |
protected String | Returns: the description for the given MBeanAttributeInfo.The default MBeanAttributeInfo derived by reflection. info)Customization hook: Get the description that will be used in the MBeanAttributeInfo returned by this MBean. |
protected String | Returns: the description for the given MBeanConstructorInfo.The default MBeanConstructorInfo derived by reflection. info)Customization hook: Get the description that will be used in the MBeanConstructorInfo returned by this MBean. |
protected String | Returns: the description for the given MBeanParameterInfo.The default MBeanConstructorInfo derived by reflection. ctor, MBeanParameterInfo The default MBeanParameterInfo derived by reflection. param, int The sequence number of the parameter considered
("0" for the first parameter, "1" for the second parameter,
etc...). sequence)Customization hook: Get the description that will be used for the sequence MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean. |
protected String | Returns: the description for the given MBeanOperationInfo.The default MBeanOperationInfo derived by reflection. info)Customization hook: Get the description that will be used in the MBeanOperationInfo returned by this MBean. |
protected String | Returns: the description for the given MBeanParameterInfo.The default MBeanOperationInfo derived by reflection. op, MBeanParameterInfo The default MBeanParameterInfo derived by reflection. param, int The sequence number of the parameter considered
("0" for the first parameter, "1" for the second parameter,
etc...). sequence)Customization hook: Get the description that will be used for the sequence MBeanParameterInfo of the MBeanOperationInfo returned by this MBean. |
pack-priv Descriptor | Returns: the Descriptor for the new MBeanInfo.The default MBeanInfo derived by reflection. info, boolean immutableInfo)Get the Descriptor that will be used in the MBeanInfo returned by this MBean. |
protected int | Returns: the impact flag for the given MBeanOperationInfo.The default MBeanOperationInfo derived by reflection. info)Customization hook: Get the impact flag of the operation that will be used in the MBeanOperationInfo returned by this MBean. |
public Object | Returns: The implementation of this Standard MBean (or MXBean).Get the implementation of this Standard MBean (or MXBean). |
public Class | Returns: The class of the implementation of this Standard MBean (or MXBean).Get the class of the implementation of this Standard MBean (or MXBean). |
public MBeanInfo | Returns: The cached MBeanInfo for that MBean, if not null, or a newly built MBeanInfo if none was cached.Implements javax. Get the |
public final Class | Returns: The management interface of this Standard MBean (or MXBean).Get the Management Interface of this Standard MBean (or MXBean). |
pack-priv MBeanNotificationInfo[] | Returns: the MBeanNotificationInfo[] for the new MBeanInfo.The default MBeanInfo derived by reflection. info)Customization hook: Get the MBeanNotificationInfo[] that will be used in the MBeanInfo returned by this MBean. |
private MBeanOperationInfo[] | |
protected String | Returns: the name for the given MBeanParameterInfo.The default MBeanConstructorInfo derived by reflection. ctor, MBeanParameterInfo The default MBeanParameterInfo derived by reflection. param, int The sequence number of the parameter considered
("0" for the first parameter, "1" for the second parameter,
etc...). sequence)Customization hook: Get the name that will be used for the sequence MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean. |
protected String | Returns: the name to use for the given MBeanParameterInfo.The default MBeanOperationInfo derived by reflection. op, MBeanParameterInfo The default MBeanParameterInfo derived by reflection. param, int The sequence number of the parameter considered
("0" for the first parameter, "1" for the second parameter,
etc...). sequence)Customization hook: Get the name that will be used for the sequence MBeanParameterInfo of the MBeanOperationInfo returned by this MBean. |
private static <T> boolean | |
pack-priv static boolean | immutableInfo(Class<? extends StandardMBean> subclass)
Return true if |
public Object | invoke(String
The name of the action to be invoked. actionName, Object[] An array containing the parameters to be set when the action is
invoked. params, String[] An array containing the signature of the action. The class objects will
be loaded through the same class loader as the one used for loading the
MBean on which the action is invoked. signature)Implements javax. Allows an action to be invoked on the Dynamic MBean. |
private boolean | |
pack-priv static boolean | |
private static OpenMBeanParameterInfo[] | |
public void | postDeregister()
Implements javax. Allows the MBean to perform any operations needed after having been unregistered in the MBean server. |
public void | postRegister(Boolean
Indicates whether or not the MBean has
been successfully registered in the MBean server. The value
false means that the registration phase has failed. registrationDone)Implements javax. Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed. |
public void | preDeregister()
Implements javax. Allows the MBean to perform any operations it needs before being unregistered by the MBean server. |
public ObjectName | Returns: The name under which the MBean is to be registered. This value must not be null. If thename
parameter is not null, it will usually but not necessarily be
the returned value.The MBean server in which the MBean will be registered. server, ObjectName The object name of the MBean. This name is null if
the name parameter to one of the name)createMBean or
registerMBean methods in the MBeanServer
interface is null. In that case, this method must return a
non-null ObjectName for the new MBean.Implements javax. Allows the MBean to perform any operations it needs before being registered in the MBean server. |
public void | setAttribute(Attribute
The identification of the attribute to
be set and the value it is to be set to. attribute)Implements javax. Set the value of a specific attribute of the Dynamic MBean. |
public AttributeList | setAttributes(AttributeList
A list of attributes: The identification of the
attributes to be set and the values they are to be set to. attributes)Implements javax. Sets the values of several attributes of the Dynamic MBean. |
public void | setImplementation(Object
The new implementation of this Standard MBean
(or MXBean). The implementation)implementation object must implement
the Standard MBean (or MXBean) interface that was supplied when this
StandardMBean was constructed.Replace the implementation object wrapped in this object. |
cachedMBeanInfo | back to summary |
---|---|
private volatile MBeanInfo cachedMBeanInfo The cached MBeanInfo. |
descriptors | back to summary |
---|---|
private static final DescriptorCache descriptors |
mbean | back to summary |
---|---|
private volatile MBeanSupport<?> mbean The DynamicMBean that wraps the MXBean or Standard MBean implementation. |
mbeanInfoSafeMap | back to summary |
---|---|
private static final Map<Class<?>, Boolean> mbeanInfoSafeMap Cached results of previous calls to immutableInfo. This is a WeakHashMap so that we don't prevent a class from being garbage collected just because we know whether its MBeanInfo is immutable. |
StandardMBean | back to summary |
---|---|
public <T> StandardMBean(T implementation, Class<T> mbeanInterface) throws NotCompliantMBeanException Make a DynamicMBean out of the object implementation, using the specified mbeanInterface class.
|
StandardMBean | back to summary |
---|---|
protected StandardMBean(Class<?> mbeanInterface) throws NotCompliantMBeanException Make a DynamicMBean out of this, using the specified mbeanInterface class. Calls
|
StandardMBean | back to summary |
---|---|
public <T> StandardMBean(T implementation, Class<T> mbeanInterface, boolean isMXBean) Make a DynamicMBean out of the object
implementation, using the specified
mbeanInterface class, and choosing whether the
resultant MBean is an MXBean. This constructor can be used
to make either Standard MBeans or MXBeans. Unlike the
constructor
|
StandardMBean | back to summary |
---|---|
protected StandardMBean(Class<?> mbeanInterface, boolean isMXBean) Make a DynamicMBean out of this, using the specified
mbeanInterface class, and choosing whether the resulting
MBean is an MXBean. This constructor can be used
to make either Standard MBeans or MXBeans. Unlike the
constructor Calls
|
cacheMBeanInfo | back to summary |
---|---|
protected void cacheMBeanInfo(MBeanInfo info) Customization hook: cache the MBeanInfo built for this object. Subclasses may redefine this method in order to implement
their own caching policy. The default implementation stores
|
construct | back to summary |
---|---|
private <T> void construct(T implementation, Class<T> mbeanInterface, boolean nullImplementationAllowed, boolean isMXBean) throws NotCompliantMBeanException Make a DynamicMBean out of implementation, using the specified mbeanInterface class.
|
customize | back to summary |
---|---|
private static MBeanParameterInfo customize(MBeanParameterInfo pi, String name, String description) |
customize | back to summary |
---|---|
private static MBeanConstructorInfo customize(MBeanConstructorInfo ci, String description, MBeanParameterInfo[] signature) |
customize | back to summary |
---|---|
private static MBeanOperationInfo customize(MBeanOperationInfo oi, String description, MBeanParameterInfo[] signature, int impact) |
customize | back to summary |
---|---|
private static MBeanAttributeInfo customize(MBeanAttributeInfo ai, String description) |
equal | back to summary |
---|---|
private static <T> boolean equal(T a, T b) |
getAttribute | back to summary |
---|---|
public Object getAttribute(String attribute) throws AttributeNotFoundException, MBeanException, ReflectionException Implements javax. Doc from javax. Obtain the value of a specific attribute of the Dynamic MBean.
|
getAttributes | back to summary |
---|---|
public AttributeList getAttributes(String[] attributes) Implements javax. Doc from javax. Get the values of several attributes of the Dynamic MBean.
|
getAttributes | back to summary |
---|---|
private MBeanAttributeInfo[] getAttributes(MBeanInfo info) |
getCachedMBeanInfo | back to summary |
---|---|
protected MBeanInfo getCachedMBeanInfo() Customization hook: Return the MBeanInfo cached for this object. Subclasses may redefine this method in order to implement their
own caching policy. The default implementation stores one
|
getClassName | back to summary |
---|---|
protected String getClassName(MBeanInfo info) Customization hook:
Get the className that will be used in the MBeanInfo returned by
this MBean.
|
getConstructors | back to summary |
---|---|
protected MBeanConstructorInfo[] getConstructors(MBeanConstructorInfo[] ctors, Object impl) Customization hook:
Get the MBeanConstructorInfo[] that will be used in the MBeanInfo
returned by this MBean.
|
getConstructors | back to summary |
---|---|
private MBeanConstructorInfo[] getConstructors(MBeanInfo info, Object impl) |
getDescription | back to summary |
---|---|
protected String getDescription(MBeanInfo info) Customization hook:
Get the description that will be used in the MBeanInfo returned by
this MBean.
|
getDescription | back to summary |
---|---|
protected String getDescription(MBeanFeatureInfo info) Customization hook: Get the description that will be used in the MBeanFeatureInfo returned by this MBean. Subclasses may redefine this method in order to supply
their custom description. The default implementation returns
This method is called by
|
getDescription | back to summary |
---|---|
protected String getDescription(MBeanAttributeInfo info) Customization hook: Get the description that will be used in the MBeanAttributeInfo returned by this MBean. Subclasses may redefine this method in order to supply their
custom description. The default implementation returns
|
getDescription | back to summary |
---|---|
protected String getDescription(MBeanConstructorInfo info) Customization hook:
Get the description that will be used in the MBeanConstructorInfo
returned by this MBean.
|
getDescription | back to summary |
---|---|
protected String getDescription(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence) Customization hook:
Get the description that will be used for the sequence
MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
|
getDescription | back to summary |
---|---|
protected String getDescription(MBeanOperationInfo info) Customization hook:
Get the description that will be used in the MBeanOperationInfo
returned by this MBean.
|
getDescription | back to summary |
---|---|
protected String getDescription(MBeanOperationInfo op, MBeanParameterInfo param, int sequence) Customization hook:
Get the description that will be used for the sequence
MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
|
getDescriptor | back to summary |
---|---|
pack-priv Descriptor getDescriptor(MBeanInfo info, boolean immutableInfo) Get the Descriptor that will be used in the MBeanInfo returned by this MBean. Subclasses may redefine this method in order to supply their custom descriptor. The default implementation of this method returns a Descriptor
that contains at least the field
|
getImpact | back to summary |
---|---|
protected int getImpact(MBeanOperationInfo info) Customization hook:
Get the impact flag of the operation that will be used in
the MBeanOperationInfo returned by this MBean.
|
getImplementation | back to summary |
---|---|
public Object getImplementation() Get the implementation of this Standard MBean (or MXBean).
|
getImplementationClass | back to summary |
---|---|
public Class Get the class of the implementation of this Standard MBean (or MXBean).
|
getMBeanInfo | back to summary |
---|---|
public MBeanInfo getMBeanInfo() Implements javax. Get the
This method implements
This method first calls
While building the MBeanInfo, this method calls the customization
hooks that make it possible for subclasses to supply their custom
descriptions, parameter names, etc...
|
getMBeanInterface | back to summary |
---|---|
public final Class Get the Management Interface of this Standard MBean (or MXBean).
|
getNotifications | back to summary |
---|---|
pack-priv MBeanNotificationInfo[] getNotifications(MBeanInfo info) Customization hook:
Get the MBeanNotificationInfo[] that will be used in the MBeanInfo
returned by this MBean.
|
getOperations | back to summary |
---|---|
private MBeanOperationInfo[] getOperations(MBeanInfo info) |
getParameterName | back to summary |
---|---|
protected String getParameterName(MBeanConstructorInfo ctor, MBeanParameterInfo param, int sequence) Customization hook:
Get the name that will be used for the sequence
MBeanParameterInfo of the MBeanConstructorInfo returned by this MBean.
|
getParameterName | back to summary |
---|---|
protected String getParameterName(MBeanOperationInfo op, MBeanParameterInfo param, int sequence) Customization hook:
Get the name that will be used for the sequence
MBeanParameterInfo of the MBeanOperationInfo returned by this MBean.
|
identicalArrays | back to summary |
---|---|
private static <T> boolean identicalArrays(T[] a, T[] b) |
immutableInfo | back to summary |
---|---|
pack-priv static boolean immutableInfo(Class<? extends StandardMBean> subclass) Return true if
|
invoke | back to summary |
---|---|
public Object invoke(String actionName, Object[] params, String[] signature) throws MBeanException, ReflectionException Implements javax. Doc from javax. Allows an action to be invoked on the Dynamic MBean.
|
isMXBean | back to summary |
---|---|
private boolean isMXBean() |
overrides | back to summary |
---|---|
pack-priv static boolean overrides(Class<?> subclass, Class<?> superclass, String name, Class<?>... params) |
paramsToOpenParams | back to summary |
---|---|
private static OpenMBeanParameterInfo[] paramsToOpenParams(MBeanParameterInfo[] params) |
postDeregister | back to summary |
---|---|
public void postDeregister() Implements javax. Allows the MBean to perform any operations needed after having been unregistered in the MBean server. The default implementation of this method does nothing for
Standard MBeans. For MXBeans, it removes any information that
was recorded by the It is good practice for a subclass that overrides this method
to call the overridden method via
|
postRegister | back to summary |
---|---|
public void postRegister(Boolean registrationDone) Implements javax. Allows the MBean to perform any operations needed after having been registered in the MBean server or after the registration has failed. The default implementation of this method does nothing for
Standard MBeans. For MXBeans, it undoes any work done by
It is good practice for a subclass that overrides this method
to call the overridden method via
|
preDeregister | back to summary |
---|---|
public void preDeregister() throws Exception Implements javax. Allows the MBean to perform any operations it needs before being unregistered by the MBean server. The default implementation of this method does nothing. It is good practice for a subclass that overrides this method
to call the overridden method via
|
preRegister | back to summary |
---|---|
public ObjectName preRegister(MBeanServer server, ObjectName name) throws Exception Implements javax. Allows the MBean to perform any operations it needs before being registered in the MBean server. If the name of the MBean is not specified, the MBean can provide a name for its registration. If any exception is raised, the MBean will not be registered in the MBean server. The default implementation of this method returns the It is good practice for a subclass that overrides this method
to call the overridden method via
|
setAttribute | back to summary |
---|---|
public void setAttribute(Attribute attribute) throws AttributeNotFoundException, InvalidAttributeValueException, MBeanException, ReflectionException Implements javax. Doc from javax. Set the value of a specific attribute of the Dynamic MBean.
|
setAttributes | back to summary |
---|---|
public AttributeList setAttributes(AttributeList attributes) Implements javax. Doc from javax. Sets the values of several attributes of the Dynamic MBean.
|
setImplementation | back to summary |
---|---|
public void setImplementation(Object implementation) throws NotCompliantMBeanException Replace the implementation object wrapped in this object.
|
Access | Constructor and Description |
---|---|
pack-priv |
Modifier and Type | Method and Description |
---|---|
public Boolean |
subclass | back to summary |
---|---|
private final Class<?> subclass |
MBeanInfoSafeAction | back to summary |
---|---|
pack-priv MBeanInfoSafeAction(Class<?> subclass) |
run | back to summary |
---|---|
public Boolean run() Implements java. Doc from java. Performs the computation. This method will be called by
|