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/01/03 11:20:34 UTC

[camel] 01/06: CAMEL-14535: Eager init LRUCacheFactory

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 59bb14f2cee18cf167bd432a53120a3c45de678a
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Jan 3 11:58:19 2020 +0100

    CAMEL-14535: Eager init LRUCacheFactory
---
 .../camel/impl/engine/AbstractCamelContext.java    |  4 ++++
 .../org/apache/camel/support/LRUCacheFactory.java  | 22 +++++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)

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 eddaf50..4c73eca 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
@@ -141,6 +141,7 @@ import org.apache.camel.spi.ValidatorRegistry;
 import org.apache.camel.support.CamelContextHelper;
 import org.apache.camel.support.EndpointHelper;
 import org.apache.camel.support.EventHelper;
+import org.apache.camel.support.LRUCacheFactory;
 import org.apache.camel.support.OrderedComparator;
 import org.apache.camel.support.ProcessorEndpoint;
 import org.apache.camel.support.jsse.SSLContextParameters;
@@ -323,6 +324,9 @@ public abstract class AbstractCamelContext extends ServiceSupport implements Ext
 
     @Override
     public void doInit() throws Exception {
+        // initialize LRUCacheFactory as eager as possible, to let it warm up concurrently while Camel is startup up
+        LRUCacheFactory.init();
+
         // setup management first since end users may use it to add event
         // notifiers using the management strategy before the CamelContext has been started
         setupManagement(null);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/LRUCacheFactory.java b/core/camel-support/src/main/java/org/apache/camel/support/LRUCacheFactory.java
index 048576a8..d1a32ee 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/LRUCacheFactory.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/LRUCacheFactory.java
@@ -33,7 +33,27 @@ public abstract class LRUCacheFactory {
     private static final Logger LOGGER = LoggerFactory.getLogger(LRUCacheFactory.class);
 
     private static volatile LRUCacheFactory instance;
-    
+
+    /**
+     * Initializes and creates the cache factory if not explicit set.
+     */
+    public static void init() {
+        if (instance == null) {
+            instance = createLRUCacheFactory();
+        }
+    }
+
+    /**
+     * Use this to set a specific LRUCacheFactory instance, such as before starting Camel, that
+     * then avoids doing auto discovery of the cache factory via classpath.
+     */
+    public static void setLRUCacheFactory(LRUCacheFactory cacheFactory) {
+        instance = cacheFactory;
+    }
+
+    /**
+     * Gets (and creates if needed) the LRUCacheFactory to use.
+     */
     public static LRUCacheFactory getInstance() {
         if (instance == null) {
             synchronized (LRUCacheFactory.class) {