当前位置: 首页>>代码示例>>Java>>正文


Java ReflectionUtils.getDeclaredFieldsIncludingInherited方法代码示例

本文整理汇总了Java中org.apache.hadoop.util.ReflectionUtils.getDeclaredFieldsIncludingInherited方法的典型用法代码示例。如果您正苦于以下问题:Java ReflectionUtils.getDeclaredFieldsIncludingInherited方法的具体用法?Java ReflectionUtils.getDeclaredFieldsIncludingInherited怎么用?Java ReflectionUtils.getDeclaredFieldsIncludingInherited使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.util.ReflectionUtils的用法示例。


在下文中一共展示了ReflectionUtils.getDeclaredFieldsIncludingInherited方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: MetricsSourceBuilder

import org.apache.hadoop.util.ReflectionUtils; //导入方法依赖的package包/类
MetricsSourceBuilder(Object source, MutableMetricsFactory factory) {
  this.source = checkNotNull(source, "source");
  this.factory = checkNotNull(factory, "mutable metrics factory");
  Class<?> cls = source.getClass();
  registry = initRegistry(source);

  for (Field field : ReflectionUtils.getDeclaredFieldsIncludingInherited(cls)) {
    add(source, field);
  }
  for (Method method : ReflectionUtils.getDeclaredMethodsIncludingInherited(cls)) {
    add(source, method);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:14,代码来源:MetricsSourceBuilder.java

示例2: initRegistry

import org.apache.hadoop.util.ReflectionUtils; //导入方法依赖的package包/类
private MetricsRegistry initRegistry(Object source) {
  Class<?> cls = source.getClass();
  MetricsRegistry r = null;
  // Get the registry if it already exists.
  for (Field field : ReflectionUtils.getDeclaredFieldsIncludingInherited(cls)) {
    if (field.getType() != MetricsRegistry.class) continue;
    try {
      field.setAccessible(true);
      r = (MetricsRegistry) field.get(source);
      hasRegistry = r != null;
      break;
    } catch (Exception e) {
      LOG.warn("Error accessing field "+ field, e);
      continue;
    }
  }
  // Create a new registry according to annotation
  for (Annotation annotation : cls.getAnnotations()) {
    if (annotation instanceof Metrics) {
      Metrics ma = (Metrics) annotation;
      info = factory.getInfo(cls, ma);
      if (r == null) {
        r = new MetricsRegistry(info);
      }
      r.setContext(ma.context());
    }
  }
  if (r == null) return new MetricsRegistry(cls.getSimpleName());
  return r;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:31,代码来源:MetricsSourceBuilder.java

示例3: initRegistry

import org.apache.hadoop.util.ReflectionUtils; //导入方法依赖的package包/类
private MetricsRegistry initRegistry(Object source) {
  Class<?> cls = source.getClass();
  MetricsRegistry r = null;
  // Get the registry if it already exists.
  for (Field field : ReflectionUtils.getDeclaredFieldsIncludingInherited(cls)) {
    if (field.getType() != MetricsRegistry.class) continue;
    try {
      field.setAccessible(true);
      r = (MetricsRegistry) field.get(source);
      hasRegistry = r != null;
      break;
    }
    catch (Exception e) {
      LOG.warn("Error accessing field "+ field, e);
      continue;
    }
  }
  // Create a new registry according to annotation
  for (Annotation annotation : cls.getAnnotations()) {
    if (annotation instanceof Metrics) {
      Metrics ma = (Metrics) annotation;
      info = factory.getInfo(cls, ma);
      if (r == null) {
        r = new MetricsRegistry(info);
      }
      r.setContext(ma.context());
    }
  }
  if (r == null) return new MetricsRegistry(cls.getSimpleName());
  return r;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:MetricsSourceBuilder.java


注:本文中的org.apache.hadoop.util.ReflectionUtils.getDeclaredFieldsIncludingInherited方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。