United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-6323980 Annotations to simplify MBean development
JDK-6323980 : Annotations to simplify MBean development

Details
Type:
Enhancement
Submit Date:
2005-09-14
Status:
Closed
Updated Date:
2011-03-08
Project Name:
JDK
Resolved Date:
2011-03-08
Component:
core-svc
OS:
generic
Sub-Component:
javax.management
CPU:
generic
Priority:
P4
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports
Duplicate:
Relates:
Relates:
Relates:

Sub Tasks

Description
Today creating a Standard MBean means writing an interface that defines the management interface, and a class that implements that interface.  This could be made simpler using annotations.

In the simplest case, you could eliminate the interface and instead add a @Management annotation to each public method that is part of the management interface.

@MBean
public class MyResource {
    @Management
    public int getCacheSize() {...}
    @Management
    public void setCacheSize(int x) {...}
    ...other stuff unrelated to management...
}

You could also use annotations to control what the name of the MBean is, for example by saying that its name is derived from the values of the Foo and Bar attributes.

@MBean(type = "MyResource")
public class MyResource {
    @MBeanNameKey("foo")
    public String getFoo() {...}
    @MBeanNameKey("bar")
    public int getBar() {...}
}

Although there are some tricky implementation questions, it would be great if you could tag a private field as being an attribute:

public class MyResource {
    @MBeanAttribute("RequestCount")
    private int requestCount;

    public Result request(...) {
        requestCount++;
        ...
    }
}

                                    

Comments
EVALUATION

Worth investigating.  Annotating private fields to make them into attributes raises the question of how they are accessed.  Byte-code modification and AccessibleObject.setAccessible are both rather unattractive.  apt cannot modify a class to add a bridge method as we might like.

There is also a higher-level question of how a random application object that has been transformed into an MBean gets registered in the MBean Server.  Does the developer have to register the object explicitly just after it's been created?  Could there be a static method that you just need to call from the constructor?  What happens when the object is no longer alive?
                                     
2005-09-14
EVALUATION

See <http://weblogs.java.net/blog/emcmanus/archive/2007/08/defining_mbeans.html> for the current proposal.
                                     
2008-01-24



Hardware and Software, Engineered to Work Together