Java 类javax.management.Descriptor 实例源码

项目:eZooKeeper    文件:BaseJmxModelMainFormPage.java   
protected void initDescriptorSectionFromModel() {

        Descriptor descriptor = getJmxDescriptor();
        if (descriptor == null) {
            return;
        }

        Table table = getDescriptorTable();
        if (table == null) {
            return;
        }

        table.removeAll();

        for (String fieldName : descriptor.getFieldNames()) {
            TableItem item = new TableItem(table, SWT.NONE);
            Object value = descriptor.getFieldValue(fieldName);
            item.setText(0, fieldName);
            item.setText(1, String.valueOf(value));
        }

        packTable(table, DEFAULT_NAME_VALUE_COLUMN_WIDTHS);
    }
项目:lams    文件:MetadataMBeanInfoAssembler.java   
private void populateMetricDescriptor(Descriptor desc, ManagedMetric metric) {
    applyCurrencyTimeLimit(desc, metric.getCurrencyTimeLimit());

    if (StringUtils.hasLength(metric.getPersistPolicy())) {
        desc.setField(FIELD_PERSIST_POLICY, metric.getPersistPolicy());
    }
    if (metric.getPersistPeriod() >= 0) {
        desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(metric.getPersistPeriod()));
    }

    if (StringUtils.hasLength(metric.getDisplayName())) {
        desc.setField(FIELD_DISPLAY_NAME, metric.getDisplayName());
    }

    if(StringUtils.hasLength(metric.getUnit())) {
        desc.setField(FIELD_UNITS, metric.getUnit());
    }

    if(StringUtils.hasLength(metric.getCategory())) {
        desc.setField(FIELD_METRIC_CATEGORY, metric.getCategory());
    }

    String metricType = (metric.getMetricType() == null) ? MetricType.GAUGE.toString() : metric.getMetricType().toString();
    desc.setField(FIELD_METRIC_TYPE, metricType);
}
项目:openjdk-jdk10    文件:RequiredModelMBean.java   
/**
 * 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);
}
项目: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);
    }
}
项目:openjdk-jdk10    文件:ModelMBeanNotificationInfo.java   
/**
 * 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.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
    }

    if (notificationDescriptor == null) {
        // Dead code. Should never happen.
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
            MODELMBEAN_LOGGER.log(Level.TRACE,
                    "Descriptor value is null, " +
                    "setting descriptor to default values");
        }
        notificationDescriptor = validDescriptor(null);
    }

    return((Descriptor)notificationDescriptor.clone());
}
项目:OpenJSharp    文件:ModelMBeanConstructorInfo.java   
/**
 * Returns a copy of the associated Descriptor.
 *
 * @return Descriptor associated with the
 * ModelMBeanConstructorInfo object.
 *
 * @see #setDescriptor
 */


