java类javax.management.AttributeList的实例源码

MBeanServerDelegateImpl.java 文件源码 项目:OpenJSharp 阅读 25 收藏 0 点赞 0 评论 0
/**
 * Makes it possible to get the values of several attributes of
 * the MBeanServerDelegate.
 *
 * @param attributes A list of the attributes to be retrieved.
 *
 * @return  The list of attributes retrieved.
 *
 */
public AttributeList getAttributes(String[] attributes) {
    // If attributes is null, the get all attributes.
    //
    final String[] attn = (attributes==null?attributeNames:attributes);

    // Prepare the result list.
    //
    final int len = attn.length;
    final AttributeList list = new AttributeList(len);

    // Get each requested attribute.
    //
    for (int i=0;i<len;i++) {
        try {
            final Attribute a =
                new Attribute(attn[i],getAttribute(attn[i]));
            list.add(a);
        } catch (Exception x) {
            // Skip the attribute that couldn't be obtained.
            //
            if (MBEANSERVER_LOGGER.isLoggable(Level.FINEST)) {
                MBEANSERVER_LOGGER.logp(Level.FINEST,
                        MBeanServerDelegateImpl.class.getName(),
                        "getAttributes",
                        "Attribute " + attn[i] + " not found");
            }
        }
    }

    // Finally return the result.
    //
    return list;
}
AttributeListTypeSafeTest.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
private static void doOp(AttributeList alist, Op op) {
    Object x = "oops";
    switch (op) {
        case ADD: alist.add(x); break;
        case ADD_AT: alist.add(0, x); break;
        case ADD_ALL: alist.add(Collections.singleton(x)); break;
        case ADD_ALL_AT: alist.add(0, Collections.singleton(x)); break;
        case SET: alist.set(0, x); break;
        default: throw new AssertionError("Case not covered");
    }
}
KafkaMetrics.java 文件源码 项目:kmanager 阅读 13 收藏 0 点赞 0 评论 0
private Long getLongValue(AttributeList attributes, String name) {
  List<Attribute> _attributes = attributes.asList();
  for (Attribute attr : _attributes) {
    if (attr.getName().equalsIgnoreCase(name)) {
      return (Long) attr.getValue();
    }
  }
  return 0L;
}
MBeanSupport.java 文件源码 项目:OpenJSharp 阅读 23 收藏 0 点赞 0 评论 0
public final AttributeList getAttributes(String[] attributes) {
    final AttributeList result = new AttributeList(attributes.length);
    for (String attrName : attributes) {
        try {
            final Object attrValue = getAttribute(attrName);
            result.add(new Attribute(attrName, attrValue));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}
RequiredModelMBean.java 文件源码 项目:OpenJSharp 阅读 26 收藏 0 点赞 0 评论 0
/**
 * Returns the values of several attributes in the ModelMBean.
 * Executes a getAttribute for each attribute name in the
 * attrNames array passed in.
 *
 * @param attrNames A String array of names of the attributes
 * to be retrieved.
 *
 * @return The array of the retrieved attributes.
 *
 * @exception RuntimeOperationsException Wraps an
 * {@link IllegalArgumentException}: The object name in parameter is
 * null or attributes in parameter is null.
 *
 * @see #setAttributes(javax.management.AttributeList)
 */
public AttributeList getAttributes(String[] attrNames)      {
    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
        "getAttributes(String[])","Entry");
    }

    if (attrNames == null)
        throw new RuntimeOperationsException(new
            IllegalArgumentException("attributeNames must not be null"),
            "Exception occurred trying to get attributes of a "+
            "RequiredModelMBean");

    AttributeList responseList = new AttributeList();
    for (int i = 0; i < attrNames.length; i++) {
        try {
            responseList.add(new Attribute(attrNames[i],
                                 getAttribute(attrNames[i])));
        } catch (Exception e) {
            // eat exceptions because interface doesn't have an
            // exception on it
            if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
                MODELMBEAN_LOGGER.logp(Level.FINER,
                        RequiredModelMBean.class.getName(),
                    "getAttributes(String[])",
                        "Failed to get \"" + attrNames[i] + "\": ", e);
            }
        }
    }

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
            RequiredModelMBean.class.getName(),
                "getAttributes(String[])","Exit");
    }

    return responseList;
}
RequiredModelMBean.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
/**
 * Sets the values of an array of attributes of this ModelMBean.
 * Executes the setAttribute() method for each attribute in the list.
 *
 * @param attributes A list of attributes: The identification of the
 * attributes to be set and  the values they are to be set to.
 *
 * @return  The array of attributes that were set, with their new
 *    values in Attribute instances.
 *
 * @exception RuntimeOperationsException Wraps an
 *   {@link IllegalArgumentException}: The object name in parameter
 *   is null or attributes in parameter is null.
 *
 * @see #getAttributes
 **/
public AttributeList setAttributes(AttributeList attributes) {

    if (MODELMBEAN_LOGGER.isLoggable(Level.FINER)) {
        MODELMBEAN_LOGGER.logp(Level.FINER,
                RequiredModelMBean.class.getName(),
            "setAttribute(Attribute)", "Entry");
    }

    if (attributes == null)
        throw new RuntimeOperationsException(new
            IllegalArgumentException("attributes must not be null"),
            "Exception occurred trying to set attributes of a "+
            "RequiredModelMBean");

    final AttributeList responseList = new AttributeList();

    // Go through the list of attributes
    for (Attribute attr : attributes.asList()) {
        try {
            setAttribute(attr);
            responseList.add(attr);
        } catch (Exception excep) {
            responseList.remove(attr);
        }
    }

    return responseList;
}
OffHeapManagementDUnitTest.java 文件源码 项目:monarch 阅读 15 收藏 0 点赞 0 评论 0
/**
 * Creates and adds a generic GaugeMonitor for an attribute of the MemberMXBean.
 * 
 * @param attribute the attribute to monitor.
 * @param highThreshold the high threshold trigger.
 * @param lowThreshold the low threshold trigger.
 */
protected void setupOffHeapMonitor(String attribute, long highThreshold, long lowThreshold) {
  ObjectName memberMBeanObjectName = MBeanJMXAdapter.getMemberMBeanName(
      InternalDistributedSystem.getConnectedInstance().getDistributedMember());
  assertNotNull(memberMBeanObjectName);

  try {
    ObjectName offHeapMonitorName = new ObjectName("monitors:type=Gauge,attr=" + attribute);
    mbeanServer.createMBean("javax.management.monitor.GaugeMonitor", offHeapMonitorName);

    AttributeList al = new AttributeList();
    al.add(new Attribute("ObservedObject", memberMBeanObjectName));
    al.add(new Attribute("GranularityPeriod", 500));
    al.add(new Attribute("ObservedAttribute", attribute));
    al.add(new Attribute("Notify", true));
    al.add(new Attribute("NotifyHigh", true));
    al.add(new Attribute("NotifyLow", true));
    al.add(new Attribute("HighTheshold", highThreshold));
    al.add(new Attribute("LowThreshold", lowThreshold));

    mbeanServer.setAttributes(offHeapMonitorName, al);
    mbeanServer.addNotificationListener(offHeapMonitorName, notificationListener, null, null);
    mbeanServer.invoke(offHeapMonitorName, "start", new Object[] {}, new String[] {});
  } catch (Exception e) {
    fail(e.getMessage());
  }
}
BaseCloseMBean.java 文件源码 项目:ChronoBike 阅读 19 收藏 0 点赞 0 评论 0
public AttributeList setAttributes(AttributeList attributes) 
 {
       // Check attributes is not null to avoid NullPointerException later on
       //
       if (attributes != null) 
       {
        AttributeList resultList = new AttributeList();

        // If attributeNames is empty, nothing more to do
        //
        if (attributes.isEmpty())
            return resultList;

        // For each attribute, try to set it and add to the result list if
        // successfull
        //
        for (Iterator i = attributes.iterator(); i.hasNext();)
        {
            Attribute attr = (Attribute) i.next();
            try
            {
                setAttribute(attr);
                String name = attr.getName();
                Object value = getAttribute(name); 
                resultList.add(new Attribute(name,value));
            } 
            catch(Exception e)
            {
                e.printStackTrace();
            }
        }
        return resultList;
    }
       return null;
}
OldMBeanServerTest.java 文件源码 项目:openjdk-jdk10 阅读 18 收藏 0 点赞 0 评论 0
public AttributeList getAttributes(String[] attributes) {
    AttributeList list = new AttributeList();
    for (String attr : attributes) {
        try {
            list.add(new Attribute(attr, getAttribute(attr)));
        } catch (Exception e) {
            // OK: ignore per spec
        }
    }
    return list;
}
MBeanSupport.java 文件源码 项目:jdk8u-jdk 阅读 26 收藏 0 点赞 0 评论 0
public final AttributeList getAttributes(String[] attributes) {
    final AttributeList result = new AttributeList(attributes.length);
    for (String attrName : attributes) {
        try {
            final Object attrValue = getAttribute(attrName);
            result.add(new Attribute(attrName, attrValue));
        } catch (Exception e) {
            // OK: attribute is not included in returned list, per spec
            // XXX: log the exception
        }
    }
    return result;
}


问题


面经


文章

微信
公众号

扫码关注公众号