-
- 所有已知实现类:
-
GarbageCollectionNotificationInfo,GcInfo
public interface CompositeDataViewJava类可以实现此接口,以指示MXBean框架如何将其转换为
CompositeData。使用此类的典型方法是向
CompositeData添加额外的项目,以及MXBean框架提供的CompositeType中声明的CompositeType。 要执行此操作,您必须创建另一个具有所有相同项目的CompositeType以及您的额外项目。例如,假设您有一个类
Measure,它包含一个名为units的字符串和一个value,它是long或double。 它可能看起来像这样:public class Measure implements CompositeDataView { private String units; private Number value; // a Long or a Double public Measure(String units, Number value) { this.units = units; this.value = value; } public static Measure from(CompositeData cd) { return new Measure((String) cd.get("units"), (Number) cd.get("value")); } public String getUnits() { return units; } // Can't be called getValue(), because Number is not a valid type // in an MXBean, so the implied "value" property would be rejected. public Number _getValue() { return value; } public CompositeData toCompositeData(CompositeType ct) { try {List<String> itemNames = new ArrayList<String>(ct.keySet());List<String> itemDescriptions = new ArrayList<String>();List<OpenType<?>> itemTypes = new ArrayList<OpenType<?>>();for (String item : itemNames) { itemDescriptions.add(ct.getDescription(item)); itemTypes.add(ct.getType(item)); } itemNames.add("value"); itemDescriptions.add("long or double value of the measure"); itemTypes.add((value instanceof Long) ? SimpleType.LONG : SimpleType.DOUBLE); CompositeType xct = new CompositeType(ct.getTypeName(), ct.getDescription(), itemNames.toArray(new String[0]), itemDescriptions.toArray(new String[0]), itemTypes.toArray(new OpenType<?>[0])); CompositeData cd = new CompositeDataSupport(xct, new String[] {"units", "value"}, new Object[] {units, value}); assert ct.isValue(cd); // check we've done it right return cd; } catch (Exception e) { throw new RuntimeException(e); } } }该
CompositeType将出现在openType的领域Descriptor对于这种类型的属性或操作中,只显示units项目,但实际CompositeData所产生将同时拥有units和value。- 从以下版本开始:
- 1.6
- 另请参见:
-
MXBean
-
-
方法摘要
所有方法 实例方法 抽象方法 变量和类型 方法 描述 CompositeDatatoCompositeData(CompositeType ct)返回与此对象中的值对应的CompositeData。
-
-
-
方法详细信息
-
toCompositeData
CompositeData toCompositeData(CompositeType ct)
返回与此对象中的值对应的
CompositeData。 返回值通常应为CompositeDataSupport的实例,或通过writeReplace方法序列化为CompositeDataSupport的类。 否则,接收对象的远程客户端可能无法重建它。- 参数
-
ct- 返回值的预期CompositeType。 如果返回值为cd,则cd.getCompositeType().equals(ct)应为true。 典型地,这将是因为cd是CompositeDataSupport与构造ct作为其CompositeType。 - 结果
-
CompositeData。
-
-