javax.management.Descriptor Java Examples

The following examples show how to use javax.management.Descriptor. 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: ModelMBeanNotificationInfo.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Returns a copy of the associated Descriptor for the
 * ModelMBeanNotificationInfo.
 *
 * @return Descriptor associated with the
 * ModelMBeanNotificationInfo object.
 *
 * @see #setDescriptor
 **/
public Descriptor getDescriptor() {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanNotificationInfo.class.getName(),
                "getDescriptor()", "Entry");
    }

    if (notificationDescriptor == null) {
        // Dead code. Should never happen.
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
            MODELMBEAN_LOGGER.logp(Level.FINER,
                    ModelMBeanNotificationInfo.class.getName(),
                    "getDescriptor()", "Descriptor value is null, " +
                    "setting descriptor to default values");
        }
        notificationDescriptor = validDescriptor(null);
    }

    return((Descriptor)notificationDescriptor.clone());
}
 
Example #2
Source File: RequiredModelMBean.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a default ModelMBeanNotificationInfo for GENERIC
 * notification.  (bug 4744667)
 **/
private static final ModelMBeanNotificationInfo makeGenericInfo() {
    final Descriptor genericDescriptor = new DescriptorSupport( new
        String[] {
            "name=GENERIC",
            "descriptorType=notification",
            "log=T",
            "severity=6",
            "displayName=jmx.modelmbean.generic"} );

    return new ModelMBeanNotificationInfo(new
        String[] {"jmx.modelmbean.generic"},
        "GENERIC",
        "A text notification has been issued by the managed resource",
        genericDescriptor);
}
 
Example #3
Source File: ImmutableNotificationInfoTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private static boolean test(Object mbean, boolean expectImmutable)
        throws Exception {
    MBeanServer mbs = MBeanServerFactory.newMBeanServer();
    ObjectName on = new ObjectName("a:b=c");
    mbs.registerMBean(mbean, on);
    MBeanInfo mbi = mbs.getMBeanInfo(on);
    Descriptor d = mbi.getDescriptor();
    String immutableValue = (String) d.getFieldValue("immutableInfo");
    boolean immutable = ("true".equals(immutableValue));
    if (immutable != expectImmutable) {
        System.out.println("FAILED: " + mbean.getClass().getName() +
                " -> " + immutableValue);
        return false;
    } else {
        System.out.println("OK: " + mbean.getClass().getName());
        return true;
    }
}
 
Example #4
Source File: ModelMBeanNotificationInfo.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns a copy of the associated Descriptor for the
 * ModelMBeanNotificationInfo.
 *
 * @return Descriptor associated with the
 * ModelMBeanNotificationInfo object.
 *
 * @see #setDescriptor
 **/
public Descriptor getDescriptor() {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanNotificationInfo.class.getName(),
                "getDescriptor()", "Entry");
    }

    if (notificationDescriptor == null) {
        // Dead code. Should never happen.
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
            MODELMBEAN_LOGGER.logp(Level.FINER,
                    ModelMBeanNotificationInfo.class.getName(),
                    "getDescriptor()", "Descriptor value is null, " +
                    "setting descriptor to default values");
        }
        notificationDescriptor = validDescriptor(null);
    }

    return((Descriptor)notificationDescriptor.clone());
}
 
Example #5
Source File: AnnotationTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example #6
Source File: AnnotationTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
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);
    }
}
 
Example #7
Source File: RequiredModelMBean.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a default ModelMBeanNotificationInfo for ATTRIBUTE_CHANGE
 * notification.  (bug 4744667)
 **/
private static final
    ModelMBeanNotificationInfo makeAttributeChangeInfo() {
    final Descriptor attributeDescriptor = new DescriptorSupport(new
        String[] {
            "name=ATTRIBUTE_CHANGE",
            "descriptorType=notification",
            "log=T",
            "severity=6",
            "displayName=jmx.attribute.change"});

    return new ModelMBeanNotificationInfo(new
        String[] {"jmx.attribute.change"},
        "ATTRIBUTE_CHANGE",
        "Signifies that an observed MBean attribute value has changed",
        attributeDescriptor );
}
 
