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/05/28 11:16:29 UTC
[camel] branch master updated (b9adf54 -> 522883f)
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 b9adf54 CAMEL-15117: camel-salesforce - prevent NPE during stop (#3867)
new dab0775 CAMEL-15126: camel-health - Remove unusued api from spi
new bc2c52b CAMEL-15126: camel-health - polished and fix TODO with route controller not an extension
new 19a0580 CAMEL-15126: camel-health - discover health check at doBuild phase
new 522883f camel-core - Move inlined class into its own class.
The 4 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:
components/camel-spring/pom.xml | 4 ++
.../apache/camel/health/HealthCheckService.java | 18 +-----
.../camel/impl/engine/AbstractCamelContext.java | 53 +++-------------
.../engine/OnCamelContextLifecycleStrategy.java | 70 ++++++++++++++++++++++
.../org/apache/camel/impl/DefaultCamelContext.java | 6 --
.../camel/impl/MultipleLifecycleStrategyTest.java | 4 +-
.../impl/health/DefaultHealthCheckService.java | 15 ++++-
.../org/apache/camel/main/BaseMainSupport.java | 2 +-
.../management/ManagedNonManagedServiceTest.java | 2 +-
...edProducerRouteAddRemoveRegisterAlwaysTest.java | 2 +-
.../management/ManagedRouteAddRemoveTest.java | 2 +-
11 files changed, 103 insertions(+), 75 deletions(-)
create mode 100644 core/camel-base/src/main/java/org/apache/camel/impl/engine/OnCamelContextLifecycleStrategy.java
[camel] 01/04: CAMEL-15126: camel-health - Remove unusued api from
spi
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 dab077597d9b29218360ef8dba8aad34060f72ac
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu May 28 09:21:50 2020 +0200
CAMEL-15126: camel-health - Remove unusued api from spi
---
.../org/apache/camel/health/HealthCheckService.java | 18 +-----------------
.../camel/impl/health/DefaultHealthCheckService.java | 15 +++++++++++++--
2 files changed, 14 insertions(+), 19 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckService.java b/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckService.java
index 5a2acd3..706caa9 100644
--- a/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckService.java
+++ b/core/camel-api/src/main/java/org/apache/camel/health/HealthCheckService.java
@@ -20,33 +20,17 @@ import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import java.util.Optional;
-import java.util.function.BiConsumer;
import org.apache.camel.CamelContextAware;
-import org.apache.camel.Service;
import org.apache.camel.StaticService;
/**
- * An health check service that invokes the checks registered on the {@link HealthCheckRegistry}
+ * An health check service that invokes the {@link HealthCheck} registered on the {@link HealthCheckRegistry}
* according to a schedule.
*/
public interface HealthCheckService extends StaticService, CamelContextAware {
/**
- * Add a listener to invoke when the state of a check change.
- *
- * @param consumer the event listener.
- */
- void addStateChangeListener(BiConsumer<HealthCheck.State, HealthCheck> consumer);
-
- /**
- * Remove the state change listener.
- *
- * @param consumer the event listener to remove.
- */
- void removeStateChangeListener(BiConsumer<HealthCheck.State, HealthCheck> consumer);
-
- /**
* Sets the options to be used when invoking the check identified by the
* given id.
*
diff --git a/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java b/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java
index 046ca4c..e2d3d8e 100644
--- a/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java
+++ b/core/camel-health/src/main/java/org/apache/camel/impl/health/DefaultHealthCheckService.java
@@ -44,6 +44,9 @@ import org.apache.camel.util.concurrent.LockHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+/**
+ * Default {@link HealthCheckService}
+ */
public final class DefaultHealthCheckService extends ServiceSupport implements HealthCheckService {
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultHealthCheckService.class);
@@ -102,7 +105,11 @@ public final class DefaultHealthCheckService extends ServiceSupport implements H
this.checkInterval = checkInterval;
}
- @Override
+ /**
+ * Add a listener to invoke when the state of a check change.
+ *
+ * @param consumer the event listener.
+ */
public void addStateChangeListener(BiConsumer<HealthCheck.State, HealthCheck> consumer) {
LockHelper.doWithWriteLock(
lock,
@@ -110,7 +117,11 @@ public final class DefaultHealthCheckService extends ServiceSupport implements H
);
}
- @Override
+ /**
+ * Remove the state change listener.
+ *
+ * @param consumer the event listener to remove.
+ */
public void removeStateChangeListener(BiConsumer<HealthCheck.State, HealthCheck> consumer) {
LockHelper.doWithWriteLock(
lock,
[camel] 04/04: camel-core - Move inlined class into its own class.
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 522883f7d54893a26a440ac6eed75158fee335af
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu May 28 13:13:32 2020 +0200
camel-core - Move inlined class into its own class.
---
.../camel/impl/engine/AbstractCamelContext.java | 42 +------------
.../engine/OnCamelContextLifecycleStrategy.java | 70 ++++++++++++++++++++++
2 files changed, 72 insertions(+), 40 deletions(-)
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 470cd66..0972e19 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -336,46 +336,8 @@ public abstract class AbstractCamelContext extends BaseService
// add the defer service startup listener
this.startupListeners.add(deferStartupListener);
- // add a default LifecycleStrategy that discover strategies on the registry
- // and invoke them
- // TODO: Move this into its own class to reduce number of code lines here
- this.lifecycleStrategies.add(new LifecycleStrategySupport() {
- @Override
- public void onContextInitialized(CamelContext context) throws VetoCamelContextStartException {
- for (OnCamelContextInitialized handler : context.getRegistry().findByType(OnCamelContextInitialized.class)) {
- // RoutesBuilder should register them-self to the camel context
- // to avoid invoking them multiple times if routes are discovered
- // from the registry (i.e. camel-main)
- if (!(handler instanceof RoutesBuilder)) {
- handler.onContextInitialized(context);
- }
- }
- }
-
- @Override
- public void onContextStart(CamelContext context) throws VetoCamelContextStartException {
- for (OnCamelContextStart handler : context.getRegistry().findByType(OnCamelContextStart.class)) {
- // RoutesBuilder should register them-self to the camel context
- // to avoid invoking them multiple times if routes are discovered
- // from the registry (i.e. camel-main)
- if (!(handler instanceof RoutesBuilder)) {
- handler.onContextStart(context);
- }
- }
- }
-
- @Override
- public void onContextStop(CamelContext context) {
- for (OnCamelContextStop handler : context.getRegistry().findByType(OnCamelContextStop.class)) {
- // RoutesBuilder should register them-self to the camel context
- // to avoid invoking them multiple times if routes are discovered
- // from the registry (i.e. camel-main)
- if (!(handler instanceof RoutesBuilder)) {
- handler.onContextStop(context);
- }
- }
- }
- });
+ // add a default LifecycleStrategy that discover strategies on the registry and invoke them
+ this.lifecycleStrategies.add(new OnCamelContextLifecycleStrategy());
if (build) {
try {
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/OnCamelContextLifecycleStrategy.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/OnCamelContextLifecycleStrategy.java
new file mode 100644
index 0000000..e420fb1
--- /dev/null
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/OnCamelContextLifecycleStrategy.java
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.impl.engine;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.VetoCamelContextStartException;
+import org.apache.camel.spi.LifecycleStrategy;
+import org.apache.camel.spi.OnCamelContextInitialized;
+import org.apache.camel.spi.OnCamelContextStart;
+import org.apache.camel.spi.OnCamelContextStop;
+import org.apache.camel.support.LifecycleStrategySupport;
+
+/**
+ * {@link LifecycleStrategy} for invoking callbacks {@link OnCamelContextInitialized}, {@link OnCamelContextStart}, and {@link OnCamelContextStop}
+ * which has been registered in the Camel {@link org.apache.camel.spi.Registry}.
+ */
+class OnCamelContextLifecycleStrategy extends LifecycleStrategySupport {
+
+ @Override
+ public void onContextInitialized(CamelContext context) throws VetoCamelContextStartException {
+ for (OnCamelContextInitialized handler : context.getRegistry().findByType(OnCamelContextInitialized.class)) {
+ // RoutesBuilder should register them-self to the camel context
+ // to avoid invoking them multiple times if routes are discovered
+ // from the registry (i.e. camel-main)
+ if (!(handler instanceof RoutesBuilder)) {
+ handler.onContextInitialized(context);
+ }
+ }
+ }
+
+ @Override
+ public void onContextStart(CamelContext context) throws VetoCamelContextStartException {
+ for (OnCamelContextStart handler : context.getRegistry().findByType(OnCamelContextStart.class)) {
+ // RoutesBuilder should register them-self to the camel context
+ // to avoid invoking them multiple times if routes are discovered
+ // from the registry (i.e. camel-main)
+ if (!(handler instanceof RoutesBuilder)) {
+ handler.onContextStart(context);
+ }
+ }
+ }
+
+ @Override
+ public void onContextStop(CamelContext context) {
+ for (OnCamelContextStop handler : context.getRegistry().findByType(OnCamelContextStop.class)) {
+ // RoutesBuilder should register them-self to the camel context
+ // to avoid invoking them multiple times if routes are discovered
+ // from the registry (i.e. camel-main)
+ if (!(handler instanceof RoutesBuilder)) {
+ handler.onContextStop(context);
+ }
+ }
+ }
+
+}
[camel] 02/04: CAMEL-15126: camel-health - polished and fix TODO
with route controller not an extension
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 bc2c52b9f112fe47fa59718ff6f704387d2c4f1d
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu May 28 09:54:22 2020 +0200
CAMEL-15126: camel-health - polished and fix TODO with route controller not an extension
---
.../java/org/apache/camel/impl/engine/AbstractCamelContext.java | 8 ++++++--
.../src/main/java/org/apache/camel/impl/DefaultCamelContext.java | 6 ------
.../src/main/java/org/apache/camel/main/BaseMainSupport.java | 2 +-
3 files changed, 7 insertions(+), 9 deletions(-)
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index 4e3a469..a772ac7 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -376,9 +376,8 @@ public abstract class AbstractCamelContext extends BaseService
}
});
+ // TODO:
setDefaultExtension(HealthCheckRegistry.class, this::createHealthCheckRegistry);
- // TODO: is route controller needed as extension?
- setDefaultExtension(RouteController.class, this::createRouteController);
if (build) {
try {
@@ -3232,6 +3231,11 @@ public abstract class AbstractCamelContext extends BaseService
}
protected void doStartEagerServices() {
+ // initialize health-check registry
+ HealthCheckRegistry hcr = getExtension(HealthCheckRegistry.class);
+ if (hcr == null) {
+ setExtension(HealthCheckRegistry.class, createHealthCheckRegistry());
+ }
getFactoryFinderResolver();
getDefaultFactoryFinder();
getComponentResolver();
diff --git a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index a53f472..67e34f7 100644
--- a/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/core/camel-core-engine/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -298,12 +298,6 @@ public class DefaultCamelContext extends SimpleCamelContext implements ModelCame
}
@Override
- protected void doStartEagerServices() {
- getExtension(HealthCheckRegistry.class);
- super.doStartEagerServices();
- }
-
- @Override
protected void bindDataFormats() throws Exception {
// eager lookup data formats and bind to registry so the dataformats can
// be looked up and used
diff --git a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index ef615c3..5bde1e9 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -403,7 +403,7 @@ public abstract class BaseMainSupport extends BaseService {
if (mainConfigurationProperties.getPackageScanRouteBuilders() != null) {
String[] pkgs = mainConfigurationProperties.getPackageScanRouteBuilders().split(",");
- Set<Class<?>> set = camelContext.getExtension(ExtendedCamelContext.class).getPackageScanClassResolver().findImplementations(RoutesBuilder.class, pkgs);
+ Set<Class<?>> set = camelContext.adapt(ExtendedCamelContext.class).getPackageScanClassResolver().findImplementations(RoutesBuilder.class, pkgs);
for (Class<?> routeClazz : set) {
Object builder = camelContext.getInjector().newInstance(routeClazz);
if (builder instanceof RoutesBuilder) {
[camel] 03/04: CAMEL-15126: camel-health - discover health check at
doBuild phase
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 19a0580fc19512373ab2acc1817a3f5b09877695
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Thu May 28 13:08:13 2020 +0200
CAMEL-15126: camel-health - discover health check at doBuild phase
---
components/camel-spring/pom.xml | 4 ++++
.../apache/camel/impl/engine/AbstractCamelContext.java | 17 ++++++++---------
.../camel/impl/MultipleLifecycleStrategyTest.java | 4 ++--
.../camel/management/ManagedNonManagedServiceTest.java | 2 +-
...ManagedProducerRouteAddRemoveRegisterAlwaysTest.java | 2 +-
.../camel/management/ManagedRouteAddRemoveTest.java | 2 +-
6 files changed, 17 insertions(+), 14 deletions(-)
diff --git a/components/camel-spring/pom.xml b/components/camel-spring/pom.xml
index de6b5d7..954d621 100644
--- a/components/camel-spring/pom.xml
+++ b/components/camel-spring/pom.xml
@@ -58,6 +58,10 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
+ <artifactId>camel-health</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
<artifactId>camel-main</artifactId>
</dependency>
<dependency>
diff --git a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
index a772ac7..470cd66 100644
--- a/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
+++ b/core/camel-base/src/main/java/org/apache/camel/impl/engine/AbstractCamelContext.java
@@ -338,6 +338,7 @@ public abstract class AbstractCamelContext extends BaseService
// add a default LifecycleStrategy that discover strategies on the registry
// and invoke them
+ // TODO: Move this into its own class to reduce number of code lines here
this.lifecycleStrategies.add(new LifecycleStrategySupport() {
@Override
public void onContextInitialized(CamelContext context) throws VetoCamelContextStartException {
@@ -376,9 +377,6 @@ public abstract class AbstractCamelContext extends BaseService
}
});
- // TODO:
- setDefaultExtension(HealthCheckRegistry.class, this::createHealthCheckRegistry);
-
if (build) {
try {
build();
@@ -2534,6 +2532,13 @@ public abstract class AbstractCamelContext extends BaseService
// notifiers using the management strategy before the CamelContext has been started
setupManagement(null);
+ // setup health-check registry as its needed this early phase for 3rd party to register custom repositories
+ HealthCheckRegistry hcr = getExtension(HealthCheckRegistry.class);
+ if (hcr == null) {
+ // install health-check registry if discovered from classpath
+ setExtension(HealthCheckRegistry.class, createHealthCheckRegistry());
+ }
+
// Call all registered trackers with this context
// Note, this may use a partially constructed object
CamelContextTracker.notifyContextCreated(this);
@@ -2542,7 +2547,6 @@ public abstract class AbstractCamelContext extends BaseService
if (eagerCreateTypeConverter()) {
getOrCreateTypeConverter();
}
-
}
@Override
@@ -3231,11 +3235,6 @@ public abstract class AbstractCamelContext extends BaseService
}
protected void doStartEagerServices() {
- // initialize health-check registry
- HealthCheckRegistry hcr = getExtension(HealthCheckRegistry.class);
- if (hcr == null) {
- setExtension(HealthCheckRegistry.class, createHealthCheckRegistry());
- }
getFactoryFinderResolver();
getDefaultFactoryFinder();
getComponentResolver();
diff --git a/core/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java b/core/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
index bdb5fa1..d07b73c 100644
--- a/core/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
+++ b/core/camel-core/src/test/java/org/apache/camel/impl/MultipleLifecycleStrategyTest.java
@@ -49,9 +49,9 @@ public class MultipleLifecycleStrategyTest extends TestSupport {
context.stop();
List<String> expectedEvents = Arrays.asList(
- "onServiceAdd", "onServiceAdd",
"onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd",
- "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd",
+ "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd", "onServiceAdd",
+ "onServiceAdd",
"onContextStart",
"onComponentAdd", "onEndpointAdd", "onComponentRemove", "onContextStop");
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java
index e9d545e..3642872 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedNonManagedServiceTest.java
@@ -29,7 +29,7 @@ import org.junit.Test;
public class ManagedNonManagedServiceTest extends ManagementTestSupport {
- private static final int SERVICES = 10;
+ private static final int SERVICES = 11;
@Test
public void testService() throws Exception {
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
index ccbb65a..ac22496 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedProducerRouteAddRemoveRegisterAlwaysTest.java
@@ -28,7 +28,7 @@ import org.junit.Test;
public class ManagedProducerRouteAddRemoveRegisterAlwaysTest extends ManagementTestSupport {
- private static final int SERVICES = 10;
+ private static final int SERVICES = 11;
@Override
protected CamelContext createCamelContext() throws Exception {
diff --git a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
index 702ff39..fff6e2d 100644
--- a/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
+++ b/core/camel-management/src/test/java/org/apache/camel/management/ManagedRouteAddRemoveTest.java
@@ -33,7 +33,7 @@ import org.junit.Test;
*/
public class ManagedRouteAddRemoveTest extends ManagementTestSupport {
- private static final int SERVICES = 10;
+ private static final int SERVICES = 11;
@Override
protected RouteBuilder createRouteBuilder() throws Exception {