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

JmxDumpUtil.java 文件源码 项目:alfresco-repository 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Dumps the details of a single MBean.
 * 
 * @param connection
 *            the server connection (or server itself)
 * @param objectName
 *            the object name
 * @param out
 *            PrintWriter to write the output to
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 * @throws JMException
 *             Signals a JMX error
 */
private static void printMBeanInfo(MBeanServerConnection connection, ObjectName objectName, PrintWriter out)
        throws IOException, JMException
{
    Map<String, Object> attributes = new TreeMap<String, Object>();
    MBeanInfo info = connection.getMBeanInfo(objectName);
    attributes.put("** Object Name", objectName.toString());
    attributes.put("** Object Type", info.getClassName());
    for (MBeanAttributeInfo element : info.getAttributes())
    {
        Object value;
        if (element.isReadable())
        {
            try
            {
                value = connection.getAttribute(objectName, element.getName());
            }
            catch (Exception e)
            {
                value = JmxDumpUtil.PROTECTED_VALUE;
            }
        }
        else
        {
            value = JmxDumpUtil.PROTECTED_VALUE;
        }
        attributes.put(element.getName(), value);
    }
    if (objectName.getCanonicalName().equals("Alfresco:Name=SystemProperties"))
    {
        String osName = (String) attributes.get(OS_NAME);
        if (osName != null && osName.toLowerCase().startsWith("linux"))
        {
            attributes.put(OS_NAME, updateOSNameAttributeForLinux(osName));
        }
    }
    tabulate(JmxDumpUtil.NAME_HEADER, JmxDumpUtil.VALUE_HEADER, attributes, out, 0);
}
JmxManagerView.java 文件源码 项目:truevfs 阅读 23 收藏 0 点赞 0 评论 0
@Override
protected String getDescription(final MBeanAttributeInfo info) {
    switch (info.getName()) {
    case "FileSystemsMounted":
        return "The number of file systems which have been mounted.";
    case "FileSystemsTotal":
        return "The total number of file systems.";
    case "TopLevelArchiveFileSystemsMounted":
        return "The number of top level archive file systems which have been mounted.";
    case "TopLevelArchiveFileSystemsTotal":
        return "The total number of top level archive file systems.";
    default:
        return null;
    }
}
JmxModelView.java 文件源码 项目:truevfs 阅读 24 收藏 0 点赞 0 评论 0
@Override
protected String getDescription(final MBeanAttributeInfo info) {
    switch (info.getName()) {
    case "Mounted":
        return "Whether or not this file system is mounted.";
    case "MountPoint":
        return "The mount point URI of this file system.";
    case "MountPointOfParent":
        return "The mount point URI of the parent file system.";
    case "SizeOfData":
        return "The data size of this file system.";
    case "SizeOfStorage":
        return "The storage size of this file system.";
    case "TimeCreatedDate":
        return "The time this file system has been created.";
    case "TimeCreatedMillis":
        return "The time this file system has been created in milliseconds.";
    case "TimeReadDate":
        return "The last time this file system has been read or accessed.";
    case "TimeReadMillis":
        return "The last time this file system has been read or accessed in milliseconds.";
    case "TimeWrittenDate":
        return "The last time this file system has been written.";
    case "TimeWrittenMillis":
        return "The last time this file system has been written in milliseconds.";
    default:
        return null;
    }
}
JMXAccessorSetTask.java 文件源码 项目:tomcat7 阅读 22 收藏 0 点赞 0 评论 0
/**
 * Get MBean Attribute from Mbean Server
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(
        MBeanServerConnection jmxServerConnection,
        String name,
        String attribute) throws Exception {
    ObjectName oname = new ObjectName(name);
    String mattrType = null;
    MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
    MBeanAttributeInfo attrs[] = minfo.getAttributes();
    for (int i = 0; mattrType == null && i < attrs.length; i++) {
        if (attribute.equals(attrs[i].getName()))
            mattrType = attrs[i].getType();
    }
    return mattrType;
}
JMXPollUtil.java 文件源码 项目:flume-release-1.7.0 阅读 25 收藏 0 点赞 0 评论 0
public static Map<String, Map<String, String>> getAllMBeans() {
  Map<String, Map<String, String>> mbeanMap = Maps.newHashMap();
  Set<ObjectInstance> queryMBeans = null;
  try {
    queryMBeans = mbeanServer.queryMBeans(null, null);
  } catch (Exception ex) {
    LOG.error("Could not get Mbeans for monitoring", ex);
    Throwables.propagate(ex);
  }
  for (ObjectInstance obj : queryMBeans) {
    try {
      if (!obj.getObjectName().toString().startsWith("org.apache.flume")) {
        continue;
      }
      MBeanAttributeInfo[] attrs = mbeanServer.getMBeanInfo(obj.getObjectName()).getAttributes();
      String[] strAtts = new String[attrs.length];
      for (int i = 0; i < strAtts.length; i++) {
        strAtts[i] = attrs[i].getName();
      }
      AttributeList attrList = mbeanServer.getAttributes(obj.getObjectName(), strAtts);
      String component = obj.getObjectName().toString().substring(
          obj.getObjectName().toString().indexOf('=') + 1);
      Map<String, String> attrMap = Maps.newHashMap();

      for (Object attr : attrList) {
        Attribute localAttr = (Attribute) attr;
        if (localAttr.getName().equalsIgnoreCase("type")) {
          component = localAttr.getValue() + "." + component;
        }
        attrMap.put(localAttr.getName(), localAttr.getValue().toString());
      }
      mbeanMap.put(component, attrMap);
    } catch (Exception e) {
      LOG.error("Unable to poll JMX for metrics.", e);
    }
  }
  return mbeanMap;
}
MBeanClientInterceptor.java 文件源码 项目:lams 阅读 37 收藏 0 点赞 0 评论 0
private Object invokeAttribute(PropertyDescriptor pd, MethodInvocation invocation)
        throws JMException, IOException {

    String attributeName = JmxUtils.getAttributeName(pd, this.useStrictCasing);
    MBeanAttributeInfo inf = this.allowedAttributes.get(attributeName);
    // If no attribute is returned, we know that it is not defined in the
    // management interface.
    if (inf == null) {
        throw new InvalidInvocationException(
                "Attribute '" + pd.getName() + "' is not exposed on the management interface");
    }
    if (invocation.getMethod().equals(pd.getReadMethod())) {
        if (inf.isReadable()) {
            return this.serverToUse.getAttribute(this.objectName, attributeName);
        }
        else {
            throw new InvalidInvocationException("Attribute '" + attributeName + "' is not readable");
        }
    }
    else if (invocation.getMethod().equals(pd.getWriteMethod())) {
        if (inf.isWritable()) {
            this.serverToUse.setAttribute(this.objectName, new Attribute(attributeName, invocation.getArguments()[0]));
            return null;
        }
        else {
            throw new InvalidInvocationException("Attribute '" + attributeName + "' is not writable");
        }
    }
    else {
        throw new IllegalStateException(
                "Method [" + invocation.getMethod() + "] is neither a bean property getter nor a setter");
    }
}
JMXAccessorSetTask.java 文件源码 项目:lams 阅读 32 收藏 0 点赞 0 评论 0
/**
 * Get MBean Attriute from Mbean Server
 * @param jmxServerConnection
 * @param name
 * @param attribute
 * @return The type
 * @throws Exception
 */