Example #8
Source File: ModelMBeanInfoSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
public void setDescriptors(Descriptor[] inDescriptors)
throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
    }
    if (inDescriptors==null) {
        // throw RuntimeOperationsException - invalid descriptor
        throw new RuntimeOperationsException(
                new IllegalArgumentException("Descriptor list is invalid"),
                "Exception occurred trying to set the descriptors " +
                "of the MBeanInfo");
    }
    if (inDescriptors.length == 0) { // empty list, no-op
        return;
    }
    for (int j=0; j < inDescriptors.length; j++) {
        setDescriptor(inDescriptors[j],null);
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
    }

}
 
Example #9
Source File: RequiredModelMBean.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Creates a default ModelMBeanNotificationInfo for GENERIC
 * notification.  (bug 4744667)
 **/
private static final ModelMBeanNotificationInfo makeGenericInfo() {
    final Descriptor genericDescriptor = new DescriptorSupport( new
        String[] {
            "name=GENERIC",
            "descriptorType=notification",
            "log=T",
            "severity=6",
            "displayName=jmx.modelmbean.generic"} );

    return new ModelMBeanNotificationInfo(new
        String[] {"jmx.modelmbean.generic"},
        "GENERIC",
        "A text notification has been issued by the managed resource",
        genericDescriptor);
}
 
Example #10
Source File: OpenMBeanParameterInfoSupport.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
private <T> OpenMBeanParameterInfoSupport(String name,
                                          String description,
                                          OpenType<T> openType,
                                          T defaultValue,
                                          T[] legalValues,
                                          Comparable<T> minValue,
                                          Comparable<T> maxValue)
        throws OpenDataException {
    super(name,
          (openType == null) ? null : openType.getClassName(),
          description,
          makeDescriptor(openType,
                         defaultValue, legalValues, minValue, maxValue));

    this.openType = openType;

    Descriptor d = getDescriptor();
    this.defaultValue = defaultValue;
    this.minValue = minValue;
    this.maxValue = maxValue;
    // We already converted the array into an unmodifiable Set
    // in the descriptor.
    this.legalValues = (Set<?>) d.getFieldValue("legalValues");

    check(this);
}
 
Example #11
Source File: ModelMBeanAttributeInfo.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
/**
 * Constructs a new ModelMBeanAttributeInfo object from this
 * ModelMBeanAttributeInfo Object.  A default descriptor will
 * be created.
 *
 * @param inInfo the ModelMBeanAttributeInfo to be duplicated
 */

public ModelMBeanAttributeInfo(ModelMBeanAttributeInfo inInfo)
{
        super(inInfo.getName(),
                  inInfo.getType(),
                  inInfo.getDescription(),
                  inInfo.isReadable(),
                  inInfo.isWritable(),
                  inInfo.isIs());
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
            MODELMBEAN_LOGGER.logp(Level.FINER,
                    ModelMBeanAttributeInfo.class.getName(),
                    "ModelMBeanAttributeInfo(ModelMBeanAttributeInfo)",
                    "Entry");
        }
        Descriptor newDesc = inInfo.getDescriptor();
        attrDescriptor = validDescriptor(newDesc);
}
 
Example #12
Source File: RequiredModelMBean.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a default ModelMBeanNotificationInfo for ATTRIBUTE_CHANGE
 * notification.  (bug 4744667)
 **/
private static final
    ModelMBeanNotificationInfo makeAttributeChangeInfo() {
    final Descriptor attributeDescriptor = new DescriptorSupport(new
        String[] {
            "name=ATTRIBUTE_CHANGE",
            "descriptorType=notification",
            "log=T",
            "severity=6",
            "displayName=jmx.attribute.change"});

    return new ModelMBeanNotificationInfo(new
        String[] {"jmx.attribute.change"},
        "ATTRIBUTE_CHANGE",
        "Signifies that an observed MBean attribute value has changed",
        attributeDescriptor );
}
 
