use of javax.management.openmbean.ArrayType in project jdk8u_jdk by JetBrains.
the class ArrayTypeTest method main.
public static void main(String[] args) throws Exception {
System.out.println("\nTest that Open MBeans support arrays of primitive types.");
int index = 0;
int error = 0;
//
// Constructor tests
//
System.out.println("\n>>> Constructor tests");
System.out.println("\nArrayType<String[][]> a1 = new ArrayType<String[][]>(2, SimpleType.STRING)");
ArrayType<String[][]> a1 = new ArrayType<String[][]>(2, SimpleType.STRING);
printArrayType(a1);
error += checkResult(index++, a1);
System.out.println("\nArrayType<int[]> a2 = new ArrayType<int[]>(SimpleType.INTEGER, true)");
ArrayType<int[]> a2 = new ArrayType<int[]>(SimpleType.INTEGER, true);
printArrayType(a2);
error += checkResult(index++, a2);
System.out.println("\nArrayType<Integer[]> a3 = new ArrayType<Integer[]>(SimpleType.INTEGER, false)");
ArrayType<Integer[]> a3 = new ArrayType<Integer[]>(SimpleType.INTEGER, false);
printArrayType(a3);
error += checkResult(index++, a3);
System.out.println("\nArrayType<int[][][][]> a4 = new ArrayType<int[][][][]>(3, a2)");
ArrayType<int[][][][]> a4 = new ArrayType<int[][][][]>(3, a2);
printArrayType(a4);
error += checkResult(index++, a4);
System.out.println("\nArrayType<Integer[][][][]> a5 = new ArrayType<Integer[][][][]>(3, a3)");
ArrayType<Integer[][][][]> a5 = new ArrayType<Integer[][][][]>(3, a3);
printArrayType(a5);
error += checkResult(index++, a5);
System.out.println("\nArrayType<String[]> a6 = new ArrayType<String[]>(SimpleType.STRING, false)");
ArrayType<String[]> a6 = new ArrayType<String[]>(SimpleType.STRING, false);
printArrayType(a6);
error += checkResult(index++, a6);
System.out.println("\nArrayType<String[]> a7 = new ArrayType<String[]>(SimpleType.STRING, true)");
// skip this dummy entry in the toStringResult array
index++;
try {
ArrayType<String[]> a7 = new ArrayType<String[]>(SimpleType.STRING, true);
System.out.println("\tDid not get expected OpenDataException!");
System.out.println("Test failed!");
error++;
} catch (OpenDataException e) {
System.out.println("\tGot expected OpenDataException: " + e);
System.out.println("Test passed!");
}
//
// Factory tests
//
System.out.println("\n>>> Factory tests");
System.out.println("\nArrayType<Integer[]> a8 = ArrayType.getArrayType(SimpleType.INTEGER)");
ArrayType<Integer[]> a8 = ArrayType.getArrayType(SimpleType.INTEGER);
printArrayType(a8);
error += checkResult(index++, a8);
System.out.println("\nArrayType<Integer[][]> a9 = ArrayType.getArrayType(a8)");
ArrayType<Integer[][]> a9 = ArrayType.getArrayType(a8);
printArrayType(a9);
error += checkResult(index++, a9);
System.out.println("\nArrayType<int[][]> a10 = ArrayType.getPrimitiveArrayType(int[][].class)");
ArrayType<int[][]> a10 = ArrayType.getPrimitiveArrayType(int[][].class);
printArrayType(a10);
error += checkResult(index++, a10);
System.out.println("\nArrayType<int[][][]> a11 = ArrayType.getArrayType(a10)");
ArrayType<int[][][]> a11 = ArrayType.getArrayType(a10);
printArrayType(a11);
error += checkResult(index++, a11);
System.out.println("\nArrayType<float[]> a12 = ArrayType.getPrimitiveArrayType(float[].class)");
ArrayType<float[]> a12 = ArrayType.getPrimitiveArrayType(float[].class);
printArrayType(a12);
error += checkResult(index++, a12);
System.out.println("\nArrayType<float[][]> a13 = ArrayType.getArrayType(a12)");
ArrayType<float[][]> a13 = ArrayType.getArrayType(a12);
printArrayType(a13);
error += checkResult(index++, a13);
System.out.println("\nArrayType<ObjectName[]> a14 = ArrayType.getArrayType(SimpleType.OBJECTNAME)");
ArrayType<ObjectName[]> a14 = ArrayType.getArrayType(SimpleType.OBJECTNAME);
printArrayType(a14);
error += checkResult(index++, a14);
System.out.println("\nArrayType<ObjectName[][]> a15 = ArrayType.getArrayType(a14)");
ArrayType<ObjectName[][]> a15 = ArrayType.getArrayType(a14);
printArrayType(a15);
error += checkResult(index++, a15);
System.out.println("\nArrayType<String[][][]> a16 = new ArrayType<String[][][]>(3, SimpleType.STRING)");
ArrayType<String[][][]> a16 = new ArrayType<String[][][]>(3, SimpleType.STRING);
printArrayType(a16);
error += checkResult(index++, a16);
System.out.println("\nArrayType<String[]> a17 = new ArrayType<String[]>(1, SimpleType.STRING)");
System.out.println("ArrayType<String[][]> a18 = new ArrayType<String[][]>(1, a17)");
System.out.println("ArrayType<String[][][]> a19 = new ArrayType<String[][][]>(1, a18)");
ArrayType<String[]> a17 = new ArrayType<String[]>(1, SimpleType.STRING);
ArrayType<String[][]> a18 = new ArrayType<String[][]>(1, a17);
ArrayType<String[][][]> a19 = new ArrayType<String[][][]>(1, a18);
printArrayType(a19);
error += checkResult(index++, a19);
//
// Serialization tests
//
System.out.println("\n>>> Serialization tests\n");
ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class);
ArrayType<int[]> i2 = null;
ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class);
ArrayType<boolean[][]> b2 = null;
ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG);
ArrayType<Long[]> l2 = null;
ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE);
ArrayType<Double[]> d2 = null;
// serialize the objects
try {
FileOutputStream fo = new FileOutputStream("serial.tmp");
ObjectOutputStream so = new ObjectOutputStream(fo);
System.out.println("Serialize ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class)");
so.writeObject(i1);
System.out.println("Serialize ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class)");
so.writeObject(b1);
System.out.println("Serialize ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG)");
so.writeObject(l1);
System.out.println("Serialize ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE)");
so.writeObject(d1);
so.flush();
} catch (Exception e) {
System.out.println(e);
System.exit(1);
}
// deserialize the objects
try {
FileInputStream fi = new FileInputStream("serial.tmp");
ObjectInputStream si = new ObjectInputStream(fi);
System.out.println("Deserialize ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class)");
i2 = (ArrayType<int[]>) si.readObject();
System.out.println("Deserialize ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class)");
b2 = (ArrayType<boolean[][]>) si.readObject();
System.out.println("Deserialize ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG)");
l2 = (ArrayType<Long[]>) si.readObject();
System.out.println("Deserialize ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE)");
d2 = (ArrayType<Double[]>) si.readObject();
} catch (Exception e) {
System.out.println(e);
System.exit(1);
}
if (i1.toString().equals(toStringResult[index++]) && i1.toString().equals(i2.toString())) {
System.out.println("Test passed for ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class)");
} else {
System.out.println("Test failed for ArrayType<int[]> i1 = ArrayType.getPrimitiveArrayType(int[].class)");
error++;
}
if (b1.toString().equals(toStringResult[index++]) && b1.toString().equals(b2.toString())) {
System.out.println("Test passed for ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class)");
} else {
System.out.println("Test failed for ArrayType<boolean[][]> b1 = ArrayType.getPrimitiveArrayType(boolean[][].class)");
error++;
}
if (l1.toString().equals(toStringResult[index++]) && l1.toString().equals(l2.toString())) {
System.out.println("Test passed for ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG)");
} else {
System.out.println("Test failed for ArrayType<Long[]> l1 = ArrayType.getArrayType(SimpleType.LONG)");
error++;
}
if (d1.toString().equals(toStringResult[index++]) && d1.toString().equals(d2.toString())) {
System.out.println("Test passed for ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE)");
} else {
System.out.println("Test failed for ArrayType<Double[]> d1 = ArrayType.getArrayType(SimpleType.DOUBLE)");
error++;
}
//
// Test getters
//
System.out.println("\n>>> Getter tests");
System.out.println("\nArrayType<Integer[][]> g1 = new ArrayType<Integer[][]>(2, SimpleType.INTEGER)");
ArrayType<Integer[][]> g1 = new ArrayType<Integer[][]>(2, SimpleType.INTEGER);
printArrayType(g1);
error += checkGetters(g1, "[[Ljava.lang.Integer;", "2-dimension array of java.lang.Integer", "[[Ljava.lang.Integer;", true, false, 2);
System.out.println("\nArrayType<int[][]> g2 = ArrayType.getPrimitiveArrayType(int[][].class)");
ArrayType<int[][]> g2 = ArrayType.getPrimitiveArrayType(int[][].class);
printArrayType(g2);
error += checkGetters(g2, "[[I", "2-dimension array of int", "[[I", true, true, 2);
if (error > 0) {
final String msg = "\nTest FAILED! Got " + error + " error(s)";
System.out.println(msg);
throw new IllegalArgumentException(msg);
} else {
System.out.println("\nTest PASSED!");
}
}
use of javax.management.openmbean.ArrayType in project karaf by apache.
the class JmxReference method createReferenceType.
private static CompositeType createReferenceType() {
try {
String description = "This type encapsulates Scr references";
String[] itemNames = ScrServiceMBean.REFERENCE;
OpenType[] itemTypes = new OpenType[itemNames.length];
String[] itemDescriptions = new String[itemNames.length];
itemTypes[0] = SimpleType.STRING;
itemTypes[1] = SimpleType.BOOLEAN;
itemTypes[2] = SimpleType.STRING;
itemTypes[3] = SimpleType.STRING;
itemTypes[4] = SimpleType.STRING;
itemTypes[5] = new ArrayType(1, SimpleType.STRING);
itemDescriptions[0] = "The name of the reference";
itemDescriptions[1] = "The state of the reference";
itemDescriptions[2] = "The cardinality of the reference";
itemDescriptions[3] = "The availability of the reference";
itemDescriptions[4] = "The policy of the reference";
itemDescriptions[5] = "The bound services";
return new CompositeType("Reference", description, itemNames, itemDescriptions, itemTypes);
} catch (OpenDataException e) {
throw new IllegalStateException("Unable to build reference type", e);
}
}
use of javax.management.openmbean.ArrayType in project geode by apache.
the class OpenTypeConverter method makeArrayOrCollectionConverter.
private static OpenTypeConverter makeArrayOrCollectionConverter(Type collectionType, Type elementType) throws OpenDataException {
final OpenTypeConverter elementConverter = toConverter(elementType);
final OpenType elementOpenType = elementConverter.getOpenType();
final ArrayType openType = new ArrayType(1, elementOpenType);
final Class elementOpenClass = elementConverter.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 CollectionConverter(collectionType, openType, openArrayClass, elementConverter);
} else {
if (elementConverter.isIdentity()) {
return new IdentityConverter(collectionType, openType, openArrayClass);
} else {
return new ArrayConverter(collectionType, openType, openArrayClass, elementConverter);
}
}
}
use of javax.management.openmbean.ArrayType in project fabric8 by jboss-fuse.
the class JSONTypeGenerator method toOpenData.
public static Object toOpenData(OpenType<?> otype, ClassLoader classLoader, Object value) throws OpenDataException {
Object result;
if (otype instanceof CompositeType && value instanceof JSONObject) {
StringToOpenTypeConverter converter = converters.getToOpenTypeConverter();
result = converter.convertToObject(otype, value);
} else if (otype instanceof TabularType && value instanceof JSONObject) {
StringToOpenTypeConverter converter = converters.getToOpenTypeConverter();
result = converter.convertToObject(otype, value);
} else if (otype instanceof ArrayType && value instanceof JSONArray) {
StringToOpenTypeConverter converter = converters.getToOpenTypeConverter();
result = converter.convertToObject(otype, value);
} else {
result = OpenTypeGenerator.toOpenData(otype, value);
}
boolean isAssignable = result == null || otype.isValue(result);
IllegalStateAssertion.assertTrue(isAssignable, "Value " + result + " is not a value of: " + otype);
return result;
}
use of javax.management.openmbean.ArrayType in project druid by alibaba.
the class JdbcStatManager method getDataSourceCompositeType.
public static CompositeType getDataSourceCompositeType() throws JMException {
if (COMPOSITE_TYPE != null) {
return COMPOSITE_TYPE;
}
OpenType<?>[] indexTypes = new OpenType<?>[] { //
SimpleType.LONG, //
SimpleType.STRING, //
SimpleType.STRING, //
new ArrayType<SimpleType<String>>(SimpleType.STRING, false), //
SimpleType.DATE, //
SimpleType.STRING, //
SimpleType.STRING, //
SimpleType.INTEGER, //
SimpleType.INTEGER, //
SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.STRING, //
SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.INTEGER, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.STRING, //
SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.DATE, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.INTEGER, //
SimpleType.LONG, SimpleType.DATE, //
SimpleType.LONG, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.STRING, SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.STRING, //
SimpleType.STRING, //
SimpleType.LONG, //
SimpleType.INTEGER, //
SimpleType.LONG, //
SimpleType.DATE, //
SimpleType.LONG, //
SimpleType.LONG, //
new ArrayType<Long>(SimpleType.LONG, true), // 55 -
new ArrayType<Long>(SimpleType.LONG, true) //
//
};
String[] indexNames = { // 0 - 4
"ID", "URL", "Name", "FilterClasses", //
"CreatedTime", // 5 - 9
"RawUrl", "RawDriverClassName", "RawDriverMajorVersion", "RawDriverMinorVersion", //
"Properties", // 10 - 14
"ConnectionActiveCount", "ConnectionActiveCountMax", "ConnectionCloseCount", "ConnectionCommitCount", //
"ConnectionRollbackCount", // 15 - 19
"ConnectionConnectLastTime", "ConnectionConnectErrorCount", "ConnectionConnectErrorLastTime", "ConnectionConnectErrorLastMessage", //
"ConnectionConnectErrorLastStackTrace", // 20 - 24
"StatementCreateCount", "StatementPrepareCount", "StatementPreCallCount", "StatementExecuteCount", //
"StatementRunningCount", // 25 - 29
"StatementConcurrentMax", "StatementCloseCount", "StatementErrorCount", "StatementLastErrorTime", //
"StatementLastErrorMessage", // 30 - 34
"StatementLastErrorStackTrace", "StatementExecuteMillisTotal", "ConnectionConnectingCount", "StatementExecuteLastTime", //
"ResultSetCloseCount", // 35 -39
"ResultSetOpenCount", "ResultSetOpenningCount", "ResultSetOpenningMax", "ResultSetFetchRowCount", //
"ResultSetLastOpenTime", //
"ResultSetErrorCount", //
"ResultSetOpenningMillisTotal", //
"ResultSetLastErrorTime", //
"ResultSetLastErrorMessage", //
"ResultSetLastErrorStackTrace", //
"ConnectionConnectCount", //
"ConnectionErrorLastMessage", //
"ConnectionErrorLastStackTrace", //
"ConnectionConnectMillisTotal", "ConnectionConnectingCountMax", //
"ConnectionConnectMillisMax", //
"ConnectionErrorLastTime", //
"ConnectionAliveMillisMax", //
"ConnectionAliveMillisMin", //
"ConnectionHistogram", // 55 -
"StatementHistogram" //
};
COMPOSITE_TYPE = new CompositeType("DataSourceStatistic", "DataSource Statistic", indexNames, indexNames, indexTypes);
return COMPOSITE_TYPE;
}
Aggregations