You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2020/09/01 11:31:07 UTC
[camel] branch master updated (702aabe -> a8c6fbb)
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git.
from 702aabe Sync Properties
new b788422 Add an utility method to IsSingleton to determine if a servi e is a singleton or not
new 67f7d67 Add javadoc and remove lamda usage in utility methods
new a8c6fbb Fix checkstyle violations
The 3 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:
.../main/java/org/apache/camel/IsSingleton.java | 11 ++-
.../camel/impl/engine/AbstractCamelContext.java | 11 +--
.../org/apache/camel/util/function/Suppliers.java | 97 +++++++++++++++++-----
.../camel/util/function/ThrowingBiConsumer.java | 16 ++++
.../camel/util/function/ThrowingBiFunction.java | 18 ++++
.../camel/util/function/ThrowingConsumer.java | 14 ++++
.../camel/util/function/ThrowingFunction.java | 16 ++++
.../apache/camel/util/function/ThrowingHelper.java | 68 ++++++++++-----
.../camel/util/function/ThrowingRunnable.java | 12 +++
.../camel/util/function/ThrowingSupplier.java | 15 ++++
.../util/function/ThrowingToLongFunction.java | 15 ++++
.../camel/util/function/ThrowingTriConsumer.java | 17 ++++
.../apache/camel/util/function/TriConsumer.java | 15 ++++
13 files changed, 276 insertions(+), 49 deletions(-)
[camel] 03/03: Fix checkstyle violations
Posted by lb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit a8c6fbb0f5475e8498b83d9df8a3649d13312de6
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Sep 1 12:22:31 2020 +0200
Fix checkstyle violations
---
.../org/apache/camel/impl/engine/AbstractCamelContext.java | 10 ++++++----
1 file changed, 6 insertions(+), 4 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 aadf5ac..f8a9252 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
@@ -173,6 +173,10 @@ public abstract class AbstractCamelContext extends BaseService
implements ExtendedCamelContext, CatalogCamelContext, Suspendable {
private static final Logger LOG = LoggerFactory.getLogger(AbstractCamelContext.class);
+
+ // start auto assigning route ids using numbering 1000 and upwards
+ int defaultRouteStartupOrder = 1000;
+
private final AtomicInteger endpointKeyCounter = new AtomicInteger();
private final List<EndpointStrategy> endpointStrategies = new ArrayList<>();
private final GlobalEndpointConfiguration globalEndpointConfiguration = new DefaultGlobalEndpointConfiguration();
@@ -196,14 +200,14 @@ public abstract class AbstractCamelContext extends BaseService
= new DefaultAnnotationBasedProcessorFactory();
private final List<RouteStartupOrder> routeStartupOrder = new ArrayList<>();
private final StopWatch stopWatch = new StopWatch(false);
+ private final Map<Class<?>, Object> extensions = new ConcurrentHashMap<>();
+ private final Set<LogListener> logListeners = new LinkedHashSet<>();
private final ThreadLocal<Set<String>> componentsInCreation = new ThreadLocal<Set<String>>() {
@Override
public Set<String> initialValue() {
return new HashSet<>();
}
};
- // start auto assigning route ids using numbering 1000 and upwards
- int defaultRouteStartupOrder = 1000;
private VetoCamelContextStartException vetoed;
private String managementName;
private ClassLoader applicationContextClassLoader;
@@ -211,7 +215,6 @@ public abstract class AbstractCamelContext extends BaseService
private volatile RestConfiguration restConfiguration;
private List<InterceptStrategy> interceptStrategies = new ArrayList<>();
private List<RoutePolicyFactory> routePolicyFactories = new ArrayList<>();
- private Set<LogListener> logListeners = new LinkedHashSet<>();
// special flags to control the first startup which can are special
private volatile boolean firstStartDone;
private volatile boolean doNotStartRoutesOnFirstStart;
@@ -293,7 +296,6 @@ public abstract class AbstractCamelContext extends BaseService
private Date startDate;
private SSLContextParameters sslContextParameters;
- private Map<Class<?>, Object> extensions = new ConcurrentHashMap<>();
/**
* Creates the {@link CamelContext} using {@link org.apache.camel.support.DefaultRegistry} as registry.
[camel] 02/03: Add javadoc and remove lamda usage in utility methods
Posted by lb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 67f7d6799933f1744e7bcfd835893492094590cf
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Sep 1 11:56:30 2020 +0200
Add javadoc and remove lamda usage in utility methods
---
.../org/apache/camel/util/function/Suppliers.java | 97 +++++++++++++++++-----
.../camel/util/function/ThrowingBiConsumer.java | 16 ++++
.../camel/util/function/ThrowingBiFunction.java | 18 ++++
.../camel/util/function/ThrowingConsumer.java | 14 ++++
.../camel/util/function/ThrowingFunction.java | 16 ++++
.../apache/camel/util/function/ThrowingHelper.java | 68 ++++++++++-----
.../camel/util/function/ThrowingRunnable.java | 12 +++
.../camel/util/function/ThrowingSupplier.java | 15 ++++
.../util/function/ThrowingToLongFunction.java | 15 ++++
.../camel/util/function/ThrowingTriConsumer.java | 17 ++++
.../apache/camel/util/function/TriConsumer.java | 15 ++++
11 files changed, 262 insertions(+), 41 deletions(-)
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/Suppliers.java b/core/camel-util/src/main/java/org/apache/camel/util/function/Suppliers.java
index 61c18ab..1c2610d 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/Suppliers.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/Suppliers.java
@@ -27,44 +27,91 @@ public final class Suppliers {
private Suppliers() {
}
+ /**
+ * Returns a supplier which caches the result of the first call to {@link Supplier#get()}and returns that value on
+ * subsequent calls.
+ *
+ * @param supplier the delegate {@link Supplier}.
+ * @param <T> the type of results supplied by this supplier.
+ * @return the result fo the first call to the delegate's {@link Supplier#get()} method.
+ */
public static <T> Supplier<T> memorize(Supplier<T> supplier) {
final AtomicReference<T> valueHolder = new AtomicReference<>();
- return () -> {
- T supplied = valueHolder.get();
- if (supplied == null) {
- synchronized (valueHolder) {
- supplied = valueHolder.get();
- if (supplied == null) {
- supplied = Objects.requireNonNull(supplier.get(), "Supplier should not return null");
- valueHolder.lazySet(supplied);
+ return new Supplier<T>() {
+ @Override
+ public T get() {
+ T supplied = valueHolder.get();
+ if (supplied == null) {
+ synchronized (valueHolder) {
+ supplied = valueHolder.get();
+ if (supplied == null) {
+ supplied = Objects.requireNonNull(supplier.get(), "Supplier should not return null");
+ valueHolder.lazySet(supplied);
+ }
}
}
+ return supplied;
}
- return supplied;
};
}
+ /**
+ * Returns a supplier which caches the result of the first call to {@link Supplier#get()} and returns that value on
+ * subsequent calls.
+ *
+ * @param supplier the delegate {@link Supplier}.
+ * @param consumer a consumer for any exception thrown by the {@link ThrowingSupplier#get()}.
+ * @param <T> the type of results supplied by this supplier.
+ * @return the result fo the first call to the delegate's {@link Supplier#get()} method.
+ */
public static <T> Supplier<T> memorize(ThrowingSupplier<T, ? extends Exception> supplier, Consumer<Exception> consumer) {
final AtomicReference<T> valueHolder = new AtomicReference<>();
- return () -> {
- T supplied = valueHolder.get();
- if (supplied == null) {
- synchronized (valueHolder) {
- supplied = valueHolder.get();
- if (supplied == null) {
- try {
- supplied = Objects.requireNonNull(supplier.get(), "Supplier should not return null");
- valueHolder.lazySet(supplied);
- } catch (Exception e) {
- consumer.accept(e);
+ return new Supplier<T>() {
+ @Override
+ public T get() {
+ T supplied = valueHolder.get();
+ if (supplied == null) {
+ synchronized (valueHolder) {
+ supplied = valueHolder.get();
+ if (supplied == null) {
+ try {
+ supplied = Objects.requireNonNull(supplier.get(), "Supplier should not return null");
+ valueHolder.lazySet(supplied);
+ } catch (Exception e) {
+ consumer.accept(e);
+ }
}
}
}
+ return supplied;
+ }
+ };
+ }
+
+ /**
+ * Returns a supplier that return a constant value.
+ *
+ * @param value the constant value to return.
+ * @param <T> the type of results supplied by this supplier.
+ * @return the supplied {@code value}.
+ */
+ public static <T> Supplier<T> constant(T value) {
+ return new Supplier<T>() {
+ @Override
+ public T get() {
+ return value;
}
- return supplied;
};
}
+ /**
+ * Returns the first non null value provide by the given suppliers.
+ *
+ * @param suppliers a list of supplier.
+ * @param <T> the type of results supplied by this supplier.
+ * @return the optional computed value.
+ */
+ @SafeVarargs
public static <T> Optional<T> firstNotNull(ThrowingSupplier<T, Exception>... suppliers) throws Exception {
T answer = null;
@@ -78,6 +125,14 @@ public final class Suppliers {
return Optional.ofNullable(answer);
}
+ /**
+ * Returns the first value provide by the given suppliers that matches the given predicate.
+ *
+ * @param predicate the predicate used to evaluate the computed values.
+ * @param suppliers a list fo supplier.
+ * @param <T> the type of results supplied by this supplier.
+ * @return the optional matching value.
+ */
public static <T> Optional<T> firstMatching(Predicate<T> predicate, ThrowingSupplier<T, Exception>... suppliers)
throws Exception {
T answer = null;
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingBiConsumer.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingBiConsumer.java
index aca8938..5a956d5 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingBiConsumer.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingBiConsumer.java
@@ -16,7 +16,23 @@
*/
package org.apache.camel.util.function;
+/**
+ * Represents an operation that accepts two input arguments and returns no result and may thrown an exception.
+ *
+ * @param <I1> the type of the first argument to the operation
+ * @param <I2> the type of the second argument to the operation
+ * @param <T> the type of the exception the accept method may throw
+ *
+ * @see java.util.function.BiConsumer
+ */
@FunctionalInterface
public interface ThrowingBiConsumer<I1, I2, T extends Throwable> {
+ /**
+ * Performs this operation on the given arguments, potentially throwing an exception.
+ *
+ * @param i1 the first function argument
+ * @param i2 the first function argument
+ * @throws T the exception that may be thrown
+ */
void accept(I1 i1, I2 i2) throws T;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingBiFunction.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingBiFunction.java
index 937f1e1..e52e711 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingBiFunction.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingBiFunction.java
@@ -16,7 +16,25 @@
*/
package org.apache.camel.util.function;
+/**
+ * Represents a function that accepts two arguments, produces a result and may thrown an exception.
+ *
+ * @param <I1> the type of the first argument to the operation
+ * @param <I2> the type of the second argument to the operation
+ * @param <R> the type of the result of the function
+ * @param <T> the type of the exception the accept method may throw
+ *
+ * @see java.util.function.BiFunction
+ */
@FunctionalInterface
public interface ThrowingBiFunction<I1, I2, R, T extends Throwable> {
+ /**
+ * Applies this function to the given arguments, potentially throwing an exception.
+ *
+ * @param in1 the first function argument
+ * @param in2 the second function argument
+ * @return the function result
+ * @throws T the exception that may be thrown
+ */
R apply(I1 in1, I2 in2) throws T;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingConsumer.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingConsumer.java
index c13434d..a7f36cd 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingConsumer.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingConsumer.java
@@ -16,7 +16,21 @@
*/
package org.apache.camel.util.function;
+/**
+ * Represents an operation that accepts a single input argument and may thrown an exception.
+ *
+ * @param <I> the type of the input to the operation
+ * @param <T> the type of the exception the accept method may throw
+ *
+ * @see java.util.function.Consumer
+ */
@FunctionalInterface
public interface ThrowingConsumer<I, T extends Throwable> {
+ /**
+ * Performs this operation on the given argument, potentially throwing an exception.
+ *
+ * @param in the function argument
+ * @throws T the exception that may be thrown
+ */
void accept(I in) throws T;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingFunction.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingFunction.java
index 53bb9d4..eaf005a 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingFunction.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingFunction.java
@@ -16,7 +16,23 @@
*/
package org.apache.camel.util.function;
+/**
+ * Represents a function that accepts a single arguments, produces a result and may thrown an exception.
+ *
+ * @param <I> the type of the input of the function
+ * @param <R> the type of the result of the function
+ * @param <T> the type of the exception the accept method may throw
+ *
+ * @see java.util.function.Function
+ */
@FunctionalInterface
public interface ThrowingFunction<I, R, T extends Throwable> {
+ /**
+ * Applies this function to the given argument, potentially throwing an exception.
+ *
+ * @param in the function argument
+ * @return the function result
+ * @throws T the exception that may be thrown
+ */
R apply(I in) throws T;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingHelper.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingHelper.java
index 10236ca..4ebb39e 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingHelper.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingHelper.java
@@ -28,43 +28,71 @@ public final class ThrowingHelper {
private ThrowingHelper() {
}
+ /**
+ * Wrap a {@link ThrowingSupplier} to a standard {@link Suppliers} by throwing a {@link RuntimeException} in case of
+ * an exception is thrown by the delegated supplier.
+ */
public static <V, T extends Throwable> Supplier<V> wrapAsSupplier(ThrowingSupplier<V, T> supplier) {
- return () -> {
- try {
- return supplier.get();
- } catch (Throwable t) {
- throw new RuntimeException(t);
+ return new Supplier<V>() {
+ @Override
+ public V get() {
+ try {
+ return supplier.get();
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
}
};
}
+ /**
+ * Wrap a {@link ThrowingConsumer} to a standard {@link Consumer} by throwing a {@link RuntimeException} in case of
+ * an exception is thrown by the delegated consumer.
+ */
public static <I, T extends Throwable> Consumer<I> wrapAsConsumer(ThrowingConsumer<I, T> consumer) {
- return in -> {
- try {
- consumer.accept(in);
- } catch (Throwable t) {
- throw new RuntimeException(t);
+ return new Consumer<I>() {
+ @Override
+ public void accept(I in) {
+ try {
+ consumer.accept(in);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
}
};
}
+ /**
+ * Wrap a {@link ThrowingBiConsumer} to a standard {@link BiConsumer} by throwing a {@link RuntimeException} in case
+ * of an exception is thrown by the delegated consumer.
+ */
public static <I1, I2, T extends Throwable> BiConsumer<I1, I2> wrapAsBiConsumer(ThrowingBiConsumer<I1, I2, T> consumer) {
- return (i1, i2) -> {
- try {
- consumer.accept(i1, i2);
- } catch (Throwable t) {
- throw new RuntimeException(t);
+ return new BiConsumer<I1, I2>() {
+ @Override
+ public void accept(I1 i1, I2 i2) {
+ try {
+ consumer.accept(i1, i2);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
}
};
}
+ /**
+ * Wrap a {@link ThrowingFunction} to a standard {@link Function} by throwing a {@link RuntimeException} in case of
+ * an exception is thrown by the delegated function.
+ */
public static <I, R, T extends Throwable> Function<I, R> wrapAsFunction(ThrowingFunction<I, R, T> function) {
- return in -> {
- try {
- return function.apply(in);
+ return new Function<I, R>() {
+ @Override
+ public R apply(I in) {
+ try {
+ return function.apply(in);
- } catch (Throwable t) {
- throw new RuntimeException(t);
+ } catch (Throwable t) {
+ throw new RuntimeException(t);
+ }
}
};
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingRunnable.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingRunnable.java
index a709fee..43f0d58 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingRunnable.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingRunnable.java
@@ -16,7 +16,19 @@
*/
package org.apache.camel.util.function;
+/**
+ * Represents a {@link Runnable} like interface that may thrown an exception.
+ *
+ * @param <T> the type of the exception the accept method may throw
+ *
+ * @see Runnable
+ */
@FunctionalInterface
public interface ThrowingRunnable<T extends Throwable> {
+ /**
+ * Execute an action, potentially throwing an exception.
+ *
+ * @throws T the exception that may be thrown
+ */
void run() throws T;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingSupplier.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingSupplier.java
index 357b580..2fe54dc 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingSupplier.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingSupplier.java
@@ -16,7 +16,22 @@
*/
package org.apache.camel.util.function;
+import java.util.function.Supplier;
+
+/**
+ * Represents a supplier of results that may thrown an exception.
+ *
+ * @param <T> the type of the exception the accept method may throw.
+ *
+ * @see Supplier
+ */
@FunctionalInterface
public interface ThrowingSupplier<V, T extends Throwable> {
+ /**
+ * Get a result, potentially throwing an exception.
+ *
+ * @return the result
+ * @throws T the exception that may be thrown
+ */
V get() throws T;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingToLongFunction.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingToLongFunction.java
index 6cb9fa0..71f8312 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingToLongFunction.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingToLongFunction.java
@@ -16,7 +16,22 @@
*/
package org.apache.camel.util.function;
+/**
+ * Represents a function that produces a long-valued result and may thrown an exception.
+ *
+ * @param <I> the type of the input of the function
+ * @param <T> the type of the exception the accept method may throw
+ *
+ * @see java.util.function.ToLongFunction
+ */
@FunctionalInterface
public interface ThrowingToLongFunction<I, T extends Throwable> {
+ /**
+ * Applies this function to the given argument, potentially throwing an exception.
+ *
+ * @param in the function argument
+ * @return the function result
+ * @throws T the exception that may be thrown
+ */
long apply(I in) throws T;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingTriConsumer.java b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingTriConsumer.java
index e804ac7..31e3538 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingTriConsumer.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/ThrowingTriConsumer.java
@@ -16,7 +16,24 @@
*/
package org.apache.camel.util.function;
+/**
+ * Represents an operation that accepts three input arguments and returns no result and may thrown an exception.
+ *
+ * @param <I1> the type of the first argument to the operation
+ * @param <I2> the type of the second argument to the operation
+ * @param <I3> the type of the third argument to the operation
+ * @param <T> the type of the exception the accept method may throw
+ */
@FunctionalInterface
public interface ThrowingTriConsumer<I1, I2, I3, T extends Throwable> {
+ /**
+ * Applies this function to the given arguments, potentially throwing an exception.
+ *
+ * @param i1 the first argument
+ * @param i2 the second argument
+ * @param i3 the third argument
+ * @return the function result
+ * @throws T the exception that may be thrown
+ */
void accept(I1 i1, I2 i2, I3 i3) throws T;
}
diff --git a/core/camel-util/src/main/java/org/apache/camel/util/function/TriConsumer.java b/core/camel-util/src/main/java/org/apache/camel/util/function/TriConsumer.java
index 0028ae4..deb9032 100644
--- a/core/camel-util/src/main/java/org/apache/camel/util/function/TriConsumer.java
+++ b/core/camel-util/src/main/java/org/apache/camel/util/function/TriConsumer.java
@@ -16,7 +16,22 @@
*/
package org.apache.camel.util.function;
+/**
+ * Represents an operation that accepts three input arguments and returns no result.
+ *
+ * @param <I1> the type of the first argument to the operation
+ * @param <I2> the type of the second argument to the operation
+ * @param <I3> the type of the third argument to the operation
+ */
@FunctionalInterface
public interface TriConsumer<I1, I2, I3> {
+ /**
+ * Applies this function to the given arguments..
+ *
+ * @param i1 the first argument
+ * @param i2 the second argument
+ * @param i3 the third argument
+ * @return the function result
+ */
void accept(I1 i1, I2 i2, I3 i3);
}
[camel] 01/03: Add an utility method to IsSingleton to determine if
a servi e is a singleton or not
Posted by lb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
commit b7884228652946a28384f867f10761ee1fdfa282
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Tue Sep 1 11:55:27 2020 +0200
Add an utility method to IsSingleton to determine if a servi e is a singleton or not
---
.../src/main/java/org/apache/camel/IsSingleton.java | 11 ++++++++++-
.../org/apache/camel/impl/engine/AbstractCamelContext.java | 13 ++++---------
2 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/core/camel-api/src/main/java/org/apache/camel/IsSingleton.java b/core/camel-api/src/main/java/org/apache/camel/IsSingleton.java
index bdd0a6c..612b9d4 100644
--- a/core/camel-api/src/main/java/org/apache/camel/IsSingleton.java
+++ b/core/camel-api/src/main/java/org/apache/camel/IsSingleton.java
@@ -29,10 +29,19 @@ package org.apache.camel;
public interface IsSingleton {
/**
+ * Test if the given {@code instance} is a singleton or not.
+ *
+ * @param instance the instance ot check
+ * @return true if the given {@code instance} is a singleton
+ */
+ static boolean test(Object instance) {
+ return instance instanceof IsSingleton && ((IsSingleton) instance).isSingleton();
+ }
+
+ /**
* Whether this class supports being singleton or not.
*
* @return <tt>true</tt> to be a single shared instance, <tt>false</tt> to create new instances.
*/
boolean isSingleton();
-
}
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 a5d1ab2..aadf5ac 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
@@ -173,10 +173,6 @@ public abstract class AbstractCamelContext extends BaseService
implements ExtendedCamelContext, CatalogCamelContext, Suspendable {
private static final Logger LOG = LoggerFactory.getLogger(AbstractCamelContext.class);
-
- // start auto assigning route ids using numbering 1000 and upwards
- int defaultRouteStartupOrder = 1000;
-
private final AtomicInteger endpointKeyCounter = new AtomicInteger();
private final List<EndpointStrategy> endpointStrategies = new ArrayList<>();
private final GlobalEndpointConfiguration globalEndpointConfiguration = new DefaultGlobalEndpointConfiguration();
@@ -206,6 +202,8 @@ public abstract class AbstractCamelContext extends BaseService
return new HashSet<>();
}
};
+ // start auto assigning route ids using numbering 1000 and upwards
+ int defaultRouteStartupOrder = 1000;
private VetoCamelContextStartException vetoed;
private String managementName;
private ClassLoader applicationContextClassLoader;
@@ -1734,11 +1732,8 @@ public abstract class AbstractCamelContext extends BaseService
// check if the language is singleton, if so return the shared
// instance
- if (answer instanceof IsSingleton) {
- boolean singleton = ((IsSingleton) answer).isSingleton();
- if (singleton) {
- return answer;
- }
+ if (IsSingleton.test(answer)) {
+ return answer;
}
// language not known or not singleton, then use resolver