Example #13
Source File: OpenMBeanAttributeInfoSupport.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private <T> OpenMBeanAttributeInfoSupport(String name,
                                          String description,
                                          OpenType<T> openType,
                                          boolean isReadable,
                                          boolean isWritable,
                                          boolean isIs,
                                          T defaultValue,
                                          T[] legalValues,
                                          Comparable<T> minValue,
                                          Comparable<T> maxValue)
        throws OpenDataException {
    super(name,
          (openType==null) ? null : openType.getClassName(),
          description,
          isReadable,
          isWritable,
          isIs,
          makeDescriptor(openType,
                         defaultValue, legalValues, minValue, maxValue));

    this.openType = openType;

    Descriptor d = getDescriptor();
    this.defaultValue = defaultValue;
    this.minValue = minValue;
    this.maxValue = maxValue;
    // We already converted the array into an unmodifiable Set
    // in the descriptor.
    this.legalValues = (Set<?>) d.getFieldValue("legalValues");

    check(this);
}
 
Example #14
Source File: ModelMBeanInfoSupport.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
public void setMBeanDescriptor(Descriptor inMBeanDescriptor)
throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "setMBeanDescriptor(Descriptor)", "Entry");
    }
    modelMBeanDescriptor = validDescriptor(inMBeanDescriptor);
}
 
Example #15
Source File: ModelMBeanInfoSupport.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void setDescriptors(Descriptor[] inDescriptors)
throws MBeanException, RuntimeOperationsException {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "setDescriptors(Descriptor[])", "Entry");
    }
    if (inDescriptors==null) {
        // throw RuntimeOperationsException - invalid descriptor
        throw new RuntimeOperationsException(
                new IllegalArgumentException("Descriptor list is invalid"),
                "Exception occurred trying to set the descriptors " +
                "of the MBeanInfo");
    }
    if (inDescriptors.length == 0) { // empty list, no-op
        return;
    }
    for (int j=0; j < inDescriptors.length; j++) {
        setDescriptor(inDescriptors[j],null);
    }
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "setDescriptors(Descriptor[])", "Exit");
    }

}
 
Example #16
Source File: OpenMBeanAttributeInfoSupport.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
static <T> Descriptor makeDescriptor(OpenType<T> openType,
                                     T defaultValue,
                                     Set<T> legalValues,
                                     Comparable<T> minValue,
                                     Comparable<T> maxValue) {
    T[] legals;
    if (legalValues == null)
        legals = null;
    else {
        legals = cast(new Object[legalValues.size()]);
        legalValues.toArray(legals);
    }
    return makeDescriptor(openType, defaultValue, legals, minValue, maxValue);
}
 
Example #17
Source File: ModelAgent.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void printModelMBeanDescriptors(ObjectName mbeanObjectName)
{
	sleep(1000);

	Descriptor[] dArray = new DescriptorSupport[0];
	try
	{
		dArray = (Descriptor[]) (server.invoke(mbeanObjectName, "getDescriptors",
											   new Object[] {},
											   new String[] {}));
		if (dArray == null)
		{
			echo("\nDescriptor list is null!");
		}
	} catch (Exception e)
	{
		echo("\t!!! Could not get descriptors for mbeanName ");
		e.printStackTrace();
		return;
	}

	echo("Descriptors: (");
	echo(dArray.length + ")\n");
	for (int i=0; i < dArray.length; i++)
	{
		echo("\n**Descriptor***********************");
		String[] dlfields =  ((Descriptor) dArray[i]).getFields();
		for (int j=0; j < dlfields.length; j++)
		{
			echo(dlfields[j] + "\n");
		}
	}
}
 
