|
@@ -35,7 +35,16 @@ import org.apache.hadoop.metrics2.annotation.Metric;
|
|
|
import org.apache.hadoop.metrics2.annotation.Metrics;
|
|
|
|
|
|
/**
|
|
|
- * Helper class to build metrics source object from annotations
|
|
|
+ * Helper class to build {@link MetricsSource} object from annotations.
|
|
|
+ * <p>
|
|
|
+ * For a given source object:
|
|
|
+ * <ul>
|
|
|
+ * <li>Sets the {@link Field}s annotated with {@link Metric} to
|
|
|
+ * {@link MutableMetric} and adds it to the {@link MetricsRegistry}.</li>
|
|
|
+ * <li>
|
|
|
+ * For {@link Method}s annotated with {@link Metric} creates
|
|
|
+ * {@link MutableMetric} and adds it to the {@link MetricsRegistry}.</li>
|
|
|
+ * </ul>
|
|
|
*/
|
|
|
@InterfaceAudience.Private
|
|
|
public class MetricsSourceBuilder {
|
|
@@ -115,9 +124,15 @@ public class MetricsSourceBuilder {
|
|
|
return r;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Change the declared field {@code field} in {@code source} Object to
|
|
|
+ * {@link MutableMetric}
|
|
|
+ */
|
|
|
private void add(Object source, Field field) {
|
|
|
for (Annotation annotation : field.getAnnotations()) {
|
|
|
- if (!(annotation instanceof Metric)) continue;
|
|
|
+ if (!(annotation instanceof Metric)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
try {
|
|
|
// skip fields already set
|
|
|
field.setAccessible(true);
|
|
@@ -131,7 +146,7 @@ public class MetricsSourceBuilder {
|
|
|
registry);
|
|
|
if (mutable != null) {
|
|
|
try {
|
|
|
- field.set(source, mutable);
|
|
|
+ field.set(source, mutable); // Set the source field to MutableMetric
|
|
|
hasAtMetric = true;
|
|
|
} catch (Exception e) {
|
|
|
throw new MetricsException("Error setting field "+ field +
|
|
@@ -141,9 +156,12 @@ public class MetricsSourceBuilder {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /** Add {@link MutableMetric} for a method annotated with {@link Metric} */
|
|
|
private void add(Object source, Method method) {
|
|
|
for (Annotation annotation : method.getAnnotations()) {
|
|
|
- if (!(annotation instanceof Metric)) continue;
|
|
|
+ if (!(annotation instanceof Metric)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
factory.newForMethod(source, method, (Metric) annotation, registry);
|
|
|
hasAtMetric = true;
|
|
|
}
|