JDK-6339571 : RequiredModelMBean: don't require a ModelMBeanOperationInfo for every ModelMBeanAttributeInfo
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic
  • CPU: generic
  • Submitted: 2005-10-20
  • Updated: 2020-02-11
  • Resolved: 2020-02-11
Related Reports
Relates :  
Description
The RequiredModelMBean class allows you to define MBean attributes and operations that are directed to methods in one or more underlying "resources".  For example, you can specify that the MBean operation "resetCache()" is directed to the method "resetCache()" of some underlying object (resource).

In the case of attributes, you can either store the attribute value within the MBean itself (more exactly, within the Descriptor for the attribute), or you can forward it to a method on a resource.  In the latter case, you must add a getMethod and/or setMethod field to the Descriptor for the attribute, whose value is a String that is the name of the method to invoke on the resource.  *And* you must add an operation with that name.

So for example if I want to add a read-only attribute "CacheSize" that calls the method "getCurrentCacheSize()" on the underlying resource, I must do the following:
* define a ModelMBeanAttributeInfo for the attribute "CacheSize" that has a Descriptor that looks like this: {"name=CacheSize", "descriptorType=attribute", "getMethod=getCurrentCacheSize"}
* define a ModelMBeanOperationInfo for the operation "getCurrentCacheSize" that has a Descriptor that looks like this: {"name=getCurrentCacheSize", "descriptorType=operation"}
* put the ModelMBeanAttributeInfo and ModelMBeanOperationInfo in the appropriate arrays inside the ModelMBeanInfo for the RequiredModelMBean.

Furthermore, I can add the field "targetObject" to the Descriptor for the ModelMBeanOperationInfo to direct the "getCurrentCacheSize()" method call to some resource (object) other than the default one for this Model MBean.

The need to create a ModelMBeanOperationInfo is strange.  Not only does it lead to extra coding, but it means that the same functionality is exported in two ways by the MBean.  I can do getAttribute("CacheSize"), or I can do invoke("getCurrentCacheSize"), with the same results.

It would make sense to remove the requirement for there to be a ModelMBeanOperationInfo.  In the above scenario, all the necessary information is available from the ModelMBeanAttributeInfo.  The "targetObject" field should be allowed in the Descriptor for a ModelMBeanAttributeInfo with the obvious meaning.

There is a compatibility concern, which is that if the ModelMBeanAttributeInfo does not have a "targetObject" field in its Descriptor, we must check to see whether there is a corresponding ModelMBeanOperationInfo that does.  This will be the case for existing code that directs different attributes to different resources.

Comments
EVALUATION We will not be addressing this in the Java 7 timeframe, for lack of resources. A workaround for the problem of the same thing appearing in two forms is at <http://weblogs.java.net/blog/emcmanus/archive/2007/02/removing_getter.html>. An alternative to the serialization-based approach there would be to insert an MBeanServerForwarder between the Connector Server and the MBean Server, that rewrites the ModelMBeanInfo to remove the operations.
04-12-2008

EVALUATION Should not be hard to fix. The specification will be slightly messy because of the compatibility concern mentioned in the Description.
20-10-2005