Example #18
Source File: OpenMBeanAttributeInfoSupport.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private <T> OpenMBeanAttributeInfoSupport(String name,
                                          String description,
                                          OpenType<T> openType,
                                          boolean isReadable,
                                          boolean isWritable,
                                          boolean isIs,
                                          T defaultValue,
                                          T[] legalValues,
                                          Comparable<T> minValue,
                                          Comparable<T> maxValue)
        throws OpenDataException {
    super(name,
          (openType==null) ? null : openType.getClassName(),
          description,
          isReadable,
          isWritable,
          isIs,
          makeDescriptor(openType,
                         defaultValue, legalValues, minValue, maxValue));

    this.openType = openType;

    Descriptor d = getDescriptor();
    this.defaultValue = defaultValue;
    this.minValue = minValue;
    this.maxValue = maxValue;
    // We already converted the array into an unmodifiable Set
    // in the descriptor.
    this.legalValues = (Set<?>) d.getFieldValue("legalValues");

    check(this);
}
 
Example #19
Source File: StandardMBeanIntrospector.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #20
Source File: OpenMBeanAttributeInfoSupport.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
static boolean equal(OpenMBeanParameterInfo x1, OpenMBeanParameterInfo x2) {
    if (x1 instanceof DescriptorRead) {
        if (!(x2 instanceof DescriptorRead))
            return false;
        Descriptor d1 = ((DescriptorRead) x1).getDescriptor();
        Descriptor d2 = ((DescriptorRead) x2).getDescriptor();
        if (!d1.equals(d2))
            return false;
    } else if (x2 instanceof DescriptorRead)
        return false;

    return
        x1.getName().equals(x2.getName()) &&
        x1.getOpenType().equals(x2.getOpenType()) &&
        (x1.hasDefaultValue() ?
            x1.getDefaultValue().equals(x2.getDefaultValue()) :
            !x2.hasDefaultValue()) &&
        (x1.hasMinValue() ?
            x1.getMinValue().equals(x2.getMinValue()) :
            !x2.hasMinValue()) &&
        (x1.hasMaxValue() ?
            x1.getMaxValue().equals(x2.getMaxValue()) :
            !x2.hasMaxValue()) &&
        (x1.hasLegalValues() ?
            x1.getLegalValues().equals(x2.getLegalValues()) :
            !x2.hasLegalValues());
}
 
Example #21
Source File: OpenMBeanAttributeInfoSupport.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static <T> Comparable<?> comparableValueFrom(Descriptor d, String name,
                                             OpenType<T> openType) {
    T t = valueFrom(d, name, openType);
    if (t == null || t instanceof Comparable<?>)
        return (Comparable<?>) t;
    final String msg =
        "Descriptor field " + name + " with value " + t +
        " is not Comparable";
    throw new IllegalArgumentException(msg);
}
 
