United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-5108792 Add abstract base class to make coding DynamicMBeans easier
JDK-5108792 : Add abstract base class to make coding DynamicMBeans easier

Details
Type:
Enhancement
Submit Date:
2004-09-29
Status:
Closed
Updated Date:
2008-09-17
Project Name:
JDK
Resolved Date:
2008-09-17
Component:
core-svc
OS:
generic
Sub-Component:
javax.management
CPU:
generic
Priority:
P4
Resolution:
Won't Fix
Affected Versions:
6
Fixed Versions:

Related Reports
Relates:

Sub Tasks

Description
Coding a DynamicMBean is harder than it needs to be.  Constructing the MBeanInfo completely by hand is tedious and error-prone.  The getAttributes and setAttributes methods have to be written explicitly, even if each of them just consists of calling getAttribute or setAttribute n times.  The getAttribute and setAttribute methods frequently consist of a set of lines like this:

  if (attrName.equals("foo"))
    return getFoo();
  else if (attrName.equals("bar"))
    return getBar();
  ...
  else
    throw new AttributeNotFoundException(attrName);

There should be an easier way.

The AbstractDynamicMBean class defined by the MX4J project would be a good starting point.
http://cvs.sourceforge.net/viewcvs.py/mx4j/mx4j/src/core/mx4j/AbstractDynamicMBean.java?view=markup

                                    

Comments
EVALUATION

The hardest part here is getting the specification right, striking a balance between simplicity and ease of use on the one hand, and expressive power on the other.  Functionality in the base class should be justified by realistic examples of when it is useful.
###@###.### 2004-09-29
                                     
2004-09-29
WORK AROUND

If you know the set of attributes and operations that you want in your dynamic MBean at compile time, you can often just put them in an MBean interface and subclass javax.management.StandardMBean to override getAttribute(String) etc with the extra functionality you need.
                                     
2005-12-09
EVALUATION

In practice it appears that most cases where this might be useful are better addressed by javax.management.StandardMBean. Although if you do need to code a DynamicMBean, you often end up coding getAttributes in terms of getAttribute and setAttributes in terms of setAttribute, people don't often code DynamicMBeans so an abstract class would probably not pull its weight.
                                     
2008-09-17



Hardware and Software, Engineered to Work Together