@Override
public Descriptor getDescriptor()
{
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanConstructorInfo.class.getName(),
                "getDescriptor()", "Entry");
    }
    if (consDescriptor == null){
        consDescriptor = validDescriptor(null);
    }
    return((Descriptor)consDescriptor.clone());
}
项目:openjdk-jdk10    文件:OpenMBeanParameterInfoSupport.java   
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);
}
项目:OpenJSharp    文件:ModelMBeanInfoSupport.java   
private Descriptor getMBeanDescriptorNoException() {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "getMBeanDescriptorNoException()", "Entry");
    }

    if (modelMBeanDescriptor == null)
        modelMBeanDescriptor = validDescriptor(null);

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "getMBeanDescriptorNoException()",
                "Exit, returning: " + modelMBeanDescriptor);
    }
    return (Descriptor) modelMBeanDescriptor.clone();
}
项目:OpenJSharp    文件:RequiredModelMBean.java   
/**
 * 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);
}
项目:OpenJSharp    文件:RequiredModelMBean.java   
/**
 * 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 );
}
项目:OpenJSharp    文件:OpenMBeanParameterInfoSupport.java   
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);
}
项目: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);
    }
}
项目:jdk8u-jdk    文件:ModelMBeanInfoSupport.java   
private Descriptor getMBeanDescriptorNoException() {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "getMBeanDescriptorNoException()", "Entry");
    }

    if (modelMBeanDescriptor == null)
        modelMBeanDescriptor = validDescriptor(null);

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanInfoSupport.class.getName(),
                "getMBeanDescriptorNoException()",
                "Exit, returning: " + modelMBeanDescriptor);
    }
    return (Descriptor) modelMBeanDescriptor.clone();
}
项目:monarch    文件:MX4JModelMBean.java   
private void removeAttributeChangeNotificationListener(NotificationListener listener,
    String attributeName, Object handback)
    throws MBeanException, RuntimeOperationsException, ListenerNotFoundException {
  if (listener == null)
    throw new RuntimeOperationsException(new IllegalArgumentException(
        LocalizedStrings.MX4JModelMBean_LISTENER_CANNOT_BE_NULL.toLocalizedString()));
  AttributeChangeNotificationFilter filter = new AttributeChangeNotificationFilter();
  if (attributeName != null) {
    filter.enableAttribute(attributeName);
  } else {
    MBeanAttributeInfo[] ai = m_modelMBeanInfo.getAttributes();
    for (int i = 0; i < ai.length; i++) {
      Descriptor d = ((ModelMBeanAttributeInfo) ai[i]).getDescriptor();
      filter.enableAttribute((String) d.getFieldValue("name"));
    }
  }

  getAttributeChangeBroadcaster().removeNotificationListener(listener, filter, handback);

  Logger logger = getLogger();
  if (logger.isEnabledFor(Logger.DEBUG))
    logger.debug("Listener " + listener + " for attribute " + attributeName
        + " removed successfully, handback is " + handback);
}
项目:monarch    文件:MX4JModelMBean.java   
private boolean shouldPersistNow(Descriptor attribute, Descriptor mbean, String lastUpdateField) {
  int persist = getPersistPolicy(attribute, mbean);
  if (persist == PERSIST_NO_MORE_OFTEN_THAN) {
    Long period = getFieldTimeValue(attribute, mbean, "persistPeriod");
    long now = System.currentTimeMillis();
    Long lastUpdate = (Long) attribute.getFieldValue(lastUpdateField);
    if (now - lastUpdate.longValue() < period.longValue())
      return false;
    else
      return true;
  } else if (persist == PERSIST_NEVER) {
    return false;
  } else if (persist == PERSIST_ON_TIMER) {
    return false;
  } else if (persist == PERSIST_ON_UPDATE) {
    return true;
  } else {
    throw new ImplementationException(
        LocalizedStrings.MX4JModelMBean_INVALID_PERSIST_VALUE.toLocalizedString());
  }
}
项目:jdk8u-jdk    文件:ImmutableNotificationInfoTest.java   
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;
    }
}
项目:monarch    文件:StatisticAttributeInfo.java   
@Override
public ModelMBeanAttributeInfo createAttributeInfo() {
  Descriptor desc = new DescriptorSupport(new String[] {"name=" + this.displayName,
      "descriptorType=attribute", "currencyTimeLimit=-1", // always stale
      "displayName=" + this.displayName, "getMethod=getValue"});

  Assert.assertTrue(this.stat != null, "Stat target object is null!");
  desc.setField("targetObject", this.stat);

  ModelMBeanAttributeInfo info = new ModelMBeanAttributeInfo(this.displayName, // name
      this.type, // type
      this.description, // description
      this.readable, // isReadable
      this.writeable, // isWritable
      this.is, // isIs
      desc);

  return info;
}
项目:openjdk-jdk10    文件:OpenMBeanAttributeInfoSupport.java   
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);
}
项目:openjdk-jdk10    文件:DiagnosticCommandImpl.java   
private Descriptor commandDescriptor(Wrapper w) throws IllegalArgumentException {
    HashMap<String, Object> map = new HashMap<>();
    map.put("dcmd.name", w.info.getName());
    map.put("dcmd.description", w.info.getDescription());
    map.put("dcmd.vmImpact", w.info.getImpact());
    map.put("dcmd.permissionClass", w.info.getPermissionClass());
    map.put("dcmd.permissionName", w.info.getPermissionName());
    map.put("dcmd.permissionAction", w.info.getPermissionAction());
    map.put("dcmd.enabled", w.info.isEnabled());
    StringBuilder sb = new StringBuilder();
    sb.append("help ");
    sb.append(w.info.getName());
    map.put("dcmd.help", executeDiagnosticCommand(sb.toString()));
    if (w.info.getArgumentsInfo() != null && !w.info.getArgumentsInfo().isEmpty()) {
        HashMap<String, Object> allargmap = new HashMap<>();
        for (DiagnosticCommandArgumentInfo arginfo : w.info.getArgumentsInfo()) {
            HashMap<String, Object> argmap = new HashMap<>();
            argmap.put("dcmd.arg.name", arginfo.getName());
            argmap.put("dcmd.arg.type", arginfo.getType());
            argmap.put("dcmd.arg.description", arginfo.getDescription());
            argmap.put("dcmd.arg.isMandatory", arginfo.isMandatory());
            argmap.put("dcmd.arg.isMultiple", arginfo.isMultiple());
            boolean isOption = arginfo.isOption();
            argmap.put("dcmd.arg.isOption", isOption);
            if(!isOption) {
                argmap.put("dcmd.arg.position", arginfo.getPosition());
            } else {
                argmap.put("dcmd.arg.position", -1);
            }
            allargmap.put(arginfo.getName(), new ImmutableDescriptor(argmap));
        }
        map.put("dcmd.arguments", new ImmutableDescriptor(allargmap));
    }
    return new ImmutableDescriptor(map);
}
项目:lams    文件:MetadataMBeanInfoAssembler.java   
/**
 * Adds descriptor fields from the {@code ManagedResource} attribute
 * to the MBean descriptor. Specifically, adds the {@code currencyTimeLimit},
 * {@code persistPolicy}, {@code persistPeriod}, {@code persistLocation}
 * and {@code persistName} descriptor fields if they are present in the metadata.
 */