Example #22
Source File: ModelMBeanInfoSupport.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    if (compat) {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
        modelMBeanDescriptor =
                (Descriptor) fields.get("modelMBeanDescriptor", null);
        if (fields.defaulted("modelMBeanDescriptor")) {
            throw new NullPointerException("modelMBeanDescriptor");
        }
        modelMBeanAttributes =
                (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
        if (fields.defaulted("mmbAttributes")) {
            throw new NullPointerException("mmbAttributes");
        }
        modelMBeanConstructors =
                (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
        if (fields.defaulted("mmbConstructors")) {
            throw new NullPointerException("mmbConstructors");
        }
        modelMBeanNotifications =
                (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
        if (fields.defaulted("mmbNotifications")) {
            throw new NullPointerException("mmbNotifications");
        }
        modelMBeanOperations =
                (MBeanOperationInfo[]) fields.get("mmbOperations", null);
        if (fields.defaulted("mmbOperations")) {
            throw new NullPointerException("mmbOperations");
        }
    } else {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
    }
}
 
Example #23
Source File: OpenMBeanAttributeInfoSupport.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
static boolean equal(OpenMBeanParameterInfo x1, OpenMBeanParameterInfo x2) {
    if (x1 instanceof DescriptorRead) {
        if (!(x2 instanceof DescriptorRead))
            return false;
        Descriptor d1 = ((DescriptorRead) x1).getDescriptor();
        Descriptor d2 = ((DescriptorRead) x2).getDescriptor();
        if (!d1.equals(d2))
            return false;
    } else if (x2 instanceof DescriptorRead)
        return false;

    return
        x1.getName().equals(x2.getName()) &&
        x1.getOpenType().equals(x2.getOpenType()) &&
        (x1.hasDefaultValue() ?
            x1.getDefaultValue().equals(x2.getDefaultValue()) :
            !x2.hasDefaultValue()) &&
        (x1.hasMinValue() ?
            x1.getMinValue().equals(x2.getMinValue()) :
            !x2.hasMinValue()) &&
        (x1.hasMaxValue() ?
            x1.getMaxValue().equals(x2.getMaxValue()) :
            !x2.hasMaxValue()) &&
        (x1.hasLegalValues() ?
            x1.getLegalValues().equals(x2.getLegalValues()) :
            !x2.hasLegalValues());
}
 
Example #24
Source File: ModelMBeanInfoSupport.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    if (compat) {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
        modelMBeanDescriptor =
                (Descriptor) fields.get("modelMBeanDescriptor", null);
        if (fields.defaulted("modelMBeanDescriptor")) {
            throw new NullPointerException("modelMBeanDescriptor");
        }
        modelMBeanAttributes =
                (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
        if (fields.defaulted("mmbAttributes")) {
            throw new NullPointerException("mmbAttributes");
        }
        modelMBeanConstructors =
                (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
        if (fields.defaulted("mmbConstructors")) {
            throw new NullPointerException("mmbConstructors");
        }
        modelMBeanNotifications =
                (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
        if (fields.defaulted("mmbNotifications")) {
            throw new NullPointerException("mmbNotifications");
        }
        modelMBeanOperations =
                (MBeanOperationInfo[]) fields.get("mmbOperations", null);
        if (fields.defaulted("mmbOperations")) {
            throw new NullPointerException("mmbOperations");
        }
    } else {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
    }
}
 
Example #25
Source File: ModelMBeanInfoSupport.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Deserializes a {@link ModelMBeanInfoSupport} from an {@link ObjectInputStream}.
 */
private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
    if (compat) {
        // Read an object serialized in the old serial form
        //
        ObjectInputStream.GetField fields = in.readFields();
        modelMBeanDescriptor =
                (Descriptor) fields.get("modelMBeanDescriptor", null);
        if (fields.defaulted("modelMBeanDescriptor")) {
            throw new NullPointerException("modelMBeanDescriptor");
        }
        modelMBeanAttributes =
                (MBeanAttributeInfo[]) fields.get("mmbAttributes", null);
        if (fields.defaulted("mmbAttributes")) {
            throw new NullPointerException("mmbAttributes");
        }
        modelMBeanConstructors =
                (MBeanConstructorInfo[]) fields.get("mmbConstructors", null);
        if (fields.defaulted("mmbConstructors")) {
            throw new NullPointerException("mmbConstructors");
        }
        modelMBeanNotifications =
                (MBeanNotificationInfo[]) fields.get("mmbNotifications", null);
        if (fields.defaulted("mmbNotifications")) {
            throw new NullPointerException("mmbNotifications");
        }
        modelMBeanOperations =
                (MBeanOperationInfo[]) fields.get("mmbOperations", null);
        if (fields.defaulted("mmbOperations")) {
            throw new NullPointerException("mmbOperations");
        }
    } else {
        // Read an object serialized in the new serial form
        //
        in.defaultReadObject();
    }
}
 
Example #26
Source File: OpenMBeanParameterInfoSupport.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 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);
    }
}
 
