我正在尝试创建一个 MXBean 操作,该操作将返回一个没有属性的抽象类型(实际类型及其属性将在运行时确定)。我的数据模型可以简单地说如下:
public interface I extends CompositeDataView {
// empty
}
public final class A implements I {
private final String foo;
@ConstructorProperties({"foo"})
public A(final String foo) {/* ... */}
public String getFoo() {/* ... */}
@Override
public CompositeData toCompositeData(CompositeType ct) {/* ... */}
public static A from(final CompositeData cd) {/* ... */}
}
public final class B implements I {
private final String bar;
@ConstructorProperties({"bar"})
public B(final String bar) {/* ... */}
public String getBar() {/* ... */}
@Override
public CompositeData toCompositeData(CompositeType ct) {/* ... */}
public static B from(final CompositeData cd) {/* ... */}
}
... MXBean 操作签名是:
@MXBean
public interface Baz {
I f();
}
该操作可以返回 A
具有foo
属性的实例或具有属性的B
实例bar
。当然,当NotCompliantMBeanException
我尝试注册MBean
实例时,我会立即看到一个闪亮的信息:
Caused by: javax.management.openmbean.OpenDataException: Can't map I to an open data type
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeCompositeMapping(DefaultMXBeanMappingFactory.java:458)
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.makeMapping(DefaultMXBeanMappingFactory.java:292)
at com.sun.jmx.mbeanserver.DefaultMXBeanMappingFactory.mappingForType(DefaultMXBeanMappingFactory.java:257)
似乎我可以用常规MBean
s 做一些事情,Serializable
但不能用MXBean
s 和CompositeDataView
. 还是我错了?