@Override
protected void populateMBeanDescriptor(Descriptor desc, Object managedBean, String beanKey) {
    ManagedResource mr = this.attributeSource.getManagedResource(getClassToExpose(managedBean));
    if (mr == null) {
        throw new InvalidMetadataException(
                "No ManagedResource attribute found for class: " + getClassToExpose(managedBean));
    }

    applyCurrencyTimeLimit(desc, mr.getCurrencyTimeLimit());

    if (mr.isLog()) {
        desc.setField(FIELD_LOG, "true");
    }
    if (StringUtils.hasLength(mr.getLogFile())) {
        desc.setField(FIELD_LOG_FILE, mr.getLogFile());
    }

    if (StringUtils.hasLength(mr.getPersistPolicy())) {
        desc.setField(FIELD_PERSIST_POLICY, mr.getPersistPolicy());
    }
    if (mr.getPersistPeriod() >= 0) {
        desc.setField(FIELD_PERSIST_PERIOD, Integer.toString(mr.getPersistPeriod()));
    }
    if (StringUtils.hasLength(mr.getPersistName())) {
        desc.setField(FIELD_PERSIST_NAME, mr.getPersistName());
    }
    if (StringUtils.hasLength(mr.getPersistLocation())) {
        desc.setField(FIELD_PERSIST_LOCATION, mr.getPersistLocation());
    }
}
项目:lams    文件:MetadataMBeanInfoAssembler.java   
/**
 * Adds descriptor fields from the {@code ManagedAttribute} attribute or the {@code ManagedMetric} attribute
 * to the attribute descriptor.
 */
@Override
protected void populateAttributeDescriptor(Descriptor desc, Method getter, Method setter, String beanKey) {
    if(getter != null && hasManagedMetric(getter)) {
        populateMetricDescriptor(desc, this.attributeSource.getManagedMetric(getter));
    }
    else {
        ManagedAttribute gma =
            (getter == null) ? ManagedAttribute.EMPTY : this.attributeSource.getManagedAttribute(getter);
        ManagedAttribute sma =
            (setter == null) ? ManagedAttribute.EMPTY : this.attributeSource.getManagedAttribute(setter);
        populateAttributeDescriptor(desc,gma,sma);
    }
}
项目:OpenJSharp    文件: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;
}
项目:openjdk-jdk10    文件:ModelMBeanOperationInfo.java   
/**
 * Returns a copy of the associated Descriptor of the
 * ModelMBeanOperationInfo.
 *
 * @return Descriptor associated with the
 * ModelMBeanOperationInfo object.
 *
 * @see #setDescriptor
 */

