-
- 所有已知实现类:
-
GarbageCollectionNotificationInfo,GcInfo
public interface CompositeDataViewJava类可以实现此接口,以指示如何通过MXBean框架将其转换为
CompositeData。使用此类的一个典型方法是除了在MXBean框架提供的
CompositeType中声明的内容CompositeData,还可以向CompositeData添加额外的项目。 为此,您必须创建另一个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
-
-
方法摘要
所有方法 接口方法 抽象方法 Modifier and Type 方法 描述 CompositeDatatoCompositeData(CompositeType ct)返回对应于此对象中的值的CompositeData。
-
-
-
方法详细信息
-
toCompositeData
CompositeData toCompositeData(CompositeType ct)
返回一个
CompositeData对应于该对象中的值。 返回的值通常应为CompositeDataSupport的实例,或通过writeReplace方法序列化为CompositeDataSupport的类。 否则,接收对象的远程客户端可能无法重构。- 参数
-
ct- 预期的CompositeType的返回值。 如果返回值是cd,然后cd.getCompositeType().equals(ct)应该是真实的。 通常这将是因为cd是一个CompositeDataSupport构造与ct作为其CompositeType。 - 结果
-
CompositeData。
-
-