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:08 UTC

[camel] 01/03: Add an utility method to IsSingleton to determine if a servi e is a singleton or not

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