本文整理汇总了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);
}
}
示例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;
}
示例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;
}