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.
|
|
|
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?
|
|
|
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...
}
|
|
|
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);
|
|
|
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(...);
...
}
}
|
|
|
|