public Descriptor getDescriptor()
{
    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
    }
    if (operationDescriptor == null) {
        operationDescriptor = validDescriptor(null);
    }

    return((Descriptor) operationDescriptor.clone());
}
项目:jdk8u-jdk    文件:OpenMBeanAttributeInfoSupport.java   
static String toString(OpenMBeanParameterInfo info) {
    Descriptor d = (info instanceof DescriptorRead) ?
        ((DescriptorRead) info).getDescriptor() : null;
    return
        info.getClass().getName() +
        "(name=" + info.getName() +
        ",openType=" + info.getOpenType() +
        ",default=" + info.getDefaultValue() +
        ",minValue=" + info.getMinValue() +
        ",maxValue=" + info.getMaxValue() +
        ",legalValues=" + info.getLegalValues() +
        ((d == null) ? "" : ",descriptor=" + d) +
        ")";
}
项目:openjdk-jdk10    文件:ModelMBeanInfoSupport.java   
private Descriptor getMBeanDescriptorNoException() {
    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Entry");
    }

    if (modelMBeanDescriptor == null)
        modelMBeanDescriptor = validDescriptor(null);

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE,
                "Exit, returning: " + modelMBeanDescriptor);
    }
    return (Descriptor) modelMBeanDescriptor.clone();
}
项目:openjdk-jdk10    文件: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;
}
项目:openjdk-jdk10    文件:ModelMBeanInfoSupport.java   
/**
 * Constructs a ModelMBeanInfoSupport which is a duplicate of the given
 * ModelMBeanInfo.  The returned object is a shallow copy of the given
 * object.  Neither the Descriptor nor the contained arrays
 * ({@code ModelMBeanAttributeInfo[]} etc) are cloned.  This method is
 * chiefly of interest to modify the Descriptor of the returned instance
 * via {@link #setDescriptor setDescriptor} without affecting the
 * Descriptor of the original object.
 *
 * @param mbi the ModelMBeanInfo instance from which the ModelMBeanInfo
 * being created is initialized.
 */
public ModelMBeanInfoSupport(ModelMBeanInfo  mbi) {
    super(mbi.getClassName(),
            mbi.getDescription(),
            mbi.getAttributes(),
            mbi.getConstructors(),
            mbi.getOperations(),
            mbi.getNotifications());

    modelMBeanAttributes = mbi.getAttributes();
    modelMBeanConstructors = mbi.getConstructors();
    modelMBeanOperations = mbi.getOperations();
    modelMBeanNotifications = mbi.getNotifications();

    try {
        Descriptor mbeandescriptor = mbi.getMBeanDescriptor();
        modelMBeanDescriptor = validDescriptor(mbeandescriptor);
    } catch (MBeanException mbe) {
        modelMBeanDescriptor = validDescriptor(null);
        if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
            MODELMBEAN_LOGGER.log(Level.TRACE,
                    "ModelMBeanInfo(ModelMBeanInfo) " +
                    "Could not get a valid modelMBeanDescriptor, " +
                    "setting a default Descriptor");
        }
    }

    if (MODELMBEAN_LOGGER.isLoggable(Level.TRACE)) {
        MODELMBEAN_LOGGER.log(Level.TRACE, "Exit");
    }
}
项目:openjdk-jdk10    文件:AnnotationTest.java   
public static void main(String[] args) throws Exception {
    System.out.println("Testing that annotations are correctly " +
                       "reflected in Descriptor entries");

    MBeanServer mbs =
        java.lang.management.ManagementFactory.getPlatformMBeanServer();
    ObjectName on = new ObjectName("a:b=c");

    Thing thing = new Thing();
    mbs.registerMBean(thing, on);
    check(mbs, on);
    mbs.unregisterMBean(on);

    ThingImpl thingImpl = new ThingImpl();
    mbs.registerMBean(thingImpl, on);
    Descriptor d = mbs.getMBeanInfo(on).getDescriptor();
    if (!d.getFieldValue("mxbean").equals("true")) {
        System.out.println("NOT OK: expected MXBean");
        failed = "Expected MXBean";
    }
    check(mbs, on);

    if (failed == null)
        System.out.println("Test passed");
    else
        throw new Exception("TEST FAILED: " + failed);
}
项目:OpenJSharp    文件:ModelMBeanOperationInfo.java   
/**
 * Returns a copy of the associated Descriptor of the
 * ModelMBeanOperationInfo.
 *
 * @return Descriptor associated with the
 * ModelMBeanOperationInfo object.
 *
 * @see #setDescriptor
 */

