org.jsesoft.mmbi
Class ModelMBeanInstrumentor

java.lang.Object
  extended by org.jsesoft.mmbi.ModelMBeanInstrumentor

public class ModelMBeanInstrumentor
extends java.lang.Object

Instruments (an registers) an arbitrary object as Model MBean.

This class provides JMX Model MBean instrumentation and registration for objects of arbitrary classes. It is implemented using the ReflectionInspector class.

Example:

 ModelMBeanInstrumentor instrumentor = new ModelMBeanInstrumentor();
 SampleResource resource = new SampleResource();
 NamedModelMBean mbean = instrumentor.instrument(resource, "sampleResource");
 // do something and let the bean being managed
 mbean.unregister();
 

Author:
JSESoft

Constructor Summary
ModelMBeanInstrumentor(java.lang.Object theManagedResource)
          Constructs an instance with Object.class as sentinel.
ModelMBeanInstrumentor(java.lang.Object theManagedResource, java.lang.Class<?> theSentinel)
          Constructs an instance with the specified class as sentinel.
 
Method Summary
 NamedModelMBean instrument()
          Creates a ModelMBean for a managed resource.
 NamedModelMBean instrument(java.lang.String nickName)
          Creates a ModelMBean for a managed resource and registers it as JMX MBean.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ModelMBeanInstrumentor

public ModelMBeanInstrumentor(java.lang.Object theManagedResource)
                       throws java.lang.Exception
Constructs an instance with Object.class as sentinel.

Parameters:
theManagedResource - the resource to be managed as Model MBean
Throws:
java.lang.Exception - on failure
See Also:
#ModelMBeanInstrumentor(Class)

ModelMBeanInstrumentor

public ModelMBeanInstrumentor(java.lang.Object theManagedResource,
                              java.lang.Class<?> theSentinel)
                       throws java.lang.Exception
Constructs an instance with the specified class as sentinel.

Traversal of the reflection tree is recursive with respect to inheritance. The sentinel specifies where recursion stops. Default is Object.class (see non-parameter constructor).

Parameters:
theManagedResource - the resource to be managed as Model MBean
theSentinel - Class where recursive traversal stops
Throws:
java.lang.Exception - on failure
Method Detail

instrument

public NamedModelMBean instrument()
                           throws java.lang.Exception
Creates a ModelMBean for a managed resource.

Returns:
the created NamedModelMBean
Throws:
java.lang.Exception - if instrumentation fails

instrument

public NamedModelMBean instrument(java.lang.String nickName)
                           throws java.lang.Exception
Creates a ModelMBean for a managed resource and registers it as JMX MBean.

This function is the workhorse of this class. It

  1. It creates a NamedModelMBean instance.
  2. It inspects the managed resource.
  3. if the nickName parameter is null, thats it. Otherwise
  4. It creates an object name like this
     classnameOfManagedResource:id=nickName-hashCode
     
  5. registers the MBean at the platform MBean server

Parameters:
nickName - part of the object name (if null then don't register)
Returns:
the created NamedModelMBean
Throws:
java.lang.Exception - if instrumentation fails


Copyright © 2010 JSESoft. All Rights Reserved.