JmxUtils.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:voldemort 作者:
/**
 * Extract all operations and attributes from the given object that have
 * been annotated with the Jmx annotation. Operations are all methods that
 * are marked with the JmxOperation annotation.
 * 
 * @param object The object to process
 * @return An array of operations taken from the object
 */
public static ModelMBeanOperationInfo[] extractOperationInfo(Object object) {
    ArrayList<ModelMBeanOperationInfo> infos = new ArrayList<ModelMBeanOperationInfo>();
    for(Method m: object.getClass().getMethods()) {
        JmxOperation jmxOperation = m.getAnnotation(JmxOperation.class);
        JmxGetter jmxGetter = m.getAnnotation(JmxGetter.class);
        JmxSetter jmxSetter = m.getAnnotation(JmxSetter.class);
        if(jmxOperation != null || jmxGetter != null || jmxSetter != null) {
            String description = "";
            int visibility = 1;
            int impact = MBeanOperationInfo.UNKNOWN;
            if(jmxOperation != null) {
                description = jmxOperation.description();
                impact = jmxOperation.impact();
            } else if(jmxGetter != null) {
                description = jmxGetter.description();
                impact = MBeanOperationInfo.INFO;
                visibility = 4;
            } else if(jmxSetter != null) {
                description = jmxSetter.description();
                impact = MBeanOperationInfo.ACTION;
                visibility = 4;
            }
            ModelMBeanOperationInfo info = new ModelMBeanOperationInfo(m.getName(),
                                                                       description,
                                                                       extractParameterInfo(m),
                                                                       m.getReturnType()
                                                                        .getName(),
                                                                       impact);
            info.getDescriptor().setField("visibility", Integer.toString(visibility));
            infos.add(info);
        }
    }

    return infos.toArray(new ModelMBeanOperationInfo[infos.size()]);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号