You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by gn...@apache.org on 2018/07/26 16:15:37 UTC
[camel] 02/05: [CAMEL-12688] Avoid lamba
This is an automated email from the ASF dual-hosted git repository.
gnodet pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9fc335ffa767df4cf06c5127733518758c2c8fda
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Sat Jun 23 01:19:15 2018 +0200
[CAMEL-12688] Avoid lamba
---
.../org/apache/camel/impl/DefaultCamelContext.java | 33 +++++++++++++++-------
.../apache/camel/impl/DefaultFactoryFinder.java | 29 ++++++++++++-------
2 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index d081cae..8adcc18 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -42,6 +42,7 @@ import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
+import java.util.function.Function;
import java.util.stream.Collectors;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
@@ -461,9 +462,12 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
final AtomicBoolean created = new AtomicBoolean(false);
// atomic operation to get/create a component. Avoid global locks.
- final Component component = components.computeIfAbsent(name, comp -> {
- created.set(true);
- return initComponent(name, autoCreateComponents);
+ final Component component = components.computeIfAbsent(name, new Function<String, Component>() {
+ @Override
+ public Component apply(String comp) {
+ created.set(true);
+ return DefaultCamelContext.this.initComponent(name, autoCreateComponents);
+ }
});
// Start the component after its creation as if it is a component proxy
@@ -3267,7 +3271,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
}
- private void doStartCamel() throws Exception {
+ protected void doStartCamel() throws Exception {
// custom properties may use property placeholders so resolve those early on
if (globalOptions != null && !globalOptions.isEmpty()) {
@@ -3507,13 +3511,22 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
// shutdown await manager to trigger interrupt of blocked threads to attempt to free these threads graceful
shutdownServices(asyncProcessorAwaitManager);
- shutdownServices(getRouteStartupOrder().stream()
- .sorted(Comparator.comparing(RouteStartupOrder::getStartupOrder).reversed())
- .map(DefaultRouteStartupOrder.class::cast)
- .map(DefaultRouteStartupOrder::getRouteService)
- .collect(Collectors.toList()), false);
+ routeStartupOrder.sort(new Comparator<RouteStartupOrder>() {
+ @Override
+ public int compare(RouteStartupOrder o1, RouteStartupOrder o2) {
+ // Reversed order
+ return Integer.compare(o2.getStartupOrder(), o1.getStartupOrder());
+ }
+ });
+ List<RouteService> list = new ArrayList<>();
+ for (RouteStartupOrder startupOrder : routeStartupOrder) {
+ DefaultRouteStartupOrder order = (DefaultRouteStartupOrder) startupOrder;
+ RouteService routeService = order.getRouteService();
+ list.add(routeService);
+ }
+ shutdownServices(list, false);
// do not clear route services or startup listeners as we can start Camel again and get the route back as before
- getRouteStartupOrder().clear();
+ routeStartupOrder.clear();
// but clear any suspend routes
suspendedRouteServices.clear();
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java
index bf87c6e..3ed501e 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultFactoryFinder.java
@@ -25,6 +25,7 @@ import java.util.List;
import java.util.Properties;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import java.util.function.Function;
import org.apache.camel.NoFactoryAvailableException;
import org.apache.camel.spi.ClassResolver;
@@ -79,7 +80,12 @@ public class DefaultFactoryFinder implements FactoryFinder {
final String prefix = propertyPrefix != null ? propertyPrefix : "";
final String classKey = prefix + key;
- return addToClassMap(classKey, () -> newInstance(doFindFactoryProperties(key), prefix));
+ return addToClassMap(classKey, new ClassSupplier() {
+ @Override
+ public Class<?> get() throws ClassNotFoundException, IOException {
+ return DefaultFactoryFinder.this.newInstance(DefaultFactoryFinder.this.doFindFactoryProperties(key), prefix);
+ }
+ });
}
@Override
@@ -160,15 +166,18 @@ public class DefaultFactoryFinder implements FactoryFinder {
*/
protected Class<?> addToClassMap(String key, ClassSupplier mappingFunction) throws ClassNotFoundException, IOException {
try {
- return classMap.computeIfAbsent(key, (String classKey) -> {
- try {
- return mappingFunction.get();
- } catch (ClassNotFoundException e) {
- throw new WrappedRuntimeException(e);
- } catch (NoFactoryAvailableException e) {
- throw new WrappedRuntimeException(e);
- } catch (IOException e) {
- throw new WrappedRuntimeException(e);
+ return classMap.computeIfAbsent(key, new Function<String, Class<?>>() {
+ @Override
+ public Class<?> apply(String classKey) {
+ try {
+ return mappingFunction.get();
+ } catch (ClassNotFoundException e) {
+ throw new WrappedRuntimeException(e);
+ } catch (NoFactoryAvailableException e) {
+ throw new WrappedRuntimeException(e);
+ } catch (IOException e) {
+ throw new WrappedRuntimeException(e);
+ }
}
});
} catch (WrappedRuntimeException e) {