下面列出了怎么用javax.management.openmbean.OpenType的API类实例代码及写法,或者点击链接到github查看源代码。
private ArrayType<?> getVersionedArrayType(ArrayType<?> type, String version)
throws OpenDataException
{
if (type.isPrimitiveArray()) {
return type;
}
OpenType<?> ot = getVersionedType(
type.getElementOpenType(),
version
);
if (ot instanceof SimpleType) {
return new ArrayType<>((SimpleType<?>)ot, type.isPrimitiveArray());
} else {
return new ArrayType<>(type.getDimension(), ot);
}
}
private MXBeanMapping
makeTabularMapping(Type objType, boolean sortedMap,
Type keyType, Type valueType,
MXBeanMappingFactory factory)
throws OpenDataException {
final String objTypeName = typeName(objType);
final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
final OpenType<?> keyOpenType = keyMapping.getOpenType();
final OpenType<?> valueOpenType = valueMapping.getOpenType();
final CompositeType rowType =
new CompositeType(objTypeName,
objTypeName,
keyValueArray,
keyValueArray,
new OpenType<?>[] {keyOpenType, valueOpenType});
final TabularType tabularType =
new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TabularMapping(objType, sortedMap, tabularType,
keyMapping, valueMapping);
}
private static boolean isTypeMatched(OpenType<?> ot1, OpenType<?> ot2) {
if (ot1 instanceof CompositeType) {
if (! (ot2 instanceof CompositeType))
return false;
if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2))
return false;
} else if (ot1 instanceof TabularType) {
if (! (ot2 instanceof TabularType))
return false;
if (!isTypeMatched((TabularType) ot1, (TabularType) ot2))
return false;
} else if (ot1 instanceof ArrayType) {
if (! (ot2 instanceof ArrayType))
return false;
if (!isTypeMatched((ArrayType<?>) ot1, (ArrayType<?>) ot2)) {
return false;
}
} else if (!ot1.equals(ot2)) {
return false;
}
return true;
}
private MXBeanMapping
makeTabularMapping(Type objType, boolean sortedMap,
Type keyType, Type valueType,
MXBeanMappingFactory factory)
throws OpenDataException {
final String objTypeName = typeName(objType);
final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
final OpenType<?> keyOpenType = keyMapping.getOpenType();
final OpenType<?> valueOpenType = valueMapping.getOpenType();
final CompositeType rowType =
new CompositeType(objTypeName,
objTypeName,
keyValueArray,
keyValueArray,
new OpenType<?>[] {keyOpenType, valueOpenType});
final TabularType tabularType =
new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TabularMapping(objType, sortedMap, tabularType,
keyMapping, valueMapping);
}
private MXBeanMapping
makeTabularMapping(Type objType, boolean sortedMap,
Type keyType, Type valueType,
MXBeanMappingFactory factory)
throws OpenDataException {
final String objTypeName = typeName(objType);
final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
final OpenType<?> keyOpenType = keyMapping.getOpenType();
final OpenType<?> valueOpenType = valueMapping.getOpenType();
final CompositeType rowType =
new CompositeType(objTypeName,
objTypeName,
keyValueArray,
keyValueArray,
new OpenType<?>[] {keyOpenType, valueOpenType});
final TabularType tabularType =
new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TabularMapping(objType, sortedMap, tabularType,
keyMapping, valueMapping);
}
private MXBeanMapping
makeTabularMapping(Type objType, boolean sortedMap,
Type keyType, Type valueType,
MXBeanMappingFactory factory)
throws OpenDataException {
final String objTypeName = typeName(objType);
final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
final OpenType<?> keyOpenType = keyMapping.getOpenType();
final OpenType<?> valueOpenType = valueMapping.getOpenType();
final CompositeType rowType =
new CompositeType(objTypeName,
objTypeName,
keyValueArray,
keyValueArray,
new OpenType<?>[] {keyOpenType, valueOpenType});
final TabularType tabularType =
new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TabularMapping(objType, sortedMap, tabularType,
keyMapping, valueMapping);
}
private MXBeanMapping
makeTabularMapping(Type objType, boolean sortedMap,
Type keyType, Type valueType,
MXBeanMappingFactory factory)
throws OpenDataException {
final String objTypeName = typeName(objType);
final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
final OpenType<?> keyOpenType = keyMapping.getOpenType();
final OpenType<?> valueOpenType = valueMapping.getOpenType();
final CompositeType rowType =
new CompositeType(objTypeName,
objTypeName,
keyValueArray,
keyValueArray,
new OpenType<?>[] {keyOpenType, valueOpenType});
final TabularType tabularType =
new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TabularMapping(objType, sortedMap, tabularType,
keyMapping, valueMapping);
}
private static boolean isTypeMatched(OpenType<?> ot1, OpenType<?> ot2) {
if (ot1 instanceof CompositeType) {
if (! (ot2 instanceof CompositeType))
return false;
if (!isTypeMatched((CompositeType) ot1, (CompositeType) ot2))
return false;
} else if (ot1 instanceof TabularType) {
if (! (ot2 instanceof TabularType))
return false;
if (!isTypeMatched((TabularType) ot1, (TabularType) ot2))
return false;
} else if (ot1 instanceof ArrayType) {
if (! (ot2 instanceof ArrayType))
return false;
if (!isTypeMatched((ArrayType<?>) ot1, (ArrayType<?>) ot2)) {
return false;
}
} else if (!ot1.equals(ot2)) {
return false;
}
return true;
}
private MXBeanMapping
makeTabularMapping(Type objType, boolean sortedMap,
Type keyType, Type valueType,
MXBeanMappingFactory factory)
throws OpenDataException {
final String objTypeName = typeName(objType);
final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
final OpenType<?> keyOpenType = keyMapping.getOpenType();
final OpenType<?> valueOpenType = valueMapping.getOpenType();
final CompositeType rowType =
new CompositeType(objTypeName,
objTypeName,
keyValueArray,
keyValueArray,
new OpenType<?>[] {keyOpenType, valueOpenType});
final TabularType tabularType =
new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TabularMapping(objType, sortedMap, tabularType,
keyMapping, valueMapping);
}
private MXBeanMapping
makeTabularMapping(Type objType, boolean sortedMap,
Type keyType, Type valueType,
MXBeanMappingFactory factory)
throws OpenDataException {
final String objTypeName = typeName(objType);
final MXBeanMapping keyMapping = factory.mappingForType(keyType, factory);
final MXBeanMapping valueMapping = factory.mappingForType(valueType, factory);
final OpenType<?> keyOpenType = keyMapping.getOpenType();
final OpenType<?> valueOpenType = valueMapping.getOpenType();
final CompositeType rowType =
new CompositeType(objTypeName,
objTypeName,
keyValueArray,
keyValueArray,
new OpenType<?>[] {keyOpenType, valueOpenType});
final TabularType tabularType =
new TabularType(objTypeName, objTypeName, rowType, keyArray);
return new TabularMapping(objType, sortedMap, tabularType,
keyMapping, valueMapping);
}
private OpenType<?> assertCompositeType(CompositeType composite, String name, String type, String description, boolean validateType){
Assert.assertTrue(composite.keySet().contains(name));
if (validateType) {
Assert.assertEquals(type, composite.getType(name).getTypeName());
}
Assert.assertEquals(description, composite.getDescription(name));
return composite.getType(name);
}
private CompositeType makeSessionsTypePost2_1() throws OpenDataException {
String typeName = "org.apache.cassandra.streaming.SessionInfo";
String description = "SessionInfo";
String[] itemNames = {
"connecting",
"peer",
"planId",
"receivingFiles",
"receivingSummaries",
"sendingFiles",
"sendingSummaries",
"sessionIndex",
"state"
};
String[] itemDescriptions = {
"connecting",
"peer",
"planId",
"receivingFiles",
"receivingSummaries",
"sendingFiles",
"sendingSummaries",
"sessionIndex",
"state"
};
OpenType[] itemTypes = {
SimpleType.STRING,
SimpleType.STRING,
SimpleType.STRING,
ArrayType.getArrayType(makeFilesType_2_1_20()),
ArrayType.getArrayType(makeSummariesType_pre_4_0()),
ArrayType.getArrayType(makeFilesType_2_1_20()),
ArrayType.getArrayType(makeSummariesType_pre_4_0()),
SimpleType.INTEGER,
SimpleType.STRING,
};
return new CompositeType(typeName, description, itemNames, itemDescriptions, itemTypes);
}
private static Descriptor typeDescriptor(OpenType<?> openType,
Type originalType) {
return new ImmutableDescriptor(
new String[] {"openType",
"originalType"},
new Object[] {openType,
originalTypeString(originalType)});
}
static CompositeType make(String className,
String description,
String[] itemNames,
String[] itemDescriptions,
OpenType[] itemTypes) {
try {
return new CompositeType(className,
description,
itemNames,
itemDescriptions,
itemTypes);
} catch (OpenDataException e) {
throw new Error(e);
}
}
private MXBeanMapping
makeArrayOrCollectionMapping(Type collectionType, Type elementType,
MXBeanMappingFactory factory)
throws OpenDataException {
final MXBeanMapping elementMapping = factory.mappingForType(elementType, factory);
final OpenType<?> elementOpenType = elementMapping.getOpenType();
final ArrayType<?> openType = ArrayType.getArrayType(elementOpenType);
final Class<?> elementOpenClass = elementMapping.getOpenClass();
final Class<?> openArrayClass;
final String openArrayClassName;
if (elementOpenClass.isArray())
openArrayClassName = "[" + elementOpenClass.getName();
else
openArrayClassName = "[L" + elementOpenClass.getName() + ";";
try {
openArrayClass = Class.forName(openArrayClassName);
} catch (ClassNotFoundException e) {
throw openDataException("Cannot obtain array class", e);
}
if (collectionType instanceof ParameterizedType) {
return new CollectionMapping(collectionType,
openType, openArrayClass,
elementMapping);
} else {
if (isIdentity(elementMapping)) {
return new IdentityMapping(collectionType,
openType);
} else {
return new ArrayMapping(collectionType,
openType,
openArrayClass,
elementMapping);
}
}
}
static synchronized OpenType[] getBaseGcInfoItemTypes() {
if (baseGcInfoItemTypes == null) {
OpenType<?> memoryUsageOpenType = memoryUsageMapType.getOpenType();
baseGcInfoItemTypes = new OpenType<?>[] {
SimpleType.LONG,
SimpleType.LONG,
SimpleType.LONG,
SimpleType.LONG,
memoryUsageOpenType,
memoryUsageOpenType,
};
}
return baseGcInfoItemTypes;
}
private static Descriptor typeDescriptor(OpenType<?> openType,
Type originalType) {
return new ImmutableDescriptor(
new String[] {"openType",
"originalType"},
new Object[] {openType,
originalTypeString(originalType)});
}
private static Descriptor typeDescriptor(OpenType<?> openType,
Type originalType) {
return new ImmutableDescriptor(
new String[] {"openType",
"originalType"},
new Object[] {openType,
originalTypeString(originalType)});
}
private static Descriptor typeDescriptor(OpenType<?> openType,
Type originalType) {
return new ImmutableDescriptor(
new String[] {"openType",
"originalType"},
new Object[] {openType,
originalTypeString(originalType)});
}
private MXBeanMapping
makeArrayOrCollectionMapping(Type collectionType, Type elementType,
MXBeanMappingFactory factory)
throws OpenDataException {
final MXBeanMapping elementMapping = factory.mappingForType(elementType, factory);
final OpenType<?> elementOpenType = elementMapping.getOpenType();
final ArrayType<?> openType = ArrayType.getArrayType(elementOpenType);
final Class<?> elementOpenClass = elementMapping.getOpenClass();
final Class<?> openArrayClass;
final String openArrayClassName;
if (elementOpenClass.isArray())
openArrayClassName = "[" + elementOpenClass.getName();
else
openArrayClassName = "[L" + elementOpenClass.getName() + ";";
try {
openArrayClass = Class.forName(openArrayClassName);
} catch (ClassNotFoundException e) {
throw openDataException("Cannot obtain array class", e);
}
if (collectionType instanceof ParameterizedType) {
return new CollectionMapping(collectionType,
openType, openArrayClass,
elementMapping);
} else {
if (isIdentity(elementMapping)) {
return new IdentityMapping(collectionType,
openType);
} else {
return new ArrayMapping(collectionType,
openType,
openArrayClass,
elementMapping);
}
}
}
@Override
public CompositeType getOpenType() {
try {
return new CompositeType(
"property",
JmxLogger.ROOT_LOGGER.propertyCompositeType(),
new String[] {"name", "value"},
new String[] { JmxLogger.ROOT_LOGGER.propertyName(), JmxLogger.ROOT_LOGGER.propertyValue()},
new OpenType[] {SimpleType.STRING, getConverter().getOpenType()});
} catch (OpenDataException e) {
throw new RuntimeException(e);
}
}
static ArrayType make(int dims, OpenType baseType) {
try {
return new ArrayType(dims, baseType);
} catch (OpenDataException e) {
throw new Error(e);
}
}
static CompositeType make(String className,
String description,
String[] itemNames,
String[] itemDescriptions,
OpenType[] itemTypes) {
try {
return new CompositeType(className,
description,
itemNames,
itemDescriptions,
itemTypes);
} catch (OpenDataException e) {
throw new Error(e);
}
}
static synchronized OpenType[] getBaseGcInfoItemTypes() {
if (baseGcInfoItemTypes == null) {
OpenType<?> memoryUsageOpenType = memoryUsageMapType.getOpenType();
baseGcInfoItemTypes = new OpenType<?>[] {
SimpleType.LONG,
SimpleType.LONG,
SimpleType.LONG,
SimpleType.LONG,
memoryUsageOpenType,
memoryUsageOpenType,
};
}
return baseGcInfoItemTypes;
}
private static Class<?> makeOpenClass(Type javaType, OpenType<?> openType) {
if (javaType instanceof Class<?> && ((Class<?>) javaType).isPrimitive())
return (Class<?>) javaType;
try {
String className = openType.getClassName();
return Class.forName(className, false, MXBeanMapping.class.getClassLoader());
} catch (ClassNotFoundException e) {
throw new RuntimeException(e); // should not happen
}
}
@Override
public OpenType<?> getOpenType() {
try {
return ArrayType.getArrayType(getConverter(valueTypeNode, null).getOpenType());
} catch (OpenDataException e) {
throw new RuntimeException(e);
}
}
private MXBeanMapping
makeArrayOrCollectionMapping(Type collectionType, Type elementType,
MXBeanMappingFactory factory)
throws OpenDataException {
final MXBeanMapping elementMapping = factory.mappingForType(elementType, factory);
final OpenType<?> elementOpenType = elementMapping.getOpenType();
final ArrayType<?> openType = ArrayType.getArrayType(elementOpenType);
final Class<?> elementOpenClass = elementMapping.getOpenClass();
final Class<?> openArrayClass;
final String openArrayClassName;
if (elementOpenClass.isArray())
openArrayClassName = "[" + elementOpenClass.getName();
else
openArrayClassName = "[L" + elementOpenClass.getName() + ";";
try {
openArrayClass = Class.forName(openArrayClassName);
} catch (ClassNotFoundException e) {
throw openDataException("Cannot obtain array class", e);
}
if (collectionType instanceof ParameterizedType) {
return new CollectionMapping(collectionType,
openType, openArrayClass,
elementMapping);
} else {
if (isIdentity(elementMapping)) {
return new IdentityMapping(collectionType,
openType);
} else {
return new ArrayMapping(collectionType,
openType,
openArrayClass,
elementMapping);
}
}
}
private MXBeanMapping
makeArrayOrCollectionMapping(Type collectionType, Type elementType,
MXBeanMappingFactory factory)
throws OpenDataException {
final MXBeanMapping elementMapping = factory.mappingForType(elementType, factory);
final OpenType<?> elementOpenType = elementMapping.getOpenType();
final ArrayType<?> openType = ArrayType.getArrayType(elementOpenType);
final Class<?> elementOpenClass = elementMapping.getOpenClass();
final Class<?> openArrayClass;
final String openArrayClassName;
if (elementOpenClass.isArray())
openArrayClassName = "[" + elementOpenClass.getName();
else
openArrayClassName = "[L" + elementOpenClass.getName() + ";";
try {
openArrayClass = Class.forName(openArrayClassName);
} catch (ClassNotFoundException e) {
throw openDataException("Cannot obtain array class", e);
}
if (collectionType instanceof ParameterizedType) {
return new CollectionMapping(collectionType,
openType, openArrayClass,
elementMapping);
} else {
if (isIdentity(elementMapping)) {
return new IdentityMapping(collectionType,
openType);
} else {
return new ArrayMapping(collectionType,
openType,
openArrayClass,
elementMapping);
}
}
}
private static void validateType(CompositeData data) {
CompositeType type = data.getCompositeType();
Set<String> keys = Arrays.stream(names).collect(Collectors.toSet());
if (!type.keySet().equals(keys)) {
throw new RuntimeException("key not matched: " + type.keySet().toString());
}
for (int i=0; i < names.length; i++) {
OpenType t = type.getType(names[i]);
if (t != types[i]) {
throw new AssertionError(names[i] + ": type not matched: " +
t + " expected: " + types[i]);
}
}
}
static ArrayType make(int dims, OpenType baseType) {
try {
return new ArrayType(dims, baseType);
} catch (OpenDataException e) {
throw new Error(e);
}
}