public class ObjectMBean
extends java.lang.Object
implements javax.management.DynamicMBean
A dynamic MBean that can wrap an arbitrary Object instance.
The attributes and operations exposed by this bean are controlled by the merge of annotations discovered in all superclasses and all superinterfaces.
Given class com.acme.Foo
, then com.acme.jmx.FooMBean
is searched; if found, it is instantiated with the com.acme.Foo
instance passed to the constructor.
Class com.acme.jmx.FooMBean
can then override the default
behavior of ObjectMBean and provide a custom ObjectName, or custom
ObjectName properties name
and context
, etc.
Modifier and Type | Field and Description |
---|---|
private java.util.Set<java.lang.String> |
_attributes |
private java.util.Set<java.lang.String> |
_convert |
private java.util.Map<java.lang.String,java.lang.reflect.Method> |
_getters |
private javax.management.MBeanInfo |
_info |
private java.lang.ClassLoader |
_loader |
protected java.lang.Object |
_managed |
private MBeanContainer |
_mbeanContainer |
private java.util.Map<java.lang.String,java.lang.reflect.Method> |
_methods |
private java.util.Map<java.lang.String,java.lang.reflect.Method> |
_setters |
private static Logger |
LOG |
private static java.lang.Class<?>[] |
OBJ_ARG |
private static java.lang.String |
OBJECT_NAME_ARRAY_CLASS |
private static java.lang.String |
OBJECT_NAME_CLASS |
Constructor and Description |
---|
ObjectMBean(java.lang.Object managedObject)
Creates a new ObjectMBean wrapping the given
managedObject . |
Modifier and Type | Method and Description |
---|---|
private javax.management.MBeanAttributeInfo |
defineAttribute(java.lang.reflect.Method method,
ManagedAttribute attributeAnnotation)
Defines an attribute for the managed object using the annotation attributes.
|
private javax.management.MBeanOperationInfo |
defineOperation(java.lang.reflect.Method method,
ManagedOperation methodAnnotation)
Defines an operation for the managed object using the annotation attributes.
|
private static java.util.List<java.lang.Class<?>> |
findInfluences(java.util.List<java.lang.Class<?>> influences,
java.lang.Class<?> aClass) |
java.lang.Object |
getAttribute(java.lang.String name) |
javax.management.AttributeList |
getAttributes(java.lang.String[] names) |
java.lang.Object |
getManagedObject() |
MBeanContainer |
getMBeanContainer() |
javax.management.MBeanInfo |
getMBeanInfo() |
java.lang.String |
getObjectContextBasis()
Allows to customize the ObjectName property
context . |
javax.management.ObjectName |
getObjectName()
Allows to customize the ObjectName of this MBean.
|
java.lang.String |
getObjectNameBasis()
Allows to customize the ObjectName property
name . |
java.lang.Object |
invoke(java.lang.String name,
java.lang.Object[] params,
java.lang.String[] signature) |
protected boolean |
isAnnotationPresent(java.lang.Class<?> clazz,
java.lang.Class<? extends java.lang.annotation.Annotation> annotation) |
static java.lang.Object |
mbeanFor(java.lang.Object o)
Creates an ObjectMBean for the given object.
|
void |
setAttribute(javax.management.Attribute attr) |
javax.management.AttributeList |
setAttributes(javax.management.AttributeList attrs) |
protected void |
setMBeanContainer(MBeanContainer container) |
protected java.lang.String |
toVariableName(java.lang.String methodName) |
private static final Logger LOG
private static final java.lang.Class<?>[] OBJ_ARG
private static final java.lang.String OBJECT_NAME_CLASS
private static final java.lang.String OBJECT_NAME_ARRAY_CLASS
protected java.lang.Object _managed
private javax.management.MBeanInfo _info
private java.util.Map<java.lang.String,java.lang.reflect.Method> _getters
private java.util.Map<java.lang.String,java.lang.reflect.Method> _setters
private java.util.Map<java.lang.String,java.lang.reflect.Method> _methods
private java.util.Set<java.lang.String> _attributes
private java.util.Set<java.lang.String> _convert
private java.lang.ClassLoader _loader
private MBeanContainer _mbeanContainer
public ObjectMBean(java.lang.Object managedObject)
managedObject
.managedObject
- the object to managepublic static java.lang.Object mbeanFor(java.lang.Object o)
Creates an ObjectMBean for the given object.
Attempts to create an ObjectMBean for the object by searching the package and class name space. For example an object of the type:
class com.acme.MyClass extends com.acme.util.BaseClass implements com.acme.Iface
then this method would look for the following classes:
o
- The objectpublic java.lang.Object getManagedObject()
public javax.management.ObjectName getObjectName()
Allows to customize the ObjectName of this MBean.
MBeanContainer
to create a default ObjectNamepublic java.lang.String getObjectContextBasis()
Allows to customize the ObjectName property context
.
When MBeanContainer
creates default ObjectNames, the context
property
is "inherited" recursively by MBeans that are children of this MBean; this allows to
"group" descendant MBeans so that it is clear who is the ancestor they belong to.
For example, if object A has a child component B which has children components C, then AMBean can override this method to return "alpha", and then the ObjectNames will be:
context
public java.lang.String getObjectNameBasis()
Allows to customize the ObjectName property name
.
Certain components have a natural name and returning it from this method allows it to be part of the ObjectName.
name
protected void setMBeanContainer(MBeanContainer container)
public MBeanContainer getMBeanContainer()
public javax.management.MBeanInfo getMBeanInfo()
getMBeanInfo
in interface javax.management.DynamicMBean
public java.lang.Object getAttribute(java.lang.String name) throws javax.management.AttributeNotFoundException, javax.management.ReflectionException
getAttribute
in interface javax.management.DynamicMBean
javax.management.AttributeNotFoundException
javax.management.ReflectionException
public javax.management.AttributeList getAttributes(java.lang.String[] names)
getAttributes
in interface javax.management.DynamicMBean
public void setAttribute(javax.management.Attribute attr) throws javax.management.AttributeNotFoundException, javax.management.ReflectionException
setAttribute
in interface javax.management.DynamicMBean
javax.management.AttributeNotFoundException
javax.management.ReflectionException
public javax.management.AttributeList setAttributes(javax.management.AttributeList attrs)
setAttributes
in interface javax.management.DynamicMBean
public java.lang.Object invoke(java.lang.String name, java.lang.Object[] params, java.lang.String[] signature) throws javax.management.MBeanException, javax.management.ReflectionException
invoke
in interface javax.management.DynamicMBean
javax.management.MBeanException
javax.management.ReflectionException
private static java.util.List<java.lang.Class<?>> findInfluences(java.util.List<java.lang.Class<?>> influences, java.lang.Class<?> aClass)
private javax.management.MBeanAttributeInfo defineAttribute(java.lang.reflect.Method method, ManagedAttribute attributeAnnotation)
Defines an attribute for the managed object using the annotation attributes.
method
- the method on the managed objecattributeAnnotation
- the annotation with the attribute metadataprivate javax.management.MBeanOperationInfo defineOperation(java.lang.reflect.Method method, ManagedOperation methodAnnotation)
Defines an operation for the managed object using the annotation attributes.
method
- the method on the managed objectmethodAnnotation
- the annotation with the operation metadataprotected java.lang.String toVariableName(java.lang.String methodName)
protected boolean isAnnotationPresent(java.lang.Class<?> clazz, java.lang.Class<? extends java.lang.annotation.Annotation> annotation)