Example #27
Source File: ModelMBeanInfoSupport.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Creates a ModelMBeanInfoSupport with the provided information
 * and the descriptor given in parameter.
 *
 * @param className classname of the MBean
 * @param description human readable description of the
 * ModelMBean
 * @param attributes array of ModelMBeanAttributeInfo objects
 * which have descriptors
 * @param constructors array of ModelMBeanConstructorInfo
 * objects which have descriptor
 * @param operations array of ModelMBeanOperationInfo objects
 * which have descriptor
 * @param notifications array of ModelMBeanNotificationInfo
 * objects which have descriptor
 * @param mbeandescriptor descriptor to be used as the
 * MBeanDescriptor containing MBean wide policy. If the
 * descriptor is null, a default descriptor will be constructed.
 * The default descriptor is:
 * name=className, descriptorType="mbean", displayName=className,
 * persistPolicy="never", log="F", visibility="1".  If the descriptor
 * does not contain all of these fields, the missing ones are
 * added with these default values.
 *
 * @exception RuntimeOperationsException Wraps an
 * IllegalArgumentException for invalid descriptor passed in
 * parameter.  (see {@link #getMBeanDescriptor
 * getMBeanDescriptor} for the definition of a valid MBean
 * descriptor.)
 */

public ModelMBeanInfoSupport(String    className,
        String description,
        ModelMBeanAttributeInfo[] attributes,
        ModelMBeanConstructorInfo[] constructors,
        ModelMBeanOperationInfo[] operations,
        ModelMBeanNotificationInfo[] notifications,
        Descriptor mbeandescriptor) {
    super(className,
            description,
            (attributes != null) ? attributes : NO_ATTRIBUTES,
            (constructors != null) ? constructors : NO_CONSTRUCTORS,
            (operations != null) ? operations : NO_OPERATIONS,
            (notifications != null) ? notifications : NO_NOTIFICATIONS);
    /* The values saved here are possibly null, but we
       check this everywhere they are referenced.  If at
       some stage we replace null with an empty array
       here, as we do in the superclass constructor
       parameters, then we must also do this in
       readObject().  */
    modelMBeanAttributes = attributes;
    modelMBeanConstructors = constructors;
    modelMBeanOperations = operations;
    modelMBeanNotifications = notifications;
    modelMBeanDescriptor = validDescriptor(mbeandescriptor);
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "ModelMBeanInfoSupport(String,String,ModelMBeanAttributeInfo[]," +
                "ModelMBeanConstructorInfo[],ModelMBeanOperationInfo[]," +
                "ModelMBeanNotificationInfo[],Descriptor)",
                "Exit");
    }
}
 
Example #28
Source File: StandardMBeanIntrospector.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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;
}
 
Example #29
Source File: AbstractReflectiveMBeanInfoAssembler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Apply the given JMX "currencyTimeLimit" value to the given descriptor.
 * <p>The default implementation sets a value {@code >0} as-is (as number of cache seconds),
 * turns a value of {@code 0} into {@code Integer.MAX_VALUE} ("always cache")
 * and sets the "defaultCurrencyTimeLimit" (if any, indicating "never cache") in case of
 * a value {@code <0}. This follows the recommendation in the JMX 1.2 specification.
 * @param desc the JMX attribute or operation descriptor
 * @param currencyTimeLimit the "currencyTimeLimit" value to apply
 * @see #setDefaultCurrencyTimeLimit(Integer)
 * @see #applyDefaultCurrencyTimeLimit(javax.management.Descriptor)
 */
protected void applyCurrencyTimeLimit(Descriptor desc, int currencyTimeLimit) {
	if (currencyTimeLimit > 0) {
		// number of cache seconds
		desc.setField(FIELD_CURRENCY_TIME_LIMIT, Integer.toString(currencyTimeLimit));
	}
	else if (currencyTimeLimit == 0) {
		// "always cache"
		desc.setField(FIELD_CURRENCY_TIME_LIMIT, Integer.toString(Integer.MAX_VALUE));
	}
	else {
		// "never cache"
		applyDefaultCurrencyTimeLimit(desc);
	}
}
 
Example #30
Source File: ImmutableDescriptorSerialTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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");
}