United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-6450834 : RFE: allow StandardMBean to call MBeanRegistration methods on its wrapped resource

Details
Type:
Enhancement
Submit Date:
2006-07-20
Status:
Closed
Updated Date:
2011-04-19
Project Name:
JDK
Resolved Date:
2011-04-19
Component:
core-svc
OS:
generic
Sub-Component:
javax.management
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
6
Fixed Versions:

Related Reports

Sub Tasks

Description
The class javax.management.StandardMBean implements MBeanRegistration as of Mustang.  But if you have a StandardMBean constructed as new StandardMBean(impl, SomethingMBean.class), and if the impl object itself implements MBeanRegistration, the MBeanRegistration methods are not forwarded to impl as you might expect.  This is for compatibility reasons: it would have changed the behaviour of existing code.

We could have a way of creating a StandardMBean or StandardEmitterMBean that explicitly asks for MBeanRegistration methods to be forwarded to the impl object.

                                    

Comments
WORK AROUND

Subclass StandardMBean and/or StandardEmitterMBean and override the MBeanRegistration methods, like this:

public class RegistrableStandardMBean extends StandardMBean {
    public <T> RegistrableStandardMBean(T impl, Class<T> intf) {
        super(impl, intf, false);
    }

    @Override
    public ObjectName preRegister(MBeanServer mbs, ObjectName name) {
        name = super.preRegister(mbs, name);
        Object impl = getImplementation();
        if (impl instanceof MBeanRegistration)
            return ((MBeanRegistration) impl).preRegister(mbs, name);
        return name;
    }
    ...likewise for the other MBeanRegistration methods...
}
                                     
2006-07-20
EVALUATION

We don't want to add yet more boolean parameters to the constructors, so it looks as if we should have some other way of specifying this and other options.  Either a Map<String,?> parameter, or perhaps a nested StandardMBean.Options class that you can instantiate and pass to the constructor.  Like this:

public class StandardMBean {
    public static class Options implements Cloneable {
        public Options() {}
        public Options mxbean(boolean m) {
            Options clone = clone();
            clone.mxbean = m;
            return clone;
        }
        public Options forwardMBeanRegistration(boolean f) {...}
        public Options clone() {return super.clone();}
    }
    public <T> StandardMBean(T impl, Class<T> intf, Options opts) {...}
}

Used like this:
    StandardMBean.Options opts =
        new StandardMBean.Options().mxbean(true).forwardMBeanRegistration(true);
    StandardMBean mbean = new StandardMBean(myImpl, MyMBean.class, opts);
                                     
2006-07-20
EVALUATION

On the other hand we could add an additional MBeanRegistration parameter
instead of a boolean:

<T> StandardMBean(T impl, Class<T> clazz, MBeanRegistration regDelegate) {

   Then the logic would be:

   preRegister(...) {
       ...
       if (regDelegate != this && regDelegate != null) 
           regName = regDelegate.preRegister(...);
       ...
   }
}
                                     
2006-07-20
EVALUATION

One wrinkle here is the StandardMBean.setImplementation method.  Does this method cause MBeanRegistration.preRegister and .postRegister to be called on the wrapped object?  Does it cause .preDeregister and .postDeregister to be called on the previous wrapped object?
                                     
2007-07-27
EVALUATION

The proposed solution to the problem of .setImplementation is simply to say that this method is not allowed on a StandardMBean instance where the MBeanRegistration option has been set.

The proposed way of setting this option is through a new nested class StandardMBean.Options, which is a subclass of another new nested class JMX.MBeanOptions containing other options.
                                     
2008-06-18



Hardware and Software, Engineered to Work Together