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:41 UTC
[camel] branch master updated (5ee7c56 -> dcf2091)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.
from 5ee7c56 CAMEL-14805: Use doInit for iniitalizing. Fixed tests
new 9af7f53 CAMEL-14805: Use doInit for iniitalizing. Fixed tests
new dcf2091 CAMEL-14805: Use doInit for iniitalizing. Fixed tests
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../camel/component/metrics/MetricsComponent.java | 39 +++++++++++++---------
.../MetricsMessageHistoryFactory.java | 6 +---
.../MetricsMessageHistoryService.java | 29 ++++++++++------
.../routepolicy/MetricsRegistryService.java | 23 +++++++------
.../metrics/routepolicy/MetricsRoutePolicy.java | 7 ----
.../component/metrics/MetricsComponentTest.java | 15 ++++++---
6 files changed, 67 insertions(+), 52 deletions(-)
[camel] 01/02: CAMEL-14805: Use doInit for iniitalizing. Fixed tests
Posted by da...@apache.org.
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
[camel] 02/02: CAMEL-14805: Use doInit for iniitalizing. Fixed tests
Posted by da...@apache.org.
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 dcf209178819d236125b24d4134e991d2c8bcdf8
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Sun Mar 29 11:15:27 2020 +0200
CAMEL-14805: Use doInit for iniitalizing. Fixed tests
---
.../camel/component/metrics/MetricsComponent.java | 39 +++++++++++++---------
.../component/metrics/MetricsComponentTest.java | 15 ++++++---
2 files changed, 34 insertions(+), 20 deletions(-)
diff --git a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
index 614ddec..4adbd6a 100644
--- a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
+++ b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/MetricsComponent.java
@@ -28,6 +28,7 @@ import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.Registry;
import org.apache.camel.spi.annotations.Component;
import org.apache.camel.support.DefaultComponent;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -52,10 +53,6 @@ public class MetricsComponent extends DefaultComponent {
@Override
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
- if (metricRegistry == null) {
- Registry camelRegistry = getCamelContext().getRegistry();
- metricRegistry = getOrCreateMetricRegistry(camelRegistry, METRIC_REGISTRY_NAME);
- }
String metricsName = getMetricsName(remaining);
MetricsType metricsType = getMetricsType(remaining);
@@ -65,6 +62,17 @@ public class MetricsComponent extends DefaultComponent {
return endpoint;
}
+ public MetricRegistry getMetricRegistry() {
+ return metricRegistry;
+ }
+
+ /**
+ * To use a custom configured MetricRegistry.
+ */
+ public void setMetricRegistry(MetricRegistry metricRegistry) {
+ this.metricRegistry = metricRegistry;
+ }
+
String getMetricsName(String remaining) {
String name = StringHelper.after(remaining, ":");
return name == null ? remaining : name;
@@ -84,7 +92,7 @@ public class MetricsComponent extends DefaultComponent {
return type;
}
- MetricRegistry getOrCreateMetricRegistry(Registry camelRegistry, String registryName) {
+ static MetricRegistry getOrCreateMetricRegistry(Registry camelRegistry, String registryName) {
LOG.debug("Looking up MetricRegistry from Camel Registry for name \"{}\"", registryName);
MetricRegistry result = getMetricRegistryFromCamelRegistry(camelRegistry, registryName);
if (result == null) {
@@ -95,7 +103,7 @@ public class MetricsComponent extends DefaultComponent {
return result;
}
- MetricRegistry getMetricRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
+ static MetricRegistry getMetricRegistryFromCamelRegistry(Registry camelRegistry, String registryName) {
MetricRegistry registry = camelRegistry.lookupByNameAndType(registryName, MetricRegistry.class);
if (registry != null) {
return registry;
@@ -108,7 +116,7 @@ public class MetricsComponent extends DefaultComponent {
return null;
}
- MetricRegistry createMetricRegistry() {
+ static MetricRegistry createMetricRegistry() {
MetricRegistry registry = new MetricRegistry();
final Slf4jReporter reporter = Slf4jReporter.forRegistry(registry)
.outputTo(LOG)
@@ -120,14 +128,15 @@ public class MetricsComponent extends DefaultComponent {
return registry;
}
- public MetricRegistry getMetricRegistry() {
- return metricRegistry;
- }
+ @Override
+ protected void doInit() throws Exception {
+ super.doInit();
- /**
- * To use a custom configured MetricRegistry.
- */
- public void setMetricRegistry(MetricRegistry metricRegistry) {
- this.metricRegistry = metricRegistry;
+ if (metricRegistry == null) {
+ Registry camelRegistry = getCamelContext().getRegistry();
+ metricRegistry = getOrCreateMetricRegistry(camelRegistry, METRIC_REGISTRY_NAME);
+ }
+
+ ObjectHelper.notNull(metricRegistry, "MetricsRegistry", this);
}
}
diff --git a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentTest.java b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentTest.java
index 0489536..12969dc 100644
--- a/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentTest.java
+++ b/components/camel-metrics/src/test/java/org/apache/camel/component/metrics/MetricsComponentTest.java
@@ -75,10 +75,12 @@ public class MetricsComponentTest {
when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
when(camelContext.adapt(ExtendedCamelContext.class)).thenReturn(camelContext);
when(camelContext.getBeanIntrospection()).thenReturn(new DefaultBeanIntrospection());
+ when(camelContext.getConfigurerResolver()).thenReturn((name, context) -> null);
Map<String, Object> params = new HashMap<>();
Long value = System.currentTimeMillis();
params.put("mark", value);
+ component.init();
Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
assertThat(result, is(notNullValue()));
assertThat(result, is(instanceOf(MetricsEndpoint.class)));
@@ -100,9 +102,12 @@ public class MetricsComponentTest {
when(camelRegistry.lookupByNameAndType(MetricsComponent.METRIC_REGISTRY_NAME, MetricRegistry.class)).thenReturn(metricRegistry);
when(camelContext.adapt(ExtendedCamelContext.class)).thenReturn(camelContext);
when(camelContext.getBeanIntrospection()).thenReturn(new DefaultBeanIntrospection());
+ when(camelContext.getConfigurerResolver()).thenReturn((name, context) -> null);
+
Map<String, Object> params = new HashMap<>();
Long value = System.currentTimeMillis();
params.put("mark", value);
+ component.init();
Endpoint result = component.createEndpoint("metrics:meter:long.meter", "meter:long.meter", params);
assertThat(result, is(notNullValue()));
assertThat(result, is(instanceOf(MetricsEndpoint.class)));
@@ -194,7 +199,7 @@ public class MetricsComponentTest {
@Test
public void testGetOrCreateMetricRegistryFoundInCamelRegistry() throws Exception {
when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
- MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
+ MetricRegistry result = MetricsComponent.getOrCreateMetricRegistry(camelRegistry, "name");
assertThat(result, is(metricRegistry));
inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
inOrder.verifyNoMoreInteractions();
@@ -204,7 +209,7 @@ public class MetricsComponentTest {
public void testGetOrCreateMetricRegistryFoundInCamelRegistryByType() throws Exception {
when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(null);
when(camelRegistry.findByType(MetricRegistry.class)).thenReturn(Collections.singleton(metricRegistry));
- MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
+ MetricRegistry result = MetricsComponent.getOrCreateMetricRegistry(camelRegistry, "name");
assertThat(result, is(metricRegistry));
inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
inOrder.verify(camelRegistry, times(1)).findByType(MetricRegistry.class);
@@ -215,7 +220,7 @@ public class MetricsComponentTest {
public void testGetOrCreateMetricRegistryNotFoundInCamelRegistry() throws Exception {
when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(null);
when(camelRegistry.findByType(MetricRegistry.class)).thenReturn(Collections.<MetricRegistry>emptySet());
- MetricRegistry result = component.getOrCreateMetricRegistry(camelRegistry, "name");
+ MetricRegistry result = MetricsComponent.getOrCreateMetricRegistry(camelRegistry, "name");
assertThat(result, is(notNullValue()));
assertThat(result, is(not(metricRegistry)));
inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
@@ -226,7 +231,7 @@ public class MetricsComponentTest {
@Test
public void testGetMetricRegistryFromCamelRegistry() throws Exception {
when(camelRegistry.lookupByNameAndType("name", MetricRegistry.class)).thenReturn(metricRegistry);
- MetricRegistry result = component.getMetricRegistryFromCamelRegistry(camelRegistry, "name");
+ MetricRegistry result = MetricsComponent.getMetricRegistryFromCamelRegistry(camelRegistry, "name");
assertThat(result, is(metricRegistry));
inOrder.verify(camelRegistry, times(1)).lookupByNameAndType("name", MetricRegistry.class);
inOrder.verifyNoMoreInteractions();
@@ -234,7 +239,7 @@ public class MetricsComponentTest {
@Test
public void testCreateMetricRegistry() throws Exception {
- MetricRegistry registry = component.createMetricRegistry();
+ MetricRegistry registry = MetricsComponent.createMetricRegistry();
assertThat(registry, is(notNullValue()));
}
}