Do not expose Metrics reporter as CDI bean
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/6300194a Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/6300194a Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/6300194a Branch: refs/heads/master Commit: 6300194a1d45e190c264009a82be1ec30a7261e2 Parents: 40eea30 Author: Antonin Stefanutti <anto...@stefanutti.fr> Authored: Mon Jan 25 10:34:48 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Mon Jan 25 13:53:39 2016 +0100 ---------------------------------------------------------------------- .../example/metrics/cdi/MetricsCdiConfig.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/6300194a/examples/camel-example-metrics-cdi/src/main/java/org/apache/camel/example/metrics/cdi/MetricsCdiConfig.java ---------------------------------------------------------------------- diff --git a/examples/camel-example-metrics-cdi/src/main/java/org/apache/camel/example/metrics/cdi/MetricsCdiConfig.java b/examples/camel-example-metrics-cdi/src/main/java/org/apache/camel/example/metrics/cdi/MetricsCdiConfig.java index 0b543c8..8509804 100644 --- a/examples/camel-example-metrics-cdi/src/main/java/org/apache/camel/example/metrics/cdi/MetricsCdiConfig.java +++ b/examples/camel-example-metrics-cdi/src/main/java/org/apache/camel/example/metrics/cdi/MetricsCdiConfig.java @@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit; import javax.enterprise.context.ApplicationScoped; import javax.enterprise.event.Observes; import javax.enterprise.inject.Produces; +import javax.inject.Inject; import javax.inject.Named; import com.codahale.metrics.MetricRegistry; @@ -29,6 +30,7 @@ import org.apache.camel.component.metrics.MetricsComponent; import org.apache.camel.management.event.CamelContextStartedEvent; import org.apache.camel.management.event.CamelContextStoppedEvent; +@ApplicationScoped class MetricsCdiConfig { @Produces @@ -37,24 +39,25 @@ class MetricsCdiConfig { // TODO: remove when Camel Metrics component looks up for the Metrics registry by type only private MetricRegistry registry = new MetricRegistry(); - @Produces - @ApplicationScoped - private Slf4jReporter reporter(MetricRegistry registry) { - return Slf4jReporter.forRegistry(registry) + private final Slf4jReporter reporter; + + @Inject + MetricsCdiConfig(MetricRegistry registry) { + reporter = Slf4jReporter.forRegistry(registry) .convertRatesTo(TimeUnit.SECONDS) .convertDurationsTo(TimeUnit.MILLISECONDS) .build(); } - private static void onStart(@Observes CamelContextStartedEvent event, Slf4jReporter reporter) { + private void onStart(@Observes CamelContextStartedEvent event) { reporter.start(10L, TimeUnit.SECONDS); } - private static void onStop(@Observes CamelContextStoppedEvent event, Slf4jReporter reporter) { + private void onStop(@Observes CamelContextStoppedEvent event) { reporter.stop(); } - private static void configure(@Observes MetricsConfiguration config) { + private void configure(@Observes MetricsConfiguration config) { config.useAbsoluteName(true); } }