try {
Method executeMethod = task.getClass().getMethod("execute",
ImmutableMultimap.class, PrintWriter.class);
if(executeMethod.isAnnotationPresent(Timed.class)) {
Timed annotation = executeMethod.getAnnotation(Timed.class);
String name = chooseName(annotation.name(),
annotation.absolute(),
task);
Timer timer = metricRegistry.timer(name);
taskExecutor = new TimedTask(taskExecutor, timer);
}
if(executeMethod.isAnnotationPresent(Metered.class)) {
Metered annotation = executeMethod.getAnnotation(Metered.class);
String name = chooseName(annotation.name(),
annotation.absolute(),
task);
Meter meter = metricRegistry.meter(name);
taskExecutor = new MeteredTask(taskExecutor, meter);
}
if(executeMethod.isAnnotationPresent(ExceptionMetered.class)) {
ExceptionMetered annotation = executeMethod.getAnnotation(ExceptionMetered.class);
String name = chooseName(annotation.name(),
annotation.absolute(),
task,
ExceptionMetered.DEFAULT_NAME_SUFFIX);
Meter exceptionMeter = metricRegistry.meter(name);
taskExecutor = new ExceptionMeteredTask(taskExecutor, exceptionMeter, annotation.cause());
}
} catch (NoSuchMethodException e) {
}
taskExecutors.put(task, taskExecutor);