public Descriptor getDescriptor()
{
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                ModelMBeanOperationInfo.class.getName(),
                "getDescriptor()", "Entry");
    }
    if (operationDescriptor == null) {
        operationDescriptor = validDescriptor(null);
    }

    return((Descriptor) operationDescriptor.clone());
}
项目:jdk8u-jdk    文件:DcmdMBeanPermissionsTest.java   
static void testOperation(MBeanServer mbs, CustomSecurityManager sm,
        ObjectName on, MBeanOperationInfo opInfo) {
    System.out.println("Testing " + opInfo.getName());
    Descriptor desc = opInfo.getDescriptor();
    if (desc.getFieldValue("dcmd.permissionClass") == null) {
    // No special permission required, execution should not trigger
    // any security exception
        if (invokeOperation(mbs, on, opInfo)) {
            throw new RuntimeException("TEST FAILED");
        }
    } else {
        // Building the required permission
        Permission reqPerm = createPermission(
                (String)desc.getFieldValue("dcmd.permissionClass"),
                (String)desc.getFieldValue("dcmd.permissionName"),
                (String)desc.getFieldValue("dcmd.permissionAction"));
        // Paranoid mode: check that the SecurityManager has not already
        // been granted the permission
        sm.denyPermission(reqPerm);
        // A special permission is required for this operation,
        // invoking it without the permission granted must trigger
        // a security exception
        if(!invokeOperation(mbs, on, opInfo)) {
            throw new RuntimeException("TEST FAILED");
        }
        // grant the permission and re-try invoking the operation
        sm.grantPermission(reqPerm);
        if(invokeOperation(mbs, on, opInfo)) {
            throw new RuntimeException("TEST FAILED");
        }
        // Clean up
        sm.denyPermission(reqPerm);
    }
}
项目:openjdk-jdk10    文件:DcmdMBeanTest.java   
static void printOperation(MBeanOperationInfo info) {
    System.out.println("Name: "+info.getName());
    System.out.println("Description: "+info.getDescription());
    System.out.println("Return Type: "+info.getReturnType());
    System.out.println("Impact: "+info.getImpact());
    Descriptor desc = info.getDescriptor();
    System.out.println("Descriptor");
    for(int i=0; i<desc.getFieldNames().length; i++) {
        if(desc.getFieldNames()[i].compareTo("dcmd.arguments") == 0) {
            System.out.println("\t"+desc.getFieldNames()[i]+":");
            Descriptor desc2 =
                    (Descriptor)desc.getFieldValue(desc.getFieldNames()[i]);
            for(int j=0; j<desc2.getFieldNames().length; j++) {
                System.out.println("\t\t"+desc2.getFieldNames()[j]+"=");
                Descriptor desc3 =
                        (Descriptor)desc2.getFieldValue(desc2.getFieldNames()[j]);
                for(int k=0; k<desc3.getFieldNames().length; k++) {
                    System.out.println("\t\t\t"+desc3.getFieldNames()[k]+"="
                                       +desc3.getFieldValue(desc3.getFieldNames()[k]));
                }
            }
        } else {
            System.out.println("\t"+desc.getFieldNames()[i]+"="
                    +desc.getFieldValue(desc.getFieldNames()[i]));
        }
    }
}
项目:openjdk-jdk10    文件:OpenMBeanAttributeInfoSupport.java   
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);
}
项目:OpenJSharp    文件:ModelMBeanInfoSupport.java   
/**
 * 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();
    }
}
项目:OpenJSharp    文件:RequiredModelMBean.java   
private void cacheResult(ModelMBeanOperationInfo opInfo,
                         Descriptor opDescr, Object result)
        throws MBeanException {

    Descriptor mmbDesc =
        modelMBeanInfo.getMBeanDescriptor();

    Object objctl =
        opDescr.getFieldValue("currencyTimeLimit");
    String ctl;
    if (objctl != null) {
        ctl = objctl.toString();
    } else {
        ctl = null;
    }
    if ((ctl == null) && (mmbDesc != null)) {
        objctl =
            mmbDesc.getFieldValue("currencyTimeLimit");
        if (objctl != null) {
            ctl = objctl.toString();
        } else {
            ctl = null;
        }
    }
    if ((ctl != null) && !(ctl.equals("-1"))) {
        opDescr.setField("value", result);
        opDescr.setField("lastUpdatedTimeStamp",
                String.valueOf((new Date()).getTime()));


        modelMBeanInfo.setDescriptor(opDescr,
                                     "operation");
        if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
            MODELMBEAN_LOGGER.logp(Level.FINER,
                    RequiredModelMBean.class.getName(),
                    "invoke(String,Object[],Object[])",
                    "new descriptor is " + opDescr);
        }
    }
}
项目:jdk8u-jdk    文件: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;
}
项目: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);
}
项目:OpenJSharp    文件: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);
    }
}
项目:openjdk-jdk10    文件:OpenMBeanAttributeInfoSupport.java   
static <T> T valueFrom(Descriptor d, String name, OpenType<T> openType) {
    Object x = d.getFieldValue(name);
    if (x == null)
        return null;
    try {
        return convertFrom(x, openType);
    } catch (Exception e) {
        final String msg =
            "Cannot convert descriptor field " + name + "  to " +
            openType.getTypeName();
        throw EnvHelp.initCause(new IllegalArgumentException(msg), e);
    }
}
项目:jdk8u-jdk    文件:ModelMBeanInfoSupport.java   
/**
 * 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");
    }
}
项目:jdk8u-jdk    文件:ModelMBeanInfoSupport.java   
/**
 * 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();
    }
}