This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch camel-3.18.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit b6c3aeb7f710dca85487a219bfd18d9615029a27 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Aug 31 15:25:02 2022 +0200 CAMEL-18444: camel-caffeine - Reuse cache for endpoints with the same cache name. Better lable and docs for options. Do not set initial size/max size as 10000 as that is a lot of memory waste. Leave it as default. --- .../cache/CaffeineCacheComponentConfigurer.java | 8 +-- .../cache/CaffeineCacheEndpointConfigurer.java | 8 +-- .../load/CaffeineLoadCacheComponentConfigurer.java | 8 +-- .../load/CaffeineLoadCacheEndpointConfigurer.java | 8 +-- .../component/caffeine/cache/caffeine-cache.json | 50 +++++++++--------- .../caffeine/load/caffeine-loadcache.json | 48 ++++++++--------- .../component/caffeine/CaffeineConfiguration.java | 61 ++++++++++++++-------- .../camel/component/caffeine/CaffeineHelper.java | 53 +++++++++++++++++++ .../caffeine/cache/CaffeineCacheComponent.java | 28 +++++++--- .../caffeine/cache/CaffeineCacheEndpoint.java | 43 ++++----------- .../caffeine/load/CaffeineLoadCacheComponent.java | 22 ++++---- .../caffeine/load/CaffeineLoadCacheEndpoint.java | 20 ++++--- .../cache/CaffeineCacheProducerCacheNameTest.java | 48 +++++++++++++++++ 13 files changed, 257 insertions(+), 148 deletions(-) diff --git a/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/cache/CaffeineCacheComponentConfigurer.java b/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/cache/CaffeineCacheComponentConfigurer.java index 8b977d9b9e2..0cd5267a378 100644 --- a/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/cache/CaffeineCacheComponentConfigurer.java +++ b/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/cache/CaffeineCacheComponentConfigurer.java @@ -43,14 +43,14 @@ public class CaffeineCacheComponentConfigurer extends PropertyConfigurerSupport case "expireafterwritetime": case "expireAfterWriteTime": getOrCreateConfiguration(target).setExpireAfterWriteTime(property(camelContext, int.class, value)); return true; case "initialcapacity": - case "initialCapacity": getOrCreateConfiguration(target).setInitialCapacity(property(camelContext, int.class, value)); return true; + case "initialCapacity": getOrCreateConfiguration(target).setInitialCapacity(property(camelContext, java.lang.Integer.class, value)); return true; case "key": getOrCreateConfiguration(target).setKey(property(camelContext, java.lang.Object.class, value)); return true; case "keytype": case "keyType": getOrCreateConfiguration(target).setKeyType(property(camelContext, java.lang.String.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; case "maximumsize": - case "maximumSize": getOrCreateConfiguration(target).setMaximumSize(property(camelContext, int.class, value)); return true; + case "maximumSize": getOrCreateConfiguration(target).setMaximumSize(property(camelContext, java.lang.Integer.class, value)); return true; case "removallistener": case "removalListener": getOrCreateConfiguration(target).setRemovalListener(property(camelContext, com.github.benmanes.caffeine.cache.RemovalListener.class, value)); return true; case "statscounter": @@ -81,14 +81,14 @@ public class CaffeineCacheComponentConfigurer extends PropertyConfigurerSupport case "expireafterwritetime": case "expireAfterWriteTime": return int.class; case "initialcapacity": - case "initialCapacity": return int.class; + case "initialCapacity": return java.lang.Integer.class; case "key": return java.lang.Object.class; case "keytype": case "keyType": return java.lang.String.class; case "lazystartproducer": case "lazyStartProducer": return boolean.class; case "maximumsize": - case "maximumSize": return int.class; + case "maximumSize": return java.lang.Integer.class; case "removallistener": case "removalListener": return com.github.benmanes.caffeine.cache.RemovalListener.class; case "statscounter": diff --git a/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpointConfigurer.java b/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpointConfigurer.java index 3545c8ec630..d902545ccc8 100644 --- a/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpointConfigurer.java +++ b/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpointConfigurer.java @@ -33,14 +33,14 @@ public class CaffeineCacheEndpointConfigurer extends PropertyConfigurerSupport i case "expireafterwritetime": case "expireAfterWriteTime": target.getConfiguration().setExpireAfterWriteTime(property(camelContext, int.class, value)); return true; case "initialcapacity": - case "initialCapacity": target.getConfiguration().setInitialCapacity(property(camelContext, int.class, value)); return true; + case "initialCapacity": target.getConfiguration().setInitialCapacity(property(camelContext, java.lang.Integer.class, value)); return true; case "key": target.getConfiguration().setKey(property(camelContext, java.lang.Object.class, value)); return true; case "keytype": case "keyType": target.getConfiguration().setKeyType(property(camelContext, java.lang.String.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; case "maximumsize": - case "maximumSize": target.getConfiguration().setMaximumSize(property(camelContext, int.class, value)); return true; + case "maximumSize": target.getConfiguration().setMaximumSize(property(camelContext, java.lang.Integer.class, value)); return true; case "removallistener": case "removalListener": target.getConfiguration().setRemovalListener(property(camelContext, com.github.benmanes.caffeine.cache.RemovalListener.class, value)); return true; case "statscounter": @@ -68,14 +68,14 @@ public class CaffeineCacheEndpointConfigurer extends PropertyConfigurerSupport i case "expireafterwritetime": case "expireAfterWriteTime": return int.class; case "initialcapacity": - case "initialCapacity": return int.class; + case "initialCapacity": return java.lang.Integer.class; case "key": return java.lang.Object.class; case "keytype": case "keyType": return java.lang.String.class; case "lazystartproducer": case "lazyStartProducer": return boolean.class; case "maximumsize": - case "maximumSize": return int.class; + case "maximumSize": return java.lang.Integer.class; case "removallistener": case "removalListener": return com.github.benmanes.caffeine.cache.RemovalListener.class; case "statscounter": diff --git a/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheComponentConfigurer.java b/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheComponentConfigurer.java index 28809e67224..b8f641206b1 100644 --- a/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheComponentConfigurer.java +++ b/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheComponentConfigurer.java @@ -43,14 +43,14 @@ public class CaffeineLoadCacheComponentConfigurer extends PropertyConfigurerSupp case "expireafterwritetime": case "expireAfterWriteTime": getOrCreateConfiguration(target).setExpireAfterWriteTime(property(camelContext, int.class, value)); return true; case "initialcapacity": - case "initialCapacity": getOrCreateConfiguration(target).setInitialCapacity(property(camelContext, int.class, value)); return true; + case "initialCapacity": getOrCreateConfiguration(target).setInitialCapacity(property(camelContext, java.lang.Integer.class, value)); return true; case "key": getOrCreateConfiguration(target).setKey(property(camelContext, java.lang.Object.class, value)); return true; case "keytype": case "keyType": getOrCreateConfiguration(target).setKeyType(property(camelContext, java.lang.String.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; case "maximumsize": - case "maximumSize": getOrCreateConfiguration(target).setMaximumSize(property(camelContext, int.class, value)); return true; + case "maximumSize": getOrCreateConfiguration(target).setMaximumSize(property(camelContext, java.lang.Integer.class, value)); return true; case "removallistener": case "removalListener": getOrCreateConfiguration(target).setRemovalListener(property(camelContext, com.github.benmanes.caffeine.cache.RemovalListener.class, value)); return true; case "statscounter": @@ -81,14 +81,14 @@ public class CaffeineLoadCacheComponentConfigurer extends PropertyConfigurerSupp case "expireafterwritetime": case "expireAfterWriteTime": return int.class; case "initialcapacity": - case "initialCapacity": return int.class; + case "initialCapacity": return java.lang.Integer.class; case "key": return java.lang.Object.class; case "keytype": case "keyType": return java.lang.String.class; case "lazystartproducer": case "lazyStartProducer": return boolean.class; case "maximumsize": - case "maximumSize": return int.class; + case "maximumSize": return java.lang.Integer.class; case "removallistener": case "removalListener": return com.github.benmanes.caffeine.cache.RemovalListener.class; case "statscounter": diff --git a/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheEndpointConfigurer.java b/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheEndpointConfigurer.java index 93e974d8a87..2031c350dfc 100644 --- a/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheEndpointConfigurer.java +++ b/components/camel-caffeine/src/generated/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheEndpointConfigurer.java @@ -33,14 +33,14 @@ public class CaffeineLoadCacheEndpointConfigurer extends PropertyConfigurerSuppo case "expireafterwritetime": case "expireAfterWriteTime": target.getConfiguration().setExpireAfterWriteTime(property(camelContext, int.class, value)); return true; case "initialcapacity": - case "initialCapacity": target.getConfiguration().setInitialCapacity(property(camelContext, int.class, value)); return true; + case "initialCapacity": target.getConfiguration().setInitialCapacity(property(camelContext, java.lang.Integer.class, value)); return true; case "key": target.getConfiguration().setKey(property(camelContext, java.lang.Object.class, value)); return true; case "keytype": case "keyType": target.getConfiguration().setKeyType(property(camelContext, java.lang.String.class, value)); return true; case "lazystartproducer": case "lazyStartProducer": target.setLazyStartProducer(property(camelContext, boolean.class, value)); return true; case "maximumsize": - case "maximumSize": target.getConfiguration().setMaximumSize(property(camelContext, int.class, value)); return true; + case "maximumSize": target.getConfiguration().setMaximumSize(property(camelContext, java.lang.Integer.class, value)); return true; case "removallistener": case "removalListener": target.getConfiguration().setRemovalListener(property(camelContext, com.github.benmanes.caffeine.cache.RemovalListener.class, value)); return true; case "statscounter": @@ -68,14 +68,14 @@ public class CaffeineLoadCacheEndpointConfigurer extends PropertyConfigurerSuppo case "expireafterwritetime": case "expireAfterWriteTime": return int.class; case "initialcapacity": - case "initialCapacity": return int.class; + case "initialCapacity": return java.lang.Integer.class; case "key": return java.lang.Object.class; case "keytype": case "keyType": return java.lang.String.class; case "lazystartproducer": case "lazyStartProducer": return boolean.class; case "maximumsize": - case "maximumSize": return int.class; + case "maximumSize": return java.lang.Integer.class; case "removallistener": case "removalListener": return com.github.benmanes.caffeine.cache.RemovalListener.class; case "statscounter": diff --git a/components/camel-caffeine/src/generated/resources/org/apache/camel/component/caffeine/cache/caffeine-cache.json b/components/camel-caffeine/src/generated/resources/org/apache/camel/component/caffeine/cache/caffeine-cache.json index 88f318ba669..2d29a938233 100644 --- a/components/camel-caffeine/src/generated/resources/org/apache/camel/component/caffeine/cache/caffeine-cache.json +++ b/components/camel-caffeine/src/generated/resources/org/apache/camel/component/caffeine/cache/caffeine-cache.json @@ -22,22 +22,22 @@ "lenientProperties": false }, "componentProperties": { - "action": { "kind": "property", "displayName": "Action", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default cache action. If an action is set in the message header, then the operation from the header takes p [...] - "cacheLoader": { "kind": "property", "displayName": "Cache Loader", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.CacheLoader", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure a CacheLoader in case of a LoadCache use" }, - "createCacheIfNotExist": { "kind": "property", "displayName": "Create Cache If Not Exist", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Configure if a cache need to be created if it does exist or can't be pre-configured." }, - "evictionType": { "kind": "property", "displayName": "Eviction Type", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.EvictionType", "enum": [ "size_based", "time_based" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "SIZE_BASED", "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the e [...] - "expireAfterAccessTime": { "kind": "property", "displayName": "Expire After Access Time", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the expire After Access Time in case of time based Eviction (in seconds)" }, - "expireAfterWriteTime": { "kind": "property", "displayName": "Expire After Write Time", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the expire After Access Write in case of time based Eviction (in seconds)" }, - "initialCapacity": { "kind": "property", "displayName": "Initial Capacity", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the initial Capacity for the cache" }, - "key": { "kind": "property", "displayName": "Key", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "java.lang.Object", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default action key. If a key is set in the message header, then the key from the header takes precedence." }, + "action": { "kind": "property", "displayName": "Action", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "GET", "GET_ALL", "PUT", "PUT_ALL", "INVALIDATE", "INVALIDATE_ALL", "CLEANUP", "AS_MAP" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default cache [...] + "createCacheIfNotExist": { "kind": "property", "displayName": "Create Cache If Not Exist", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Automatic create the Caffeine cache if none has been configured or exists in the reg [...] + "evictionType": { "kind": "property", "displayName": "Eviction Type", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.EvictionType", "enum": [ "size_based", "time_based" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "SIZE_BASED", "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the eviction [...] + "expireAfterAccessTime": { "kind": "property", "displayName": "Expire After Access Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies that each entry should be automatically removed from the cache once a fixed dura [...] + "expireAfterWriteTime": { "kind": "property", "displayName": "Expire After Write Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies that each entry should be automatically removed from the cache once a fixed durati [...] + "initialCapacity": { "kind": "property", "displayName": "Initial Capacity", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Sets the minimum total size for the internal data structures. Providing a large enough estimate at construction [...] + "key": { "kind": "property", "displayName": "Key", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "java.lang.Object", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default action key. If a key is set in the message header, then the key from the header takes precedence." }, "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...] - "maximumSize": { "kind": "property", "displayName": "Maximum Size", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the maximum size for the cache" }, - "removalListener": { "kind": "property", "displayName": "Removal Listener", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.RemovalListener", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific removal Listener for the cache" }, - "statsCounter": { "kind": "property", "displayName": "Stats Counter", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.stats.StatsCounter", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific Stats Counter for the cache stats" }, - "statsEnabled": { "kind": "property", "displayName": "Stats Enabled", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To enable stats on the cache" }, + "maximumSize": { "kind": "property", "displayName": "Maximum Size", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies the maximum number of entries the cache may contain. Note that the cache may evict an entry before this limit [...] "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...] + "cacheLoader": { "kind": "property", "displayName": "Cache Loader", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.CacheLoader", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure a CacheLoader in case of a LoadCache use" }, "configuration": { "kind": "property", "displayName": "Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.CaffeineConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the global component configuration" }, "keyType": { "kind": "property", "displayName": "Key Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "The cache key type, default java.lang.Object" }, + "removalListener": { "kind": "property", "displayName": "Removal Listener", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.RemovalListener", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific removal Listener for the cache" }, + "statsCounter": { "kind": "property", "displayName": "Stats Counter", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.stats.StatsCounter", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific Stats Counter for the cache stats" }, + "statsEnabled": { "kind": "property", "displayName": "Stats Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To enable stats on the cache" }, "valueType": { "kind": "property", "displayName": "Value Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "The cache value type, default java.lang.Object" } }, "headers": { @@ -50,21 +50,21 @@ "CamelCaffeineOldValue": { "kind": "header", "displayName": "", "group": "producer", "label": "", "required": false, "javaType": "", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "The old value returned according to the action.", "constantName": "org.apache.camel.component.caffeine.CaffeineConstants#OLD_VALUE" } }, "properties": { - "cacheName": { "kind": "path", "displayName": "Cache Name", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "the cache name" }, - "action": { "kind": "parameter", "displayName": "Action", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default cache action. If an action is set in the message header, then the operation from the header takes [...] - "cacheLoader": { "kind": "parameter", "displayName": "Cache Loader", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.CacheLoader", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure a CacheLoader in case of a LoadCache use" }, - "createCacheIfNotExist": { "kind": "parameter", "displayName": "Create Cache If Not Exist", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Configure if a cache need to be created if it does exist or can't be pre-configured." }, - "evictionType": { "kind": "parameter", "displayName": "Eviction Type", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.EvictionType", "enum": [ "size_based", "time_based" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "SIZE_BASED", "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the [...] - "expireAfterAccessTime": { "kind": "parameter", "displayName": "Expire After Access Time", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the expire After Access Time in case of time based Eviction (in seconds)" }, - "expireAfterWriteTime": { "kind": "parameter", "displayName": "Expire After Write Time", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the expire After Access Write in case of time based Eviction (in seconds)" }, - "initialCapacity": { "kind": "parameter", "displayName": "Initial Capacity", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the initial Capacity for the cache" }, - "key": { "kind": "parameter", "displayName": "Key", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "java.lang.Object", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default action key. If a key is set in the message header, then the key from the header takes precedence." }, - "maximumSize": { "kind": "parameter", "displayName": "Maximum Size", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the maximum size for the cache" }, - "removalListener": { "kind": "parameter", "displayName": "Removal Listener", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.RemovalListener", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific removal Listener for the cache" }, - "statsCounter": { "kind": "parameter", "displayName": "Stats Counter", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.stats.StatsCounter", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific Stats Counter for the cache stats" }, - "statsEnabled": { "kind": "parameter", "displayName": "Stats Enabled", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To enable stats on the cache" }, + "cacheName": { "kind": "path", "displayName": "Cache Name", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "Cache name" }, + "action": { "kind": "parameter", "displayName": "Action", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "GET", "GET_ALL", "PUT", "PUT_ALL", "INVALIDATE", "INVALIDATE_ALL", "CLEANUP", "AS_MAP" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default cache [...] + "createCacheIfNotExist": { "kind": "parameter", "displayName": "Create Cache If Not Exist", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Automatic create the Caffeine cache if none has been configured or exists in the re [...] + "evictionType": { "kind": "parameter", "displayName": "Eviction Type", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.EvictionType", "enum": [ "size_based", "time_based" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "SIZE_BASED", "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the eviction [...] + "expireAfterAccessTime": { "kind": "parameter", "displayName": "Expire After Access Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies that each entry should be automatically removed from the cache once a fixed dur [...] + "expireAfterWriteTime": { "kind": "parameter", "displayName": "Expire After Write Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies that each entry should be automatically removed from the cache once a fixed durat [...] + "initialCapacity": { "kind": "parameter", "displayName": "Initial Capacity", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Sets the minimum total size for the internal data structures. Providing a large enough estimate at constructio [...] + "key": { "kind": "parameter", "displayName": "Key", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "java.lang.Object", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default action key. If a key is set in the message header, then the key from the header takes precedence." }, + "maximumSize": { "kind": "parameter", "displayName": "Maximum Size", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies the maximum number of entries the cache may contain. Note that the cache may evict an entry before this limi [...] "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may other [...] + "cacheLoader": { "kind": "parameter", "displayName": "Cache Loader", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.CacheLoader", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure a CacheLoader in case of a LoadCache use" }, "keyType": { "kind": "parameter", "displayName": "Key Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "The cache key type, default java.lang.Object" }, + "removalListener": { "kind": "parameter", "displayName": "Removal Listener", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.RemovalListener", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific removal Listener for the cache" }, + "statsCounter": { "kind": "parameter", "displayName": "Stats Counter", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.stats.StatsCounter", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific Stats Counter for the cache stats" }, + "statsEnabled": { "kind": "parameter", "displayName": "Stats Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To enable stats on the cache" }, "valueType": { "kind": "parameter", "displayName": "Value Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "The cache value type, default java.lang.Object" } } } diff --git a/components/camel-caffeine/src/generated/resources/org/apache/camel/component/caffeine/load/caffeine-loadcache.json b/components/camel-caffeine/src/generated/resources/org/apache/camel/component/caffeine/load/caffeine-loadcache.json index 82b9da4eb0f..2502ee34f86 100644 --- a/components/camel-caffeine/src/generated/resources/org/apache/camel/component/caffeine/load/caffeine-loadcache.json +++ b/components/camel-caffeine/src/generated/resources/org/apache/camel/component/caffeine/load/caffeine-loadcache.json @@ -22,22 +22,22 @@ "lenientProperties": false }, "componentProperties": { - "action": { "kind": "property", "displayName": "Action", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default cache action. If an action is set in the message header, then the operation from the header takes p [...] - "cacheLoader": { "kind": "property", "displayName": "Cache Loader", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.CacheLoader", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure a CacheLoader in case of a LoadCache use" }, - "createCacheIfNotExist": { "kind": "property", "displayName": "Create Cache If Not Exist", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Configure if a cache need to be created if it does exist or can't be pre-configured." }, - "evictionType": { "kind": "property", "displayName": "Eviction Type", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.EvictionType", "enum": [ "size_based", "time_based" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "SIZE_BASED", "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the e [...] - "expireAfterAccessTime": { "kind": "property", "displayName": "Expire After Access Time", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the expire After Access Time in case of time based Eviction (in seconds)" }, - "expireAfterWriteTime": { "kind": "property", "displayName": "Expire After Write Time", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the expire After Access Write in case of time based Eviction (in seconds)" }, - "initialCapacity": { "kind": "property", "displayName": "Initial Capacity", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the initial Capacity for the cache" }, - "key": { "kind": "property", "displayName": "Key", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "java.lang.Object", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default action key. If a key is set in the message header, then the key from the header takes precedence." }, + "action": { "kind": "property", "displayName": "Action", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "GET", "GET_ALL", "PUT", "PUT_ALL", "INVALIDATE", "INVALIDATE_ALL", "CLEANUP", "AS_MAP" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default cache [...] + "createCacheIfNotExist": { "kind": "property", "displayName": "Create Cache If Not Exist", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Automatic create the Caffeine cache if none has been configured or exists in the reg [...] + "evictionType": { "kind": "property", "displayName": "Eviction Type", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.EvictionType", "enum": [ "size_based", "time_based" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "SIZE_BASED", "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the eviction [...] + "expireAfterAccessTime": { "kind": "property", "displayName": "Expire After Access Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies that each entry should be automatically removed from the cache once a fixed dura [...] + "expireAfterWriteTime": { "kind": "property", "displayName": "Expire After Write Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies that each entry should be automatically removed from the cache once a fixed durati [...] + "initialCapacity": { "kind": "property", "displayName": "Initial Capacity", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Sets the minimum total size for the internal data structures. Providing a large enough estimate at construction [...] + "key": { "kind": "property", "displayName": "Key", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "java.lang.Object", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default action key. If a key is set in the message header, then the key from the header takes precedence." }, "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during star [...] - "maximumSize": { "kind": "property", "displayName": "Maximum Size", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the maximum size for the cache" }, - "removalListener": { "kind": "property", "displayName": "Removal Listener", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.RemovalListener", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific removal Listener for the cache" }, - "statsCounter": { "kind": "property", "displayName": "Stats Counter", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.stats.StatsCounter", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific Stats Counter for the cache stats" }, - "statsEnabled": { "kind": "property", "displayName": "Stats Enabled", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To enable stats on the cache" }, + "maximumSize": { "kind": "property", "displayName": "Maximum Size", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies the maximum number of entries the cache may contain. Note that the cache may evict an entry before this limit [...] "autowiredEnabled": { "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which t [...] + "cacheLoader": { "kind": "property", "displayName": "Cache Loader", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.CacheLoader", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure a CacheLoader in case of a LoadCache use" }, "configuration": { "kind": "property", "displayName": "Configuration", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.CaffeineConfiguration", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the global component configuration" }, "keyType": { "kind": "property", "displayName": "Key Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "The cache key type, default java.lang.Object" }, + "removalListener": { "kind": "property", "displayName": "Removal Listener", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.RemovalListener", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific removal Listener for the cache" }, + "statsCounter": { "kind": "property", "displayName": "Stats Counter", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.stats.StatsCounter", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific Stats Counter for the cache stats" }, + "statsEnabled": { "kind": "property", "displayName": "Stats Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To enable stats on the cache" }, "valueType": { "kind": "property", "displayName": "Value Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "The cache value type, default java.lang.Object" } }, "headers": { @@ -51,20 +51,20 @@ }, "properties": { "cacheName": { "kind": "path", "displayName": "Cache Name", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "the cache name" }, - "action": { "kind": "parameter", "displayName": "Action", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default cache action. If an action is set in the message header, then the operation from the header takes [...] - "cacheLoader": { "kind": "parameter", "displayName": "Cache Loader", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.CacheLoader", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure a CacheLoader in case of a LoadCache use" }, - "createCacheIfNotExist": { "kind": "parameter", "displayName": "Create Cache If Not Exist", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Configure if a cache need to be created if it does exist or can't be pre-configured." }, - "evictionType": { "kind": "parameter", "displayName": "Eviction Type", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.EvictionType", "enum": [ "size_based", "time_based" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "SIZE_BASED", "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the [...] - "expireAfterAccessTime": { "kind": "parameter", "displayName": "Expire After Access Time", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the expire After Access Time in case of time based Eviction (in seconds)" }, - "expireAfterWriteTime": { "kind": "parameter", "displayName": "Expire After Write Time", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the expire After Access Write in case of time based Eviction (in seconds)" }, - "initialCapacity": { "kind": "parameter", "displayName": "Initial Capacity", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the initial Capacity for the cache" }, - "key": { "kind": "parameter", "displayName": "Key", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "java.lang.Object", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default action key. If a key is set in the message header, then the key from the header takes precedence." }, - "maximumSize": { "kind": "parameter", "displayName": "Maximum Size", "group": "producer", "label": "producer", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 10000, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the maximum size for the cache" }, - "removalListener": { "kind": "parameter", "displayName": "Removal Listener", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.RemovalListener", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific removal Listener for the cache" }, - "statsCounter": { "kind": "parameter", "displayName": "Stats Counter", "group": "producer", "label": "producer", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.stats.StatsCounter", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific Stats Counter for the cache stats" }, - "statsEnabled": { "kind": "parameter", "displayName": "Stats Enabled", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To enable stats on the cache" }, + "action": { "kind": "parameter", "displayName": "Action", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "GET", "GET_ALL", "PUT", "PUT_ALL", "INVALIDATE", "INVALIDATE_ALL", "CLEANUP", "AS_MAP" ], "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default cache [...] + "createCacheIfNotExist": { "kind": "parameter", "displayName": "Create Cache If Not Exist", "group": "producer", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Automatic create the Caffeine cache if none has been configured or exists in the re [...] + "evictionType": { "kind": "parameter", "displayName": "Eviction Type", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.caffeine.EvictionType", "enum": [ "size_based", "time_based" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "SIZE_BASED", "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set the eviction [...] + "expireAfterAccessTime": { "kind": "parameter", "displayName": "Expire After Access Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies that each entry should be automatically removed from the cache once a fixed dur [...] + "expireAfterWriteTime": { "kind": "parameter", "displayName": "Expire After Write Time", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "int", "deprecated": false, "autowired": false, "secret": false, "defaultValue": 300, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies that each entry should be automatically removed from the cache once a fixed durat [...] + "initialCapacity": { "kind": "parameter", "displayName": "Initial Capacity", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Sets the minimum total size for the internal data structures. Providing a large enough estimate at constructio [...] + "key": { "kind": "parameter", "displayName": "Key", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "java.lang.Object", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure the default action key. If a key is set in the message header, then the key from the header takes precedence." }, + "maximumSize": { "kind": "parameter", "displayName": "Maximum Size", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Specifies the maximum number of entries the cache may contain. Note that the cache may evict an entry before this limi [...] "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may other [...] + "cacheLoader": { "kind": "parameter", "displayName": "Cache Loader", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.CacheLoader", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To configure a CacheLoader in case of a LoadCache use" }, "keyType": { "kind": "parameter", "displayName": "Key Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "The cache key type, default java.lang.Object" }, + "removalListener": { "kind": "parameter", "displayName": "Removal Listener", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.RemovalListener", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific removal Listener for the cache" }, + "statsCounter": { "kind": "parameter", "displayName": "Stats Counter", "group": "advanced", "label": "advanced", "required": false, "type": "object", "javaType": "com.github.benmanes.caffeine.cache.stats.StatsCounter", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "Set a specific Stats Counter for the cache stats" }, + "statsEnabled": { "kind": "parameter", "displayName": "Stats Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "To enable stats on the cache" }, "valueType": { "kind": "parameter", "displayName": "Value Type", "group": "advanced", "label": "advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "configurationClass": "org.apache.camel.component.caffeine.CaffeineConfiguration", "configurationField": "configuration", "description": "The cache value type, default java.lang.Object" } } } diff --git a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/CaffeineConfiguration.java b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/CaffeineConfiguration.java index 3655031213e..94765fd2cf9 100644 --- a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/CaffeineConfiguration.java +++ b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/CaffeineConfiguration.java @@ -27,32 +27,32 @@ import org.apache.camel.spi.UriParams; public class CaffeineConfiguration implements Cloneable { @UriParam(defaultValue = "true") private boolean createCacheIfNotExist = true; - @UriParam(label = "producer") + @UriParam(enums = "GET,GET_ALL,PUT,PUT_ALL,INVALIDATE,INVALIDATE_ALL,CLEANUP,AS_MAP") private String action; - @UriParam(label = "producer") + @UriParam private Object key; @UriParam(label = "advanced") private String keyType; @UriParam(label = "advanced") private String valueType; - @UriParam(label = "producer") - private CacheLoader cacheLoader; - @UriParam(label = "producer") - private boolean statsEnabled; - @UriParam(label = "producer", defaultValue = "10000") - private int initialCapacity = 10000; - @UriParam(label = "producer", defaultValue = "10000") - private int maximumSize = 10000; - @UriParam(label = "producer", defaultValue = "SIZE_BASED") + @UriParam + private Integer initialCapacity; + @UriParam + private Integer maximumSize; + @UriParam(defaultValue = "SIZE_BASED") private EvictionType evictionType = EvictionType.SIZE_BASED; - @UriParam(label = "producer", defaultValue = "300") + @UriParam(defaultValue = "300") private int expireAfterAccessTime = 300; - @UriParam(label = "producer", defaultValue = "300") + @UriParam(defaultValue = "300") private int expireAfterWriteTime = 300; - @UriParam(label = "producer") + @UriParam(label = "advanced") private RemovalListener removalListener; - @UriParam(label = "producer") + @UriParam(label = "advanced") + private boolean statsEnabled; + @UriParam(label = "advanced") private StatsCounter statsCounter; + @UriParam(label = "advanced") + private CacheLoader cacheLoader; public CaffeineConfiguration() { } @@ -62,7 +62,7 @@ public class CaffeineConfiguration implements Cloneable { } /** - * Configure if a cache need to be created if it does exist or can't be pre-configured. + * Automatic create the Caffeine cache if none has been configured or exists in the registry. */ public void setCreateCacheIfNotExist(boolean createCacheIfNotExist) { this.createCacheIfNotExist = createCacheIfNotExist; @@ -136,25 +136,33 @@ public class CaffeineConfiguration implements Cloneable { this.statsEnabled = statsEnabled; } - public int getInitialCapacity() { + public Integer getInitialCapacity() { return initialCapacity; } /** - * Set the initial Capacity for the cache + * Sets the minimum total size for the internal data structures. Providing a large enough estimate at construction + * time avoids the need for expensive resizing operations later, but setting this value unnecessarily high wastes + * memory. */ public void setInitialCapacity(int initialCapacity) { this.initialCapacity = initialCapacity; } - public int getMaximumSize() { + public Integer getMaximumSize() { return maximumSize; } /** - * Set the maximum size for the cache + * Specifies the maximum number of entries the cache may contain. Note that the cache may evict an entry before this + * limit is exceeded or temporarily exceed the threshold while evicting. As the cache size grows close to the + * maximum, the cache evicts entries that are less likely to be used again. For example, the cache may evict an + * entry because it hasn't been used recently or very often. When size is zero, elements will be evicted immediately + * after being loaded into the cache. This can be useful in testing, or to disable caching temporarily without a + * code change. As eviction is scheduled on the configured executor, tests may instead prefer to configure the cache + * to execute tasks directly on the same thread. */ - public void setMaximumSize(int maximumSize) { + public void setMaximumSize(Integer maximumSize) { this.maximumSize = maximumSize; } @@ -174,7 +182,11 @@ public class CaffeineConfiguration implements Cloneable { } /** - * Set the expire After Access Time in case of time based Eviction (in seconds) + * Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after + * the entry's creation, the most recent replacement of its value, or its last read. Access time is reset by all + * cache read and write operations. + * + * The unit is in seconds. */ public void setExpireAfterAccessTime(int expireAfterAccessTime) { this.expireAfterAccessTime = expireAfterAccessTime; @@ -185,7 +197,10 @@ public class CaffeineConfiguration implements Cloneable { } /** - * Set the expire After Access Write in case of time based Eviction (in seconds) + * Specifies that each entry should be automatically removed from the cache once a fixed duration has elapsed after + * the entry's creation, or the most recent replacement of its value. + * + * The unit is in seconds. */ public void setExpireAfterWriteTime(int expireAfterWriteTime) { this.expireAfterWriteTime = expireAfterWriteTime; diff --git a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/CaffeineHelper.java b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/CaffeineHelper.java new file mode 100644 index 00000000000..e71e2e12f4d --- /dev/null +++ b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/CaffeineHelper.java @@ -0,0 +1,53 @@ +/* + * 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.component.caffeine; + +import java.util.concurrent.TimeUnit; + +import com.github.benmanes.caffeine.cache.Caffeine; +import org.apache.camel.util.ObjectHelper; + +public final class CaffeineHelper { + + private CaffeineHelper() { + } + + public static void defineBuilder(Caffeine<?, ?> builder, CaffeineConfiguration configuration) { + if (configuration.getEvictionType() == EvictionType.SIZE_BASED) { + if (configuration.getInitialCapacity() != null) { + builder.initialCapacity(configuration.getInitialCapacity()); + } + if (configuration.getMaximumSize() != null) { + builder.maximumSize(configuration.getMaximumSize()); + } + } else if (configuration.getEvictionType() == EvictionType.TIME_BASED) { + builder.expireAfterAccess(configuration.getExpireAfterAccessTime(), TimeUnit.SECONDS); + builder.expireAfterWrite(configuration.getExpireAfterWriteTime(), TimeUnit.SECONDS); + } + if (configuration.isStatsEnabled()) { + if (ObjectHelper.isEmpty(configuration.getStatsCounter())) { + builder.recordStats(); + } else { + builder.recordStats(configuration::getStatsCounter); + } + } + if (ObjectHelper.isNotEmpty(configuration.getRemovalListener())) { + builder.removalListener(configuration.getRemovalListener()); + } + } + +} diff --git a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheComponent.java b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheComponent.java index 69ed64e0c8b..2e8fba4dc2d 100644 --- a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheComponent.java +++ b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheComponent.java @@ -17,24 +17,31 @@ package org.apache.camel.component.caffeine.cache; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; import org.apache.camel.component.caffeine.CaffeineConfiguration; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; -import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.camel.component.caffeine.CaffeineHelper.defineBuilder; + /** * Represents the component that manages {@link DefaultComponent}. */ @Component("caffeine-cache") public class CaffeineCacheComponent extends DefaultComponent { + private static final Logger LOGGER = LoggerFactory.getLogger(CaffeineCacheComponent.class); + private final Map<String, Cache> caches = new ConcurrentHashMap<>(); + @Metadata(label = "advanced") private CaffeineConfiguration configuration = new CaffeineConfiguration(); @@ -54,9 +61,13 @@ public class CaffeineCacheComponent extends DefaultComponent { return endpoint; } - // **************************** - // Properties - // **************************** + protected Cache<?, ?> getOrCreateCache(String name, CaffeineConfiguration configuration) { + return caches.computeIfAbsent(name, key -> { + Caffeine<?, ?> builder = Caffeine.newBuilder(); + defineBuilder(builder, configuration); + return builder.build(); + }); + } public CaffeineConfiguration getConfiguration() { return configuration; @@ -66,9 +77,12 @@ public class CaffeineCacheComponent extends DefaultComponent { * Sets the global component configuration */ public void setConfiguration(CaffeineConfiguration configuration) { - // The component configuration can't be null - ObjectHelper.notNull(configuration, "CaffeineConfiguration"); - this.configuration = configuration; } + + @Override + protected void doShutdown() throws Exception { + caches.clear(); + } + } diff --git a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpoint.java b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpoint.java index 31321fd68bc..3e9aed6211b 100644 --- a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpoint.java +++ b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/cache/CaffeineCacheEndpoint.java @@ -16,10 +16,7 @@ */ package org.apache.camel.component.caffeine.cache; -import java.util.concurrent.TimeUnit; - import com.github.benmanes.caffeine.cache.Cache; -import com.github.benmanes.caffeine.cache.Caffeine; import org.apache.camel.Category; import org.apache.camel.Component; import org.apache.camel.Consumer; @@ -27,14 +24,12 @@ import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.component.caffeine.CaffeineConfiguration; import org.apache.camel.component.caffeine.CaffeineConstants; -import org.apache.camel.component.caffeine.EvictionType; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.spi.UriPath; import org.apache.camel.support.CamelContextHelper; import org.apache.camel.support.DefaultEndpoint; -import org.apache.camel.util.ObjectHelper; /** * Perform caching operations using Caffeine Cache. @@ -43,21 +38,26 @@ import org.apache.camel.util.ObjectHelper; syntax = "caffeine-cache:cacheName", category = { Category.CACHE, Category.DATAGRID, Category.CLUSTERING }, producerOnly = true, headersClass = CaffeineConstants.class) public class CaffeineCacheEndpoint extends DefaultEndpoint { - @UriPath(description = "the cache name") + + @UriPath(description = "Cache name") @Metadata(required = true) private final String cacheName; @UriParam private final CaffeineConfiguration configuration; - private Cache cache; + private volatile Cache<?, ?> cache; CaffeineCacheEndpoint(String uri, Component component, String cacheName, CaffeineConfiguration configuration) { super(uri, component); - this.cacheName = cacheName; this.configuration = configuration; } + @Override + public CaffeineCacheComponent getComponent() { + return (CaffeineCacheComponent) super.getComponent(); + } + @Override public Producer createProducer() throws Exception { return new CaffeineCacheProducer(this, configuration, cache); @@ -65,39 +65,16 @@ public class CaffeineCacheEndpoint extends DefaultEndpoint { @Override protected void doStart() throws Exception { - + super.doStart(); cache = CamelContextHelper.lookup(getCamelContext(), cacheName, Cache.class); if (cache == null) { if (configuration.isCreateCacheIfNotExist()) { - Caffeine<?, ?> builder = Caffeine.newBuilder(); - defineBuilder(builder, configuration); - cache = builder.build(); + cache = getComponent().getOrCreateCache(cacheName, configuration); } else { throw new IllegalArgumentException( "Cache instance '" + cacheName + "' not found and createCacheIfNotExist is set to false"); } } - super.doStart(); - } - - public static void defineBuilder(Caffeine<?, ?> builder, CaffeineConfiguration configuration) { - if (configuration.getEvictionType() == EvictionType.SIZE_BASED) { - builder.initialCapacity(configuration.getInitialCapacity()); - builder.maximumSize(configuration.getMaximumSize()); - } else if (configuration.getEvictionType() == EvictionType.TIME_BASED) { - builder.expireAfterAccess(configuration.getExpireAfterAccessTime(), TimeUnit.SECONDS); - builder.expireAfterWrite(configuration.getExpireAfterWriteTime(), TimeUnit.SECONDS); - } - if (configuration.isStatsEnabled()) { - if (ObjectHelper.isEmpty(configuration.getStatsCounter())) { - builder.recordStats(); - } else { - builder.recordStats(configuration::getStatsCounter); - } - } - if (ObjectHelper.isNotEmpty(configuration.getRemovalListener())) { - builder.removalListener(configuration.getRemovalListener()); - } } @Override diff --git a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheComponent.java b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheComponent.java index 037555d9d17..0c567aba3b2 100644 --- a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheComponent.java +++ b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheComponent.java @@ -17,7 +17,9 @@ package org.apache.camel.component.caffeine.load; import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; @@ -25,10 +27,11 @@ import org.apache.camel.component.caffeine.CaffeineConfiguration; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.annotations.Component; import org.apache.camel.support.DefaultComponent; -import org.apache.camel.util.ObjectHelper; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static org.apache.camel.component.caffeine.CaffeineHelper.defineBuilder; + /** * Represents the component that manages {@link DefaultComponent}. */ @@ -36,11 +39,11 @@ import org.slf4j.LoggerFactory; public class CaffeineLoadCacheComponent extends DefaultComponent { private static final Logger LOGGER = LoggerFactory.getLogger(CaffeineLoadCacheComponent.class); + private final Map<String, LoadingCache<?, ?>> caches = new ConcurrentHashMap<>(); + @Metadata(label = "advanced") private CaffeineConfiguration configuration = new CaffeineConfiguration(); - private LoadingCache cache; - public CaffeineLoadCacheComponent() { } @@ -57,9 +60,13 @@ public class CaffeineLoadCacheComponent extends DefaultComponent { return endpoint; } - // **************************** - // Properties - // **************************** + protected LoadingCache<?, ?> getOrCreateCache(String name, CaffeineConfiguration configuration) { + return caches.computeIfAbsent(name, key -> { + Caffeine<?, ?> builder = Caffeine.newBuilder(); + defineBuilder(builder, configuration); + return builder.build(configuration.getCacheLoader()); + }); + } public CaffeineConfiguration getConfiguration() { return configuration; @@ -69,9 +76,6 @@ public class CaffeineLoadCacheComponent extends DefaultComponent { * Sets the global component configuration */ public void setConfiguration(CaffeineConfiguration configuration) { - // The component configuration can't be null - ObjectHelper.notNull(configuration, "CaffeineConfiguration"); - this.configuration = configuration; } } diff --git a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheEndpoint.java b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheEndpoint.java index 627c1d230be..defa34ca675 100644 --- a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheEndpoint.java +++ b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/load/CaffeineLoadCacheEndpoint.java @@ -16,7 +16,6 @@ */ package org.apache.camel.component.caffeine.load; -import com.github.benmanes.caffeine.cache.Caffeine; import com.github.benmanes.caffeine.cache.LoadingCache; import org.apache.camel.Category; import org.apache.camel.Component; @@ -25,7 +24,6 @@ import org.apache.camel.Processor; import org.apache.camel.Producer; import org.apache.camel.component.caffeine.CaffeineConfiguration; import org.apache.camel.component.caffeine.CaffeineConstants; -import org.apache.camel.component.caffeine.cache.CaffeineCacheEndpoint; import org.apache.camel.spi.Metadata; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; @@ -46,15 +44,19 @@ public class CaffeineLoadCacheEndpoint extends DefaultEndpoint { @UriParam private final CaffeineConfiguration configuration; - private LoadingCache cache; + private volatile LoadingCache<?, ?> cache; CaffeineLoadCacheEndpoint(String uri, Component component, String cacheName, CaffeineConfiguration configuration) { super(uri, component); - this.cacheName = cacheName; this.configuration = configuration; } + @Override + public CaffeineLoadCacheComponent getComponent() { + return (CaffeineLoadCacheComponent) super.getComponent(); + } + @Override public Producer createProducer() throws Exception { return new CaffeineLoadCacheProducer(this, configuration, cache); @@ -62,20 +64,16 @@ public class CaffeineLoadCacheEndpoint extends DefaultEndpoint { @Override protected void doStart() throws Exception { - + super.doStart(); cache = CamelContextHelper.lookup(getCamelContext(), cacheName, LoadingCache.class); if (cache == null) { if (configuration.isCreateCacheIfNotExist()) { - Caffeine<Object, Object> builder = Caffeine.newBuilder(); - CaffeineCacheEndpoint.defineBuilder(builder, configuration); - cache = builder.build(configuration.getCacheLoader()); + cache = getComponent().getOrCreateCache(cacheName, configuration); } else { throw new IllegalArgumentException( - "Loading cache instance '" + cacheName - + "' not found and createCacheIfNotExist is set to false"); + "LoadingCache instance '" + cacheName + "' not found and createCacheIfNotExist is set to false"); } } - super.doStart(); } @Override diff --git a/components/camel-caffeine/src/test/java/org/apache/camel/component/caffeine/cache/CaffeineCacheProducerCacheNameTest.java b/components/camel-caffeine/src/test/java/org/apache/camel/component/caffeine/cache/CaffeineCacheProducerCacheNameTest.java new file mode 100644 index 00000000000..4133da45088 --- /dev/null +++ b/components/camel-caffeine/src/test/java/org/apache/camel/component/caffeine/cache/CaffeineCacheProducerCacheNameTest.java @@ -0,0 +1,48 @@ +/* + * 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.component.caffeine.cache; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.jupiter.api.Test; + +public class CaffeineCacheProducerCacheNameTest extends CaffeineCacheTestSupport { + + @Test + public void testCacheName() throws Exception { + MockEndpoint mock = getMockEndpoint("mock:result"); + mock.expectedBodiesReceived("VALUE_1"); + + template.sendBody("direct:start", "Hello World"); + + assertMockEndpointsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() { + return new RouteBuilder() { + public void configure() { + from("direct://start") + .setBody(constant("VALUE_1")) + .to("caffeine-cache://mycache?action=PUT&key=1") + .setBody(constant("VALUE_2")) + .to("caffeine-cache://mycache?key=1&action=GET") + .to("mock:result"); + } + }; + } +}
