You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2020/03/29 09:15:42 UTC
[camel] 01/02: CAMEL-14805: Use doInit for iniitalizing. Fixed tests
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9af7f53303df7e439b5238dbf4d3f03e9f349f86
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Mar 29 11:06:36 2020 +0200
CAMEL-14805: Use doInit for iniitalizing. Fixed tests
---
.../MetricsMessageHistoryFactory.java | 6 +----
.../MetricsMessageHistoryService.java | 29 ++++++++++++++--------
.../routepolicy/MetricsRegistryService.java | 23 +++++++++--------
.../metrics/routepolicy/MetricsRoutePolicy.java | 7 ------
4 files changed, 33 insertions(+), 32 deletions(-)
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java
index 75076e4..bc28141 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryFactory.java
@@ -183,7 +183,7 @@ public class MetricsMessageHistoryFactory extends ServiceSupport implements Came
}
@Override
- protected void doStart() throws Exception {
+ protected void doInit() throws Exception {
try {
messageHistoryService = camelContext.hasService(MetricsMessageHistoryService.class);
if (messageHistoryService == null) {
@@ -208,8 +208,4 @@ public class MetricsMessageHistoryFactory extends ServiceSupport implements Came
ObjectHelper.notNull(metricsRegistry, "metricsRegistry", this);
}
- @Override
- protected void doStop() throws Exception {
- // noop
- }
}
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
index cfc9a04..e0b81b8 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/messagehistory/MetricsMessageHistoryService.java
@@ -114,7 +114,9 @@ public final class MetricsMessageHistoryService extends ServiceSupport implement
}
@Override
- protected void doStart() throws Exception {
+ protected void doInit() throws Exception {
+ super.doInit();
+
if (metricsRegistry == null) {
Registry camelRegistry = getCamelContext().getRegistry();
metricsRegistry = camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
@@ -124,6 +126,20 @@ public final class MetricsMessageHistoryService extends ServiceSupport implement
}
}
+ // json mapper
+ this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
+ if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
+ // they both use same units so reuse
+ this.secondsMapper = this.mapper;
+ } else {
+ this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
+ }
+ }
+
+ @Override
+ protected void doStart() throws Exception {
+ super.doStart();
+
if (useJmx) {
ManagementAgent agent = getCamelContext().getManagementStrategy().getManagementAgent();
if (agent != null) {
@@ -136,19 +152,12 @@ public final class MetricsMessageHistoryService extends ServiceSupport implement
throw new IllegalStateException("CamelContext has not enabled JMX");
}
}
-
- // json mapper
- this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
- if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
- // they both use same units so reuse
- this.secondsMapper = this.mapper;
- } else {
- this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
- }
}
@Override
protected void doStop() throws Exception {
+ super.doStop();
+
if (reporter != null) {
reporter.stop();
reporter = null;
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java
index c654664..c3000c8 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRegistryService.java
@@ -112,7 +112,7 @@ public final class MetricsRegistryService extends ServiceSupport implements Came
}
@Override
- protected void doStart() throws Exception {
+ protected void doInit() throws Exception {
if (metricsRegistry == null) {
Registry camelRegistry = getCamelContext().getRegistry();
metricsRegistry = camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class);
@@ -122,6 +122,18 @@ public final class MetricsRegistryService extends ServiceSupport implements Came
}
}
+ // json mapper
+ this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
+ if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
+ // they both use same units so reuse
+ this.secondsMapper = this.mapper;
+ } else {
+ this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
+ }
+ }
+
+ @Override
+ protected void doStart() throws Exception {
if (useJmx) {
ManagementAgent agent = getCamelContext().getManagementStrategy().getManagementAgent();
if (agent != null) {
@@ -134,15 +146,6 @@ public final class MetricsRegistryService extends ServiceSupport implements Came
throw new IllegalStateException("CamelContext has not enabled JMX");
}
}
-
- // json mapper
- this.mapper = new ObjectMapper().registerModule(new MetricsModule(getRateUnit(), getDurationUnit(), false));
- if (getRateUnit() == TimeUnit.SECONDS && getDurationUnit() == TimeUnit.SECONDS) {
- // they both use same units so reuse
- this.secondsMapper = this.mapper;
- } else {
- this.secondsMapper = new ObjectMapper().registerModule(new MetricsModule(TimeUnit.SECONDS, TimeUnit.SECONDS, false));
- }
}
@Override
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
index 08e3b03..fd7973b 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
@@ -156,13 +156,6 @@ public class MetricsRoutePolicy extends RoutePolicySupport implements NonManaged
throw RuntimeCamelException.wrapRuntimeCamelException(e);
}
- // ensure registry service is started
- try {
- ServiceHelper.startService(registryService);
- } catch (Exception e) {
- throw RuntimeCamelException.wrapRuntimeCamelException(e);
- }
-
// create statistics holder
// for know we record only all the timings of a complete exchange (responses)
// we have in-flight / total statistics already from camel-core