This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new f59cb5827125 CAMEL-23267: Use simple LinkedHashMap as
inProgressRepository
f59cb5827125 is described below
commit f59cb5827125e88bd3ee8d01dcbbc19cf396814a
Author: Claus Ibsen <[email protected]>
AuthorDate: Fri Apr 10 18:54:49 2026 +0200
CAMEL-23267: Use simple LinkedHashMap as inProgressRepository
---
.../camel/component/aws2/s3/AWS2S3Endpoint.java | 2 +-
.../camel/component/file/GenericFileEndpoint.java | 2 +-
.../camel/component/ibm/cos/IBMCOSEndpoint.java | 2 +-
.../idempotent/MemoryIdempotentRepository.java | 40 ++++++++++++++--------
...ava => MemoryIdempotentRepositoryFifoTest.java} | 6 ++--
.../ROOT/pages/camel-4x-upgrade-guide-4_19.adoc | 9 +++--
6 files changed, 34 insertions(+), 27 deletions(-)
diff --git
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
index b095089e225d..e2db0faba804 100644
---
a/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
+++
b/components/camel-aws/camel-aws2-s3/src/main/java/org/apache/camel/component/aws2/s3/AWS2S3Endpoint.java
@@ -69,7 +69,7 @@ public class AWS2S3Endpoint extends ScheduledPollEndpoint
implements EndpointSer
+
"org.apache.camel.spi.IdempotentRepository. The in-progress repository is used
to account the current in "
+ "progress files
being consumed. By default a memory based repository is used.")
private IdempotentRepository inProgressRepository
- =
MemoryIdempotentRepository.memoryIdempotentRepository(DEFAULT_IN_PROGRESS_CACHE_SIZE);
+ =
MemoryIdempotentRepository.memoryIdempotentRepositoryFifo(DEFAULT_IN_PROGRESS_CACHE_SIZE);
public AWS2S3Endpoint(String uri, Component comp, AWS2S3Configuration
configuration) {
super(uri, comp);
diff --git
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
index 004100d46d8d..12af129e2aba 100644
---
a/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
+++
b/components/camel-file/src/main/java/org/apache/camel/component/file/GenericFileEndpoint.java
@@ -189,7 +189,7 @@ public abstract class GenericFileEndpoint<T> extends
ScheduledPollEndpoint imple
+
"org.apache.camel.spi.IdempotentRepository. The in-progress repository is used
to account the current in "
+ "progress files
being consumed. By default a memory based repository is used.")
protected IdempotentRepository inProgressRepository
- =
MemoryIdempotentRepository.memoryIdempotentRepository(DEFAULT_IN_PROGRESS_CACHE_SIZE);
+ =
MemoryIdempotentRepository.memoryIdempotentRepositoryFifo(DEFAULT_IN_PROGRESS_CACHE_SIZE);
@UriParam(label = "consumer,advanced", description = "When consuming, a
local work directory can be used to "
+ "store the remote
file content directly in local files, to avoid loading the content into memory.
This "
+ "is beneficial, if
you consume a very big remote file and thus can conserve memory.")
diff --git
a/components/camel-ibm/camel-ibm-cos/src/main/java/org/apache/camel/component/ibm/cos/IBMCOSEndpoint.java
b/components/camel-ibm/camel-ibm-cos/src/main/java/org/apache/camel/component/ibm/cos/IBMCOSEndpoint.java
index 047b7c579c8e..63d9d5b5478b 100644
---
a/components/camel-ibm/camel-ibm-cos/src/main/java/org/apache/camel/component/ibm/cos/IBMCOSEndpoint.java
+++
b/components/camel-ibm/camel-ibm-cos/src/main/java/org/apache/camel/component/ibm/cos/IBMCOSEndpoint.java
@@ -65,7 +65,7 @@ public class IBMCOSEndpoint extends ScheduledPollEndpoint
implements EndpointSer
private int maxMessagesPerPoll = 10;
@UriParam(label = "consumer,advanced")
private IdempotentRepository inProgressRepository
- =
MemoryIdempotentRepository.memoryIdempotentRepository(DEFAULT_IN_PROGRESS_CACHE_SIZE);
+ =
MemoryIdempotentRepository.memoryIdempotentRepositoryFifo(DEFAULT_IN_PROGRESS_CACHE_SIZE);
public IBMCOSEndpoint(String uri, Component comp, IBMCOSConfiguration
configuration) {
super(uri, comp);
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/processor/idempotent/MemoryIdempotentRepository.java
b/core/camel-support/src/main/java/org/apache/camel/support/processor/idempotent/MemoryIdempotentRepository.java
index 4cffa19e8228..0e0f21be3db4 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/processor/idempotent/MemoryIdempotentRepository.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/processor/idempotent/MemoryIdempotentRepository.java
@@ -18,7 +18,6 @@ package org.apache.camel.support.processor.idempotent;
import java.util.LinkedHashMap;
import java.util.Map;
-import java.util.Map.Entry;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
@@ -28,11 +27,14 @@ import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.IdempotentRepository;
import org.apache.camel.spi.Metadata;
+import org.apache.camel.support.LRUCache;
+import org.apache.camel.support.LRUCacheFactory;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.support.service.ServiceSupport;
/**
- * A memory based implementation of {@link
org.apache.camel.spi.IdempotentRepository}.
+ * A memory based implementation of {@link
org.apache.camel.spi.IdempotentRepository} using LRU (default) or FIFO
+ * algorithm.
* <p/>
* Care should be taken to use a suitable underlying {@link Map} to avoid this
class being a memory leak.
*/
@@ -49,7 +51,7 @@ public class MemoryIdempotentRepository extends
ServiceSupport implements Idempo
private final Lock cacheAndStoreLock = new ReentrantLock();
@Metadata(description = "Maximum elements that can be stored in-memory",
defaultValue = "" + MAX_CACHE_SIZE)
- private int cacheSize = MAX_CACHE_SIZE;
+ private int cacheSize;
public MemoryIdempotentRepository() {
}
@@ -59,18 +61,14 @@ public class MemoryIdempotentRepository extends
ServiceSupport implements Idempo
}
/**
- * Creates a new memory based repository using a {@link
java.util.LinkedHashMap} as its store, with 1000 maximum
- * capacity. When a new entry is added and the store has reached its
maximum capacity, the oldest entry is removed.
- *
+ * Creates a new memory based repository using a {@link LRUCache} with a
default of 1000 entries in the cache.
*/
public static IdempotentRepository memoryIdempotentRepository() {
return memoryIdempotentRepository(MAX_CACHE_SIZE);
}
/**
- * Creates a new memory based repository using a {@link
java.util.LinkedHashMap} as its store, with the given
- * maximum capacity. When a new entry is added and the store has reached
its maximum capacity, the oldest entry is
- * removed.
+ * Creates a new memory based repository using a {@link LRUCache}.
*
* @param cacheSize the cache size
*/
@@ -81,6 +79,23 @@ public class MemoryIdempotentRepository extends
ServiceSupport implements Idempo
return answer;
}
+ /**
+ * Creates a new memory based repository using a {@link LinkedHashMap} as
its store, with the given maximum
+ * capacity. When a new entry is added and the store has reached its
maximum capacity, the oldest entry is removed.
+ *
+ * @param cacheSize the cache size
+ */
+ public static IdempotentRepository memoryIdempotentRepositoryFifo(int
cacheSize) {
+ MemoryIdempotentRepository answer = new MemoryIdempotentRepository(new
LinkedHashMap<>() {
+ @Override
+ protected boolean removeEldestEntry(Map.Entry<String, Object>
eldest) {
+ return size() > cacheSize;
+ }
+ });
+ answer.setCacheSize(cacheSize);
+ return answer;
+ }
+
/**
* Creates a new memory based repository using the given {@link Map} to
use to store the processed message ids.
* <p/>
@@ -168,12 +183,7 @@ public class MemoryIdempotentRepository extends
ServiceSupport implements Idempo
@Override
protected void doStart() throws Exception {
if (cache == null) {
- cache = new LinkedHashMap<>() {
- @Override
- protected boolean removeEldestEntry(Entry<String, Object>
eldest) {
- return size() > cacheSize;
- }
- };
+ cache = LRUCacheFactory.newLRUCache(cacheSize <= 0 ?
MAX_CACHE_SIZE : cacheSize);
}
}
diff --git
a/core/camel-support/src/test/java/org/apache/camel/support/MemoryIdempotentRepositoryTest.java
b/core/camel-support/src/test/java/org/apache/camel/support/MemoryIdempotentRepositoryFifoTest.java
similarity index 94%
rename from
core/camel-support/src/test/java/org/apache/camel/support/MemoryIdempotentRepositoryTest.java
rename to
core/camel-support/src/test/java/org/apache/camel/support/MemoryIdempotentRepositoryFifoTest.java
index ef843bd330ca..2d47123f91ec 100644
---
a/core/camel-support/src/test/java/org/apache/camel/support/MemoryIdempotentRepositoryTest.java
+++
b/core/camel-support/src/test/java/org/apache/camel/support/MemoryIdempotentRepositoryFifoTest.java
@@ -25,19 +25,17 @@ import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
-class MemoryIdempotentRepositoryTest {
+class MemoryIdempotentRepositoryFifoTest {
@Test
void repositoryEvictsOldestEntryWhenRepositoryIsFull() throws IOException {
final int cacheSize = 5;
final int entriesNotFittingInRepository = 4;
- try (IdempotentRepository repository =
MemoryIdempotentRepository.memoryIdempotentRepository(
- cacheSize)) {
+ try (IdempotentRepository repository =
MemoryIdempotentRepository.memoryIdempotentRepositoryFifo(cacheSize)) {
for (int i = 0; i < cacheSize + entriesNotFittingInRepository;
i++) {
repository.add(String.valueOf(i));
}
-
for (int i = entriesNotFittingInRepository; i < cacheSize +
entriesNotFittingInRepository; i++) {
assertTrue(repository.contains(String.valueOf(i)), "Repository
should contain entry " + i);
}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_19.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_19.adoc
index 16b6d90b1f38..79a73425a8d2 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_19.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_19.adoc
@@ -27,11 +27,6 @@ The cloud integration from the following components has been
removed: `camel-con
=== camel-core
-==== MemoryIdempotentRepository
-
-The `MemoryIdempotentRepository` is no longer based on `LRUCache` but uses a
`LinkedHashMap` as the repository
-has no need for LRU semantics and the `LinkedHashMap` is more light-weight.
-
==== PQC TLS Auto-Configuration
When running on a JDK that supports `X25519MLKEM768` (typically JDK 25+),
Camel now automatically
@@ -436,6 +431,10 @@ The `camel-json-patch` is now deprecated - the library it
uses is not active mai
When configured a custom `IdempotentRepository` on `camel-mail` endpoint, then
Camel will now auto-start
the bean which is similar to what `camel-file` do as well.
+=== camel-file / camel-aws2-s3 / camel-ibm-cos
+
+The default `inProgressRepository` is now FIFO based instead of LRU as there
was no need for LRU behavior, which is lighter in memory overhead.
+
=== camel-openapi-java
When using _code first_ Rest DSL and have configured `base.path` then this
will now be exclusively used