protected String getMBeanAttributeType(
        MBeanServerConnection jmxServerConnection,
        String name,
        String attribute) throws Exception {
    ObjectName oname = new ObjectName(name);
    String mattrType = null;
    MBeanInfo minfo = jmxServerConnection.getMBeanInfo(oname);
    MBeanAttributeInfo attrs[] = minfo.getAttributes();
    if (attrs != null) {
        for (int i = 0; mattrType == null && i < attrs.length; i++) {
            if (attribute.equals(attrs[i].getName()))
                mattrType = attrs[i].getType();
        }
    }
    return mattrType;
}
AbstractDynamicWrapper.java 文件源码 项目:hashsdn-controller 阅读 22 收藏 0 点赞 0 评论 0
private static MBeanInfo generateMBeanInfo(final Module module,
        final Map<String, AttributeHolder> attributeHolderMap, final MBeanOperationInfo[] operations,
        final Set<Class<?>> jmxInterfaces) {

    String description = findDescription(module.getClass(), jmxInterfaces);
    MBeanConstructorInfo[] constructors = new MBeanConstructorInfo[0];
    List<MBeanAttributeInfo> attributes = new ArrayList<>(attributeHolderMap.size());
    for (AttributeHolder attributeHolder : attributeHolderMap.values()) {
        attributes.add(attributeHolder.toMBeanAttributeInfo());
    }
    return new MBeanInfo(module.getClass().getName(), description, attributes.toArray(new MBeanAttributeInfo[0]),
            constructors, operations, new MBeanNotificationInfo[0]);
}
StandardMBeanIntrospector.java 文件源码 项目:OpenJSharp 阅读 27 收藏 0 点赞 0 评论 0
@Override
MBeanAttributeInfo getMBeanAttributeInfo(String attributeName,
        Method getter, Method setter) {

    final String description = "Attribute exposed for management";
    try {
        return new MBeanAttributeInfo(attributeName, description,
                                      getter, setter);
    } catch (IntrospectionException e) {
        throw new RuntimeException(e); // should not happen
    }
}
MBeanIntrospector.java 文件源码 项目:OpenJSharp 阅读 24 收藏 0 点赞 0 评论 0
public void visitAttribute(String attributeName,
        M getter,
        M setter) {
    MBeanAttributeInfo mbai =
            getMBeanAttributeInfo(attributeName, getter, setter);

    attrs.add(mbai);
}


问题


面经


文章

微信
公众号

扫码关注公众号