类javax.management.ImmutableDescriptor源码实例Demo

下面列出了怎么用javax.management.ImmutableDescriptor的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u-jdk   文件: OpenMBeanAttributeInfoSupport.java
static <T> Descriptor makeDescriptor(OpenType<T> openType,
                                     T defaultValue,
                                     T[] legalValues,
                                     Comparable<T> minValue,
                                     Comparable<T> maxValue) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (defaultValue != null)
        map.put("defaultValue", defaultValue);
    if (legalValues != null) {
        Set<T> set = new HashSet<T>();
        for (T v : legalValues)
            set.add(v);
        set = Collections.unmodifiableSet(set);
        map.put("legalValues", set);
    }
    if (minValue != null)
        map.put("minValue", minValue);
    if (maxValue != null)
        map.put("maxValue", maxValue);
    if (map.isEmpty()) {
        return openType.getDescriptor();
    } else {
        map.put("openType", openType);
        return new ImmutableDescriptor(map);
    }
}
 
源代码2 项目: openjdk-8   文件: OpenMBeanAttributeInfoSupport.java
static <T> Descriptor makeDescriptor(OpenType<T> openType,
                                     T defaultValue,
                                     T[] legalValues,
                                     Comparable<T> minValue,
                                     Comparable<T> maxValue) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (defaultValue != null)
        map.put("defaultValue", defaultValue);
    if (legalValues != null) {
        Set<T> set = new HashSet<T>();
        for (T v : legalValues)
            set.add(v);
        set = Collections.unmodifiableSet(set);
        map.put("legalValues", set);
    }
    if (minValue != null)
        map.put("minValue", minValue);
    if (maxValue != null)
        map.put("maxValue", maxValue);
    if (map.isEmpty()) {
        return openType.getDescriptor();
    } else {
        map.put("openType", openType);
        return new ImmutableDescriptor(map);
    }
}
 
static <T> Descriptor makeDescriptor(OpenType<T> openType,
                                     T defaultValue,
                                     T[] legalValues,
                                     Comparable<T> minValue,
                                     Comparable<T> maxValue) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (defaultValue != null)
        map.put("defaultValue", defaultValue);
    if (legalValues != null) {
        Set<T> set = new HashSet<T>();
        for (T v : legalValues)
            set.add(v);
        set = Collections.unmodifiableSet(set);
        map.put("legalValues", set);
    }
    if (minValue != null)
        map.put("minValue", minValue);
    if (maxValue != null)
        map.put("maxValue", maxValue);
    if (map.isEmpty()) {
        return openType.getDescriptor();
    } else {
        map.put("openType", openType);
        return new ImmutableDescriptor(map);
    }
}
 
static <T> Descriptor makeDescriptor(OpenType<T> openType,
                                     T defaultValue,
                                     T[] legalValues,
                                     Comparable<T> minValue,
                                     Comparable<T> maxValue) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (defaultValue != null)
        map.put("defaultValue", defaultValue);
    if (legalValues != null) {
        Set<T> set = new HashSet<T>();
        for (T v : legalValues)
            set.add(v);
        set = Collections.unmodifiableSet(set);
        map.put("legalValues", set);
    }
    if (minValue != null)
        map.put("minValue", minValue);
    if (maxValue != null)
        map.put("maxValue", maxValue);
    if (map.isEmpty()) {
        return openType.getDescriptor();
    } else {
        map.put("openType", openType);
        return new ImmutableDescriptor(map);
    }
}
 
static <T> Descriptor makeDescriptor(OpenType<T> openType,
                                     T defaultValue,
                                     T[] legalValues,
                                     Comparable<T> minValue,
                                     Comparable<T> maxValue) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (defaultValue != null)
        map.put("defaultValue", defaultValue);
    if (legalValues != null) {
        Set<T> set = new HashSet<T>();
        for (T v : legalValues)
            set.add(v);
        set = Collections.unmodifiableSet(set);
        map.put("legalValues", set);
    }
    if (minValue != null)
        map.put("minValue", minValue);
    if (maxValue != null)
        map.put("maxValue", maxValue);
    if (map.isEmpty()) {
        return openType.getDescriptor();
    } else {
        map.put("openType", openType);
        return new ImmutableDescriptor(map);
    }
}
 
源代码6 项目: dragonwell8_jdk   文件: AnnotationTest.java
private static void check(Object x, Descriptor d, Descriptor expect) {
    String fail = null;
    try {
        Descriptor u = ImmutableDescriptor.union(d, expect);
        if (!u.equals(d))
            fail = "should contain " + expect + "; is " + d;
    } catch (IllegalArgumentException e) {
        fail = e.getMessage();
    }
    if (fail == null) {
        System.out.println("OK: " + x);
    } else {
        failed = "NOT OK: Incorrect descriptor for: " + x;
        System.out.println(failed);
        System.out.println("..." + fail);
    }
}
 
源代码7 项目: jdk8u60   文件: AnnotationTest.java
private static void check(Object x, Descriptor d, Descriptor expect) {
    String fail = null;
    try {
        Descriptor u = ImmutableDescriptor.union(d, expect);
        if (!u.equals(d))
            fail = "should contain " + expect + "; is " + d;
    } catch (IllegalArgumentException e) {
        fail = e.getMessage();
    }
    if (fail == null) {
        System.out.println("OK: " + x);
    } else {
        failed = "NOT OK: Incorrect descriptor for: " + x;
        System.out.println(failed);
        System.out.println("..." + fail);
    }
}
 
源代码8 项目: jdk8u-jdk   文件: AnnotationTest.java
private static void check(Object x, Descriptor d, Descriptor expect) {
    String fail = null;
    try {
        Descriptor u = ImmutableDescriptor.union(d, expect);
        if (!u.equals(d))
            fail = "should contain " + expect + "; is " + d;
    } catch (IllegalArgumentException e) {
        fail = e.getMessage();
    }
    if (fail == null) {
        System.out.println("OK: " + x);
    } else {
        failed = "NOT OK: Incorrect descriptor for: " + x;
        System.out.println(failed);
        System.out.println("..." + fail);
    }
}
 
源代码9 项目: jdk8u_jdk   文件: OpenMBeanAttributeInfoSupport.java
static <T> Descriptor makeDescriptor(OpenType<T> openType,
                                     T defaultValue,
                                     T[] legalValues,
                                     Comparable<T> minValue,
                                     Comparable<T> maxValue) {
    Map<String, Object> map = new HashMap<String, Object>();
    if (defaultValue != null)
        map.put("defaultValue", defaultValue);
    if (legalValues != null) {
        Set<T> set = new HashSet<T>();
        for (T v : legalValues)
            set.add(v);
        set = Collections.unmodifiableSet(set);
        map.put("legalValues", set);
    }
    if (minValue != null)
        map.put("minValue", minValue);
    if (maxValue != null)
        map.put("maxValue", maxValue);
    if (map.isEmpty()) {
        return openType.getDescriptor();
    } else {
        map.put("openType", openType);
        return new ImmutableDescriptor(map);
    }
}
 
源代码10 项目: hottub   文件: MXBeanIntrospector.java
private static Descriptor typeDescriptor(OpenType<?> openType,
                                         Type originalType) {
    return new ImmutableDescriptor(
        new String[] {"openType",
                      "originalType"},
        new Object[] {openType,
                      originalTypeString(originalType)});
}
 
源代码11 项目: jdk8u-jdk   文件: StandardMBeanIntrospector.java
@Override
Descriptor getBasicMBeanDescriptor() {
    /* We don't bother saying mxbean=false, and we can't know whether
       the info is immutable until we know whether the MBean class
       (not interface) is a NotificationBroadcaster. */
    return ImmutableDescriptor.EMPTY_DESCRIPTOR;
}
 
源代码12 项目: jdk8u-jdk   文件: OpenMBeanParameterInfoSupport.java
/**
 * Constructs an {@code OpenMBeanParameterInfoSupport} instance,
 * which describes the parameter used in one or more operations or
 * constructors of a class of open MBeans, with the specified
 * {@code name}, {@code openType}, {@code description},
 * and {@code descriptor}.
 *
 * <p>The {@code descriptor} can contain entries that will define
 * the values returned by certain methods of this class, as
 * explained in the <a href="package-summary.html#constraints">
 * package description</a>.
 *
 * @param name  cannot be a null or empty string.
 *
 * @param description  cannot be a null or empty string.
 *
 * @param openType  cannot be null.
 *
 * @param descriptor The descriptor for the parameter.  This may be null
 * which is equivalent to an empty descriptor.
 *
 * @throws IllegalArgumentException if {@code name} or {@code
 * description} are null or empty string, or {@code openType} is
 * null, or the descriptor entries are invalid as described in the
 * <a href="package-summary.html#constraints">package
 * description</a>.
 *
 * @since 1.6
 */
public OpenMBeanParameterInfoSupport(String name,
                                     String description,
                                     OpenType<?> openType,
                                     Descriptor descriptor) {


    // Construct parent's state
    //
    super(name,
          (openType==null) ? null : openType.getClassName(),
          description,
          ImmutableDescriptor.union(descriptor,(openType==null)?null:
            openType.getDescriptor()));

    // Initialize this instance's specific state
    //
    this.openType = openType;

    descriptor = getDescriptor();  // replace null by empty
    this.defaultValue = valueFrom(descriptor, "defaultValue", openType);
    this.legalValues = valuesFrom(descriptor, "legalValues", openType);
    this.minValue = comparableValueFrom(descriptor, "minValue", openType);
    this.maxValue = comparableValueFrom(descriptor, "maxValue", openType);

    try {
        check(this);
    } catch (OpenDataException e) {
        throw new IllegalArgumentException(e.getMessage(), e);
    }
}
 
源代码13 项目: openjdk-jdk8u-backup   文件: UnionTest.java
private static void checkEmpty(ImmutableDescriptor d) {
    if (d != EMPTY_DESCRIPTOR) {
        failure = "Union of empty descriptors should be " +
            "ImmutableDescriptor.EMPTY";
        System.err.println("FAILED: " + failure);
        Thread.dumpStack();
    }
}
 
源代码14 项目: openjdk-jdk9   文件: UnionTest.java
private static void checkEmpty(ImmutableDescriptor d) {
    if (d != EMPTY_DESCRIPTOR) {
        failure = "Union of empty descriptors should be " +
            "ImmutableDescriptor.EMPTY";
        System.err.println("FAILED: " + failure);
        Thread.dumpStack();
    }
}
 
public static void main(String[] args) throws Exception {
    System.out.println("Test that ImmutableDescriptor.EMPTY_DESCRIPTOR " +
            "deserializes identically");
    if (serialize(ImmutableDescriptor.EMPTY_DESCRIPTOR) !=
            ImmutableDescriptor.EMPTY_DESCRIPTOR) {
        throw new Exception("ImmutableDescriptor.EMPTY_DESCRIPTOR did not " +
                "deserialize identically");
    }
    System.out.println("...OK");

    System.out.println("Test that serialization preserves case and " +
            "that deserialized object is case-insensitive");
    Descriptor d = new ImmutableDescriptor("a=aval", "B=Bval", "cC=cCval");
    Descriptor d1 = serialize(d);
    Set<String> keys = new HashSet(Arrays.asList(d1.getFieldNames()));
    if (keys.size() != 3 ||
            !keys.containsAll(Arrays.asList("a", "B", "cC"))) {
        throw new Exception("Keys don't match: " + keys);
    }
    for (String key : keys) {
        String value = (String) d.getFieldValue(key);
        for (String t :
                Arrays.asList(key, key.toLowerCase(), key.toUpperCase())) {
            String tvalue = (String) d1.getFieldValue(t);
            if (!tvalue.equals(value)) {
                throw new Exception("Value of " + key + " for " +
                        "deserialized object does not match: " +
                        tvalue + " should be " + value);
            }
        }
    }
    System.out.println("...OK");
}
 
源代码16 项目: hottub   文件: MXBeanIntrospector.java
@Override
Descriptor getMBeanDescriptor(Class<?> resourceClass) {
    /* We already have immutableInfo=true in the Descriptor
     * included in the MBeanInfo for the MXBean interface.  This
     * method is being called for the MXBean *class* to add any
     * new items beyond those in the interface Descriptor, which
     * currently it does not.
     */
    return ImmutableDescriptor.EMPTY_DESCRIPTOR;
}
 
源代码17 项目: dragonwell8_jdk   文件: MXBeanIntrospector.java
private static Descriptor typeDescriptor(OpenType<?> openType,
                                         Type originalType) {
    return new ImmutableDescriptor(
        new String[] {"openType",
                      "originalType"},
        new Object[] {openType,
                      originalTypeString(originalType)});
}
 
源代码18 项目: dragonwell8_jdk   文件: MBeanIntrospector.java
/** Make an MBeanInfo based on the attributes and operations
 *  found in the interface. */
MBeanInfo makeMBeanInfo(Class<?> mbeanInterface,
        String description) {
    final MBeanAttributeInfo[] attrArray =
            attrs.toArray(new MBeanAttributeInfo[0]);
    final MBeanOperationInfo[] opArray =
            ops.toArray(new MBeanOperationInfo[0]);
    final String interfaceClassName =
            "interfaceClassName=" + mbeanInterface.getName();
    final Descriptor classNameDescriptor =
            new ImmutableDescriptor(interfaceClassName);
    final Descriptor mbeanDescriptor = getBasicMBeanDescriptor();
    final Descriptor annotatedDescriptor =
            Introspector.descriptorForElement(mbeanInterface);
    final Descriptor descriptor =
        DescriptorCache.getInstance().union(
            classNameDescriptor,
            mbeanDescriptor,
            annotatedDescriptor);

    return new MBeanInfo(mbeanInterface.getName(),
            description,
            attrArray,
            null,
            opArray,
            null,
            descriptor);
}
 
源代码19 项目: dragonwell8_jdk   文件: DescriptorCache.java
public ImmutableDescriptor get(ImmutableDescriptor descriptor) {
    WeakReference<ImmutableDescriptor> wr = map.get(descriptor);
    ImmutableDescriptor got = (wr == null) ? null : wr.get();
    if (got != null)
        return got;
    map.put(descriptor, new WeakReference<ImmutableDescriptor>(descriptor));
    return descriptor;
}
 
源代码20 项目: openjdk-8   文件: MBeanIntrospector.java
/** Make an MBeanInfo based on the attributes and operations
 *  found in the interface. */
MBeanInfo makeMBeanInfo(Class<?> mbeanInterface,
        String description) {
    final MBeanAttributeInfo[] attrArray =
            attrs.toArray(new MBeanAttributeInfo[0]);
    final MBeanOperationInfo[] opArray =
            ops.toArray(new MBeanOperationInfo[0]);
    final String interfaceClassName =
            "interfaceClassName=" + mbeanInterface.getName();
    final Descriptor classNameDescriptor =
            new ImmutableDescriptor(interfaceClassName);
    final Descriptor mbeanDescriptor = getBasicMBeanDescriptor();
    final Descriptor annotatedDescriptor =
            Introspector.descriptorForElement(mbeanInterface);
    final Descriptor descriptor =
        DescriptorCache.getInstance().union(
            classNameDescriptor,
            mbeanDescriptor,
            annotatedDescriptor);

    return new MBeanInfo(mbeanInterface.getName(),
            description,
            attrArray,
            null,
            opArray,
            null,
            descriptor);
}
 
源代码21 项目: openjdk-8   文件: StandardMBeanIntrospector.java
@Override
Descriptor getBasicMBeanDescriptor() {
    /* We don't bother saying mxbean=false, and we can't know whether
       the info is immutable until we know whether the MBean class
       (not interface) is a NotificationBroadcaster. */
    return ImmutableDescriptor.EMPTY_DESCRIPTOR;
}
 
源代码22 项目: dragonwell8_jdk   文件: Basic.java
private void initNotifDescriptorAtt() {
    String key = "CRABE";
    String value = "TAMBOUR";
    notifDescriptorAtt =
            new ImmutableDescriptor(new String[]{key + "=" + value});
    notifDescriptorAsMapAtt =
            new HashMap<String, String>();
    notifDescriptorAsMapAtt.put(key, value);
}
 
public static void main(String[] args) throws Exception {
    System.out.println("Test that ImmutableDescriptor.EMPTY_DESCRIPTOR " +
            "deserializes identically");
    if (serialize(ImmutableDescriptor.EMPTY_DESCRIPTOR) !=
            ImmutableDescriptor.EMPTY_DESCRIPTOR) {
        throw new Exception("ImmutableDescriptor.EMPTY_DESCRIPTOR did not " +
                "deserialize identically");
    }
    System.out.println("...OK");

    System.out.println("Test that serialization preserves case and " +
            "that deserialized object is case-insensitive");
    Descriptor d = new ImmutableDescriptor("a=aval", "B=Bval", "cC=cCval");
    Descriptor d1 = serialize(d);
    Set<String> keys = new HashSet(Arrays.asList(d1.getFieldNames()));
    if (keys.size() != 3 ||
            !keys.containsAll(Arrays.asList("a", "B", "cC"))) {
        throw new Exception("Keys don't match: " + keys);
    }
    for (String key : keys) {
        String value = (String) d.getFieldValue(key);
        for (String t :
                Arrays.asList(key, key.toLowerCase(), key.toUpperCase())) {
            String tvalue = (String) d1.getFieldValue(t);
            if (!tvalue.equals(value)) {
                throw new Exception("Value of " + key + " for " +
                        "deserialized object does not match: " +
                        tvalue + " should be " + value);
            }
        }
    }
    System.out.println("...OK");
}
 
源代码24 项目: dragonwell8_jdk   文件: UnionTest.java
private static void checkEmpty(ImmutableDescriptor d) {
    if (d != EMPTY_DESCRIPTOR) {
        failure = "Union of empty descriptors should be " +
            "ImmutableDescriptor.EMPTY";
        System.err.println("FAILED: " + failure);
        Thread.dumpStack();
    }
}
 
源代码25 项目: dragonwell8_jdk   文件: UnionTest.java
private static void checkEquivalent(ImmutableDescriptor d,
                                    ImmutableDescriptor e) {
    if (!d.equals(e)) {
        failure = "Union produced this: " + d + "; but should have " +
            "produced this: " + e;
        System.err.println("FAILED: " + failure);
        Thread.dumpStack();
    }
}
 
源代码26 项目: openjdk-8   文件: UnionTest.java
private static void checkEmpty(ImmutableDescriptor d) {
    if (d != EMPTY_DESCRIPTOR) {
        failure = "Union of empty descriptors should be " +
            "ImmutableDescriptor.EMPTY";
        System.err.println("FAILED: " + failure);
        Thread.dumpStack();
    }
}
 
源代码27 项目: jdk8u_jdk   文件: MBeanIntrospector.java
/** Make an MBeanInfo based on the attributes and operations
 *  found in the interface. */
MBeanInfo makeMBeanInfo(Class<?> mbeanInterface,
        String description) {
    final MBeanAttributeInfo[] attrArray =
            attrs.toArray(new MBeanAttributeInfo[0]);
    final MBeanOperationInfo[] opArray =
            ops.toArray(new MBeanOperationInfo[0]);
    final String interfaceClassName =
            "interfaceClassName=" + mbeanInterface.getName();
    final Descriptor classNameDescriptor =
            new ImmutableDescriptor(interfaceClassName);
    final Descriptor mbeanDescriptor = getBasicMBeanDescriptor();
    final Descriptor annotatedDescriptor =
            Introspector.descriptorForElement(mbeanInterface);
    final Descriptor descriptor =
        DescriptorCache.getInstance().union(
            classNameDescriptor,
            mbeanDescriptor,
            annotatedDescriptor);

    return new MBeanInfo(mbeanInterface.getName(),
            description,
            attrArray,
            null,
            opArray,
            null,
            descriptor);
}
 
源代码28 项目: jdk8u-dev-jdk   文件: UnionTest.java
private static void checkEquivalent(ImmutableDescriptor d,
                                    ImmutableDescriptor e) {
    if (!d.equals(e)) {
        failure = "Union produced this: " + d + "; but should have " +
            "produced this: " + e;
        System.err.println("FAILED: " + failure);
        Thread.dumpStack();
    }
}
 
源代码29 项目: TencentKona-8   文件: MBeanIntrospector.java
/** Make an MBeanInfo based on the attributes and operations
 *  found in the interface. */
MBeanInfo makeMBeanInfo(Class<?> mbeanInterface,
        String description) {
    final MBeanAttributeInfo[] attrArray =
            attrs.toArray(new MBeanAttributeInfo[0]);
    final MBeanOperationInfo[] opArray =
            ops.toArray(new MBeanOperationInfo[0]);
    final String interfaceClassName =
            "interfaceClassName=" + mbeanInterface.getName();
    final Descriptor classNameDescriptor =
            new ImmutableDescriptor(interfaceClassName);
    final Descriptor mbeanDescriptor = getBasicMBeanDescriptor();
    final Descriptor annotatedDescriptor =
            Introspector.descriptorForElement(mbeanInterface);
    final Descriptor descriptor =
        DescriptorCache.getInstance().union(
            classNameDescriptor,
            mbeanDescriptor,
            annotatedDescriptor);

    return new MBeanInfo(mbeanInterface.getName(),
            description,
            attrArray,
            null,
            opArray,
            null,
            descriptor);
}
 
源代码30 项目: hottub   文件: DescriptorCache.java
public ImmutableDescriptor get(ImmutableDescriptor descriptor) {
    WeakReference<ImmutableDescriptor> wr = map.get(descriptor);
    ImmutableDescriptor got = (wr == null) ? null : wr.get();
    if (got != null)
        return got;
    map.put(descriptor, new WeakReference<ImmutableDescriptor>(descriptor));
    return descriptor;
}
 
 类所在包
 同包方法