javax.management.openmbean.ArrayType Java Examples

The following examples show how to use javax.management.openmbean.ArrayType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultMXBeanMappingFactory.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
CollectionMapping(Type targetType,
                  ArrayType<?> openArrayType,
                  Class<?> openArrayClass,
                  MXBeanMapping elementMapping) {
    super(targetType, openArrayType);
    this.elementMapping = elementMapping;

    /* Determine the concrete class to be used when converting
       back to this Java type.  We convert all Lists to ArrayList
       and all Sets to TreeSet.  (TreeSet because it is a SortedSet,
       so works for both Set and SortedSet.)  */
    Type raw = ((ParameterizedType) targetType).getRawType();
    Class<?> c = (Class<?>) raw;
    final Class<?> collC;
    if (c == List.class)
        collC = ArrayList.class;
    else if (c == Set.class)
        collC = HashSet.class;
    else if (c == SortedSet.class)
        collC = TreeSet.class;
    else { // can't happen
        assert(false);
        collC = null;
    }
    collectionClass = Util.cast(collC);
}
 
Example #2
Source File: DefaultMXBeanMappingFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
CollectionMapping(Type targetType,
                  ArrayType<?> openArrayType,
                  Class<?> openArrayClass,
                  MXBeanMapping elementMapping) {
    super(targetType, openArrayType);
    this.elementMapping = elementMapping;

    /* Determine the concrete class to be used when converting
       back to this Java type.  We convert all Lists to ArrayList
       and all Sets to TreeSet.  (TreeSet because it is a SortedSet,
       so works for both Set and SortedSet.)  */
    Type raw = ((ParameterizedType) targetType).getRawType();
    Class<?> c = (Class<?>) raw;
    final Class<?> collC;
    if (c == List.class)
        collC = ArrayList.class;
    else if (c == Set.class)
        collC = HashSet.class;
    else if (c == SortedSet.class)
        collC = TreeSet.class;
    else { // can't happen
        assert(false);
        collC = null;
    }
    collectionClass = Util.cast(collC);
}
 
Example #3
Source File: DefaultMXBeanMappingFactory.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
CollectionMapping(Type targetType,
                  ArrayType<?> openArrayType,
                  Class<?> openArrayClass,
                  MXBeanMapping elementMapping) {
    super(targetType, openArrayType);
    this.elementMapping = elementMapping;

    /* Determine the concrete class to be used when converting
       back to this Java type.  We convert all Lists to ArrayList
       and all Sets to TreeSet.  (TreeSet because it is a SortedSet,
       so works for both Set and SortedSet.)  */
    Type raw = ((ParameterizedType) targetType).getRawType();
    Class<?> c = (Class<?>) raw;
    final Class<?> collC;
    if (c == List.class)
        collC = ArrayList.class;
    else if (c == Set.class)
        collC = HashSet.class;
    else if (c == SortedSet.class)
        collC = TreeSet.class;
    else { // can't happen
        assert(false);
        collC = null;
    }
    collectionClass = Util.cast(collC);
}
 
Example #4
Source File: ExceptionStatsTest.java    From datakernel with Apache License 2.0 6 votes vote down vote up
@Before
public void before() throws OpenDataException {
	exceptionDetailsItemNames = new String[]{
			"lastException",
			"lastExceptionCausedObject",
			"lastExceptionStackTrace",
			"lastExceptionTimestamp",
			"totalExceptions"
	};

	exceptionDetailsItemTypes = new OpenType<?>[]{
			SimpleType.STRING,
			SimpleType.STRING,
			new ArrayType<>(1, SimpleType.STRING),
			SimpleType.LONG,
			SimpleType.INTEGER
	};
}
 
Example #5
Source File: ExpressionTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testByteArrayObject() throws Exception {
    ModelNode description = createDescription(ModelType.OBJECT, ModelType.BYTES);
    TypeConverter converter = getConverter(description);

    assertMapType(assertCast(TabularType.class, converter.getOpenType()), SimpleType.STRING, ArrayType.getPrimitiveArrayType(byte[].class));

    ModelNode node = new ModelNode();
    node.get("one").set(new byte[] {1,2});
    node.get("two").set(new byte[] {3,4});

    TabularData tabularData = assertCast(TabularData.class, converter.fromModelNode(node));
    Assert.assertEquals(2, tabularData.size());
    Assert.assertTrue(Arrays.equals(new byte[] {1,2}, (byte[])tabularData.get(new Object[] {"one"}).get("value")));
    Assert.assertTrue(Arrays.equals(new byte[] {3,4}, (byte[])tabularData.get(new Object[] {"two"}).get("value")));

    //Allow plain map as well? Yeah why not!
    Map<String, byte[]> map = new HashMap<String, byte[]>();
    map.put("one", new byte[] {1,2});
    map.put("two", new byte[] {3,4});
    Assert.assertEquals(node, converter.toModelNode(map));
}
 
Example #6
Source File: LazyCompositeData.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #7
Source File: TypeVersionMapper.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example #8
Source File: LazyCompositeData.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #9
Source File: LazyCompositeData.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: LegacyTypeConverterUnitTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Test
public void testSimpleTypeExpressionList() throws Exception {
    ModelNode description = createDescription(ModelType.LIST, ModelType.INT);
    description.get(EXPRESSIONS_ALLOWED).set(true);
    TypeConverter converter = getConverter(description);
    ArrayType<?> arrayType = assertCast(ArrayType.class, converter.getOpenType());
    Assert.assertEquals(SimpleType.INTEGER, arrayType.getElementOpenType());

    ModelNode node = new ModelNode();
    node.add().set(new ValueExpression("${this.should.not.exist.!!!!!:1}"));
    node.add().set(new ValueExpression("${this.should.not.exist.!!!!!:2}"));

    Integer[] data = assertCast(Integer[].class, converter.fromModelNode(node));
    Assert.assertEquals(Integer.valueOf(1), data[0]);
    Assert.assertEquals(Integer.valueOf(2), data[1]);
}
 
Example #11
Source File: LazyCompositeData.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
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;
}
 
Example #12
Source File: DefaultMXBeanMappingFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
CollectionMapping(Type targetType,
                  ArrayType<?> openArrayType,
                  Class<?> openArrayClass,
                  MXBeanMapping elementMapping) {
    super(targetType, openArrayType);
    this.elementMapping = elementMapping;

    /* Determine the concrete class to be used when converting
       back to this Java type.  We convert all Lists to ArrayList
       and all Sets to TreeSet.  (TreeSet because it is a SortedSet,
       so works for both Set and SortedSet.)  */
    Type raw = ((ParameterizedType) targetType).getRawType();
    Class<?> c = (Class<?>) raw;
    final Class<?> collC;
    if (c == List.class)
        collC = ArrayList.class;
    else if (c == Set.class)
        collC = HashSet.class;
    else if (c == SortedSet.class)
        collC = TreeSet.class;
    else { // can't happen
        assert(false);
        collC = null;
    }
    collectionClass = Util.cast(collC);
}
 
Example #13
Source File: MXBeanTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void testMXBean(MBeanServer mbs, ObjectName on)
        throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    int nattrs = attrs.length;
    if (mbi.getAttributes().length != 1)
        failure("wrong number of attributes: " + attrs);
    else {
        MBeanAttributeInfo mbai = attrs[0];
        if (mbai.getName().equals("Ints")
            && mbai.isReadable() && !mbai.isWritable()
            && mbai.getDescriptor().getFieldValue("openType")
                .equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
            && attrs[0].getType().equals("[I"))
            success("MBeanAttributeInfo");
        else
            failure("MBeanAttributeInfo: " + mbai);
    }

    int[] ints = (int[]) mbs.getAttribute(on, "Ints");
    if (equal(ints, new int[] {1, 2, 3}, null))
        success("getAttribute");
    else
        failure("getAttribute: " + Arrays.toString(ints));

    ExplicitMXBean proxy =
        JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
    int[] pints = proxy.getInts();
    if (equal(pints, new int[] {1, 2, 3}, null))
        success("getAttribute through proxy");
    else
        failure("getAttribute through proxy: " + Arrays.toString(pints));
}
 
Example #14
Source File: MerlinMXBean.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static ArrayType make(int dims, OpenType baseType) {
    try {
        return new ArrayType(dims, baseType);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #15
Source File: ArrayTypeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void printArrayType(ArrayType a) {
    System.out.println("\tArrayType.getClassName() = " + a.getClassName());
    System.out.println("\tArrayType.getDescription() = " + a.getDescription());
    System.out.println("\tArrayType.getTypeName() = " + a.getTypeName());
    System.out.println("\tArrayType.isArray() = " + a.isArray());
    System.out.println("\tArrayType.isPrimitiveArray() = " + a.isPrimitiveArray());
    System.out.println("\tArrayType.getDimension() = " + a.getDimension());
}
 
Example #16
Source File: ArrayTypeTest.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static int checkResult(int i, ArrayType a) {
    if (a.toString().equals(toStringResult[i])) {
        System.out.println("Test passed!");
        return 0;
    } else {
        System.out.println("Test failed!");
        return 1;
    }
}
 
Example #17
Source File: MXBeanTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void testMXBean(MBeanServer mbs, ObjectName on)
        throws Exception {
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    MBeanAttributeInfo[] attrs = mbi.getAttributes();
    int nattrs = attrs.length;
    if (mbi.getAttributes().length != 1)
        failure("wrong number of attributes: " + attrs);
    else {
        MBeanAttributeInfo mbai = attrs[0];
        if (mbai.getName().equals("Ints")
            && mbai.isReadable() && !mbai.isWritable()
            && mbai.getDescriptor().getFieldValue("openType")
                .equals(new ArrayType<int[]>(SimpleType.INTEGER, true))
            && attrs[0].getType().equals("[I"))
            success("MBeanAttributeInfo");
        else
            failure("MBeanAttributeInfo: " + mbai);
    }

    int[] ints = (int[]) mbs.getAttribute(on, "Ints");
    if (equal(ints, new int[] {1, 2, 3}, null))
        success("getAttribute");
    else
        failure("getAttribute: " + Arrays.toString(ints));

    ExplicitMXBean proxy =
        JMX.newMXBeanProxy(mbs, on, ExplicitMXBean.class);
    int[] pints = proxy.getInts();
    if (equal(pints, new int[] {1, 2, 3}, null))
        success("getAttribute through proxy");
    else
        failure("getAttribute through proxy: " + Arrays.toString(pints));
}
 
Example #18
Source File: MerlinMXBean.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
static ArrayType make(int dims, OpenType baseType) {
    try {
        return new ArrayType(dims, baseType);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #19
Source File: MerlinMXBean.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static ArrayType make(SimpleType baseType, boolean primitiveArray) {
    try {
        return new ArrayType(baseType, primitiveArray);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #20
Source File: DefaultMXBeanMappingFactory.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
        }
    }
}
 
Example #21
Source File: MerlinMXBean.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
static ArrayType make(int dims, OpenType baseType) {
    try {
        return new ArrayType(dims, baseType);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #22
Source File: ArrayTypeTest.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void printArrayType(ArrayType a) {
    System.out.println("\tArrayType.getClassName() = " + a.getClassName());
    System.out.println("\tArrayType.getDescription() = " + a.getDescription());
    System.out.println("\tArrayType.getTypeName() = " + a.getTypeName());
    System.out.println("\tArrayType.isArray() = " + a.isArray());
    System.out.println("\tArrayType.isPrimitiveArray() = " + a.isPrimitiveArray());
    System.out.println("\tArrayType.getDimension() = " + a.getDimension());
}
 
Example #23
Source File: MerlinMXBean.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
static ArrayType make(SimpleType baseType, boolean primitiveArray) {
    try {
        return new ArrayType(baseType, primitiveArray);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #24
Source File: MerlinMXBean.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
static ArrayType make(SimpleType baseType, boolean primitiveArray) {
    try {
        return new ArrayType(baseType, primitiveArray);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #25
Source File: MerlinMXBean.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
static ArrayType make(SimpleType baseType, boolean primitiveArray) {
    try {
        return new ArrayType(baseType, primitiveArray);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #26
Source File: ArrayTypeTest.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static int checkResult(int i, ArrayType a) {
    if (a.toString().equals(toStringResult[i])) {
        System.out.println("Test passed!");
        return 0;
    } else {
        System.out.println("Test failed!");
        return 1;
    }
}
 
Example #27
Source File: ArrayTypeTest.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static int checkResult(int i, ArrayType a) {
    if (a.toString().equals(toStringResult[i])) {
        System.out.println("Test passed!");
        return 0;
    } else {
        System.out.println("Test failed!");
        return 1;
    }
}
 
Example #28
Source File: MerlinMXBean.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static ArrayType make(int dims, OpenType baseType) {
    try {
        return new ArrayType(dims, baseType);
    } catch (OpenDataException e) {
        throw new Error(e);
    }
}
 
Example #29
Source File: ArrayTypeTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void printArrayType(ArrayType a) {
    System.out.println("\tArrayType.getClassName() = " + a.getClassName());
    System.out.println("\tArrayType.getDescription() = " + a.getDescription());
    System.out.println("\tArrayType.getTypeName() = " + a.getTypeName());
    System.out.println("\tArrayType.isArray() = " + a.isArray());
    System.out.println("\tArrayType.isPrimitiveArray() = " + a.isPrimitiveArray());
    System.out.println("\tArrayType.getDimension() = " + a.getDimension());
}
 
Example #30
Source File: StreamServiceTest.java    From cassandra-reaper with Apache License 2.0 5 votes vote down vote up
private CompositeType streamStateType_2_1_20() throws OpenDataException {
  String typeName = "org.apache.cassandra.streaming.StreamState";
  String description = "StreamState";
  String[] itemNames = {
      "currentRxBytes",
      "currentTxBytes",
      "description",
      "planId",
      "rxPercentage",
      "sessions",
      "totalRxBytes",
      "totalTxBytes",
      "txPercentage"
  };
  String[] itemDescriptions = {
      "currentRxBytes",
      "currentTxBytes",
      "description",
      "planId",
      "rxPercentage",
      "sessions",
      "totalRxBytes",
      "totalTxBytes",
      "txPercentage"
  };

  OpenType[] itemTypes = {
      SimpleType.LONG,
      SimpleType.LONG,
      SimpleType.STRING,
      SimpleType.STRING,
      SimpleType.DOUBLE,
      ArrayType.getArrayType(makeSessionsTypePost2_1()),
      SimpleType.LONG,
      SimpleType.LONG,
      SimpleType.DOUBLE
  };

  return new CompositeType(typeName, description, itemNames, itemDescriptions, itemTypes);
}