JDK-6323980 : Annotations to simplify MBean development
  • Type: Enhancement
  • Component: core-svc
  • Sub-Component: javax.management
  • Affected Version: 6
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2005-09-14
  • Updated: 2017-05-16
  • Resolved: 2011-03-08
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7 b32Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
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 See <http://weblogs.java.net/blog/emcmanus/archive/2007/08/defining_mbeans.html> for the current proposal.
24-01-2008

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?
14-09-2005