4.3 Managed Resources

As illustrated in Figure 4.1, when attributes are retrieved or operations are invoked on a model MBean, it will delegate those requests to a managed resource. The managed resource is a runtime object associated with a model MBean via the setManagedResource() method. The setManagedResource() method sets the default managed resource for the entire model MBean. A different managed resource can be set per operation and attribute as well. The model MBean delegates operations to the managed resource associated with it.

Figure 4.1. JMX Model MBeans and a Managed Resource

graphics/04fig01.gif

Because attribute setter and getter methods are represented as operations in the model MBean, attribute values may be retrieved from or set to different managed resources as well. This capability eliminates the need to write a management facade or delegation class if your application's management characteristics are distributed across several classes or instances of the same class. The model MBean can be customized to perform as that facade.

If you want to stay simple and set one managed-resource object for your entire model MBean, you can use the ModelMBean interface's setManagedResource() method:

The first parameter is the reference of your managed resource class. The second parameter indicates the type of reference you are passing. It can be set to one of the following strings:"ObjectReference", "Handle", "IOR", "EJBHandle", "RMIReference". Although "ObjectReference" is always supported, an MBeanServer does not have to support all of these types. You should read the documentation for your JMX implementation to determine which of these types, or any additional types, are valid for your implementation.

 void setManagedResource(          java.lang.Object managedResourceReference,         java.lang.String managedResourceReference_type) 

Think back to the earlier ApacheServer example. The statement

 apacheMMBean.setManagedResource(myApacheServer, "ObjectReference"); 

causes the ApacheServer instance, myApacheServer , to be the managed resource for the model MBean. This managed resource, myApacheServer , will now be the default managed resource for executing all operations in this model MBean ”that is, start() , stop() , all get methods (including getServer() ), and setServer() . You can override this default on a particular attribute or operation by using the descriptors in ModelMBeanInfo for that particular operation. We will show how to do this in the next section.



Java and JMX. Building Manageable Systems
Javaв„ў and JMX: Building Manageable Systems
ISBN: 0672324083
EAN: 2147483647
Year: 2000
Pages: 115

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net