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 642b567fe382 CAMEL-27006: camel-core - InMemoryStrategy: a repository
tells whether it keeps its data only in memory (#30152)
642b567fe382 is described below
commit 642b567fe382d26b180486bfc3fa1877baecdd5e
Author: Claus Ibsen <[email protected]>
AuthorDate: Mon Nov 16 14:35:47 2026 +0100
CAMEL-27006: camel-core - InMemoryStrategy: a repository tells whether it
keeps its data only in memory (#30152)
Some state stores keep their data only in the memory of the JVM, so the
data is lost when the application stops. After a restart a file consumer with
`noop=true` reads the same files again, an idempotent consumer with an
in-memory repository lets the same messages through again, and an aggregator
has lost the groups it was building.
Today nothing tells a user, or a tool, which stores are in memory:
- The `processor-detail` dev console shows what a route configures, not the
defaults. So the default repository of a file consumer with `noop=true` does
not show.
- JMX does not name the repository of an idempotent consumer or an
aggregator.
- A class name does not say it either. The Caffeine repositories are in
memory, and the key-value repositories of 4.23 are in memory or persistent,
depending on the store they delegate to.
_Claude Code on behalf of davsclaus_
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/catalog/dev-consoles-openapi.json | 42 +++++
.../catalog/dev-consoles/processor-detail.json | 42 +++++
.../component/a2a/state/InMemoryTaskStore.java | 8 +-
.../component/a2a/state/InMemoryTaskStoreTest.java | 5 +
.../camel/semantic/MemorySemanticAuditStore.java | 9 +-
.../apache/camel/semantic/SemanticAuditTest.java | 5 +
.../atmosphere/websocket/MemoryWebSocketStore.java | 8 +-
.../websocket/MemoryWebSocketStoreTest.java | 7 +
.../processor/CaffeineKeyValueRepository.java | 10 +-
.../aggregate/CaffeineAggregationRepository.java | 12 +-
.../idempotent/CaffeineIdempotentRepository.java | 10 +-
.../CaffeineIdempotentRepositoryTest.java | 10 ++
.../apache/camel/oauth/InMemorySessionStore.java | 8 +-
.../camel/oauth/InMemorySessionStoreTest.java | 29 ++++
.../org/apache/camel/spi/InMemoryStrategy.java | 38 +++++
.../apache/camel/dev-console/processor-detail.json | 42 +++++
.../impl/console/ProcessorDetailDevConsole.java | 109 +++++++++++-
.../impl/console/ProcessorDetailStateTest.java | 188 +++++++++++++++++++++
.../aggregate/MemoryAggregationRepository.java | 9 +-
.../apache/camel/support/InMemoryStrategyTest.java | 82 +++++++++
.../mbean/ManagedAggregateProcessorMBean.java | 6 +
.../mbean/ManagedIdempotentConsumerMBean.java | 6 +
.../mbean/ManagedAggregateProcessor.java | 13 ++
.../mbean/ManagedIdempotentConsumer.java | 13 ++
.../management/ManagedAggregateControllerTest.java | 5 +
.../ManagedMemoryIdempotentConsumerTest.java | 7 +
.../org/apache/camel/saga/InMemorySagaService.java | 8 +-
.../support/KeyValueAggregationRepository.java | 13 +-
.../support/KeyValueIdempotentRepository.java | 12 +-
.../camel/support/MemoryKeyValueRepository.java | 9 +-
.../support/NamespacedKeyValueRepository.java | 11 +-
.../idempotent/MemoryIdempotentRepository.java | 9 +-
.../processor/state/MemoryStateRepository.java | 10 +-
33 files changed, 774 insertions(+), 21 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
index 56f159f76514..9edd862cb4cb 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles-openapi.json
@@ -5166,6 +5166,27 @@
"type": "string"
},
"description": "The processor's configured
options, as attribute\/child-element name to string value"
+
},
+
"state": {
+
"type": "array",
+
"items": {
+
"type": "object",
+
"properties": {
+
"name": {
+
"type": "string",
+
"description": "The
option that holds the state, such as idempotentRepository"
+
},
+
"type": {
+
"type": "string",
+
"description": "The
class name of the repository"
+
},
+
"inMemory": {
+
"type": "boolean",
+
"description": "True
when the repository keeps the state only in memory, so it is lost when the
integration stops (only present when true)"
+
}
+
}
+
},
+
"description": "Where the processor or route
input keeps its state, such as the repository of an idempotent consumer, an
aggregator, or a file consumer with noop=true (only present when it keeps
state)"
}
}
},
@@ -5207,6 +5228,27 @@
"type": "string"
},
"description": "The
processor's configured options, as attribute\/child-element name to string
value"
+
},
+
"state": {
+
"type": "array",
+
"items": {
+
"type":
"object",
+
"properties": {
+
"name":
{
+
"type": "string",
+
"description": "The option that holds the state, such as idempotentRepository"
+
},
+
"type":
{
+
"type": "string",
+
"description": "The class name of the repository"
+
},
+
"inMemory": {
+
"type": "boolean",
+
"description": "True when the repository keeps the state only in memory, so it
is lost when the integration stops (only present when true)"
+
}
+
}
+
},
+
"description": "Where
the processor or route input keeps its state, such as the repository of an
idempotent consumer, an aggregator, or a file consumer with noop=true (only
present when it keeps state)"
}
}
},
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/processor-detail.json
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/processor-detail.json
index 097481df5898..3a5d2d148c75 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/processor-detail.json
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/dev-consoles/processor-detail.json
@@ -62,6 +62,27 @@
"type": "string"
},
"description": "The processor's configured options, as
attribute\/child-element name to string value"
+ },
+ "state": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The option that holds the state, such as
idempotentRepository"
+ },
+ "type": {
+ "type": "string",
+ "description": "The class name of the repository"
+ },
+ "inMemory": {
+ "type": "boolean",
+ "description": "True when the repository keeps the state
only in memory, so it is lost when the integration stops (only present when
true)"
+ }
+ }
+ },
+ "description": "Where the processor or route input keeps its
state, such as the repository of an idempotent consumer, an aggregator, or a
file consumer with noop=true (only present when it keeps state)"
}
}
},
@@ -103,6 +124,27 @@
"type": "string"
},
"description": "The processor's configured options, as
attribute\/child-element name to string value"
+ },
+ "state": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The option that holds the state,
such as idempotentRepository"
+ },
+ "type": {
+ "type": "string",
+ "description": "The class name of the repository"
+ },
+ "inMemory": {
+ "type": "boolean",
+ "description": "True when the repository keeps the
state only in memory, so it is lost when the integration stops (only present
when true)"
+ }
+ }
+ },
+ "description": "Where the processor or route input keeps
its state, such as the repository of an idempotent consumer, an aggregator, or
a file consumer with noop=true (only present when it keeps state)"
}
}
},
diff --git
a/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/state/InMemoryTaskStore.java
b/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/state/InMemoryTaskStore.java
index c6356dfb9634..634dbfdccf13 100644
---
a/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/state/InMemoryTaskStore.java
+++
b/components/camel-ai/camel-a2a/src/main/java/org/apache/camel/component/a2a/state/InMemoryTaskStore.java
@@ -41,6 +41,7 @@ import org.apache.camel.component.a2a.model.TaskState;
import org.apache.camel.component.a2a.model.TaskStatus;
import org.apache.camel.component.a2a.model.TaskStatusUpdateEvent;
import org.apache.camel.component.a2a.util.WebhookUrlValidator;
+import org.apache.camel.spi.InMemoryStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -59,7 +60,7 @@ import org.slf4j.LoggerFactory;
* removes all expired terminal tasks as a backup mechanism.</li>
* </ul>
*/
-public class InMemoryTaskStore implements A2ATaskStore {
+public class InMemoryTaskStore implements A2ATaskStore, InMemoryStrategy {
private static final Logger LOG =
LoggerFactory.getLogger(InMemoryTaskStore.class);
@@ -79,6 +80,11 @@ public class InMemoryTaskStore implements A2ATaskStore {
private volatile int cleanupInterval = 100;
private volatile boolean allowLocalWebhookUrls;
+ @Override
+ public boolean isInMemory() {
+ return true;
+ }
+
// ---- Configuration ----
/**
diff --git
a/components/camel-ai/camel-a2a/src/test/java/org/apache/camel/component/a2a/state/InMemoryTaskStoreTest.java
b/components/camel-ai/camel-a2a/src/test/java/org/apache/camel/component/a2a/state/InMemoryTaskStoreTest.java
index 04f2aa4e6ffc..60629d7ebd13 100644
---
a/components/camel-ai/camel-a2a/src/test/java/org/apache/camel/component/a2a/state/InMemoryTaskStoreTest.java
+++
b/components/camel-ai/camel-a2a/src/test/java/org/apache/camel/component/a2a/state/InMemoryTaskStoreTest.java
@@ -54,6 +54,11 @@ class InMemoryTaskStoreTest {
store = new InMemoryTaskStore();
}
+ @Test
+ void theTasksAreLostWhenTheApplicationStops() {
+ assertThat(store.isInMemory()).isTrue();
+ }
+
@Test
void putAndGet() {
Task task = createTask("task-1", TaskState.SUBMITTED);
diff --git
a/components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/MemorySemanticAuditStore.java
b/components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/MemorySemanticAuditStore.java
index fe312d0701f0..e3bb60f97e0c 100644
---
a/components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/MemorySemanticAuditStore.java
+++
b/components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/MemorySemanticAuditStore.java
@@ -27,10 +27,12 @@ import java.util.Optional;
import java.util.Set;
import java.util.UUID;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.support.service.ServiceSupport;
/** Bounded recent history, lost when the context is destroyed. No
persistent-storage guarantee. */
-public final class MemorySemanticAuditStore extends ServiceSupport implements
SemanticAuditSink, SemanticAuditReader {
+public final class MemorySemanticAuditStore extends ServiceSupport
+ implements SemanticAuditSink, SemanticAuditReader, InMemoryStrategy {
private final int capacity;
private final String epoch = UUID.randomUUID().toString();
private final Deque<Entry> records = new ArrayDeque<>();
@@ -44,6 +46,11 @@ public final class MemorySemanticAuditStore extends
ServiceSupport implements Se
this.capacity = capacity;
}
+ @Override
+ public boolean isInMemory() {
+ return true;
+ }
+
@Override
public Set<String> getSupportedExtensions() {
return SemanticAuditRecord.EXTENSIONS;
diff --git
a/components/camel-ai/camel-semantic/src/test/java/org/apache/camel/semantic/SemanticAuditTest.java
b/components/camel-ai/camel-semantic/src/test/java/org/apache/camel/semantic/SemanticAuditTest.java
index 685064a1d536..2c1c489d03c2 100644
---
a/components/camel-ai/camel-semantic/src/test/java/org/apache/camel/semantic/SemanticAuditTest.java
+++
b/components/camel-ai/camel-semantic/src/test/java/org/apache/camel/semantic/SemanticAuditTest.java
@@ -51,6 +51,11 @@ import static
org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.awaitility.Awaitility.await;
class SemanticAuditTest {
+ @Test
+ void theMemoryStoreLosesItsRecordsWhenTheApplicationStops() {
+ assertThat(new MemorySemanticAuditStore(10).isInMemory()).isTrue();
+ }
+
@ParameterizedTest
@CsvSource({
"false,inherit,false", "false,true,true", "false,false,false",
"true,inherit,true", "true,true,true",
diff --git
a/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/MemoryWebSocketStore.java
b/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/MemoryWebSocketStore.java
index c42eb21c2a3c..43137b1d5ddb 100644
---
a/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/MemoryWebSocketStore.java
+++
b/components/camel-atmosphere-websocket/src/main/java/org/apache/camel/component/atmosphere/websocket/MemoryWebSocketStore.java
@@ -20,6 +20,7 @@ import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
+import org.apache.camel.spi.InMemoryStrategy;
import org.atmosphere.websocket.WebSocket;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -27,7 +28,7 @@ import org.slf4j.LoggerFactory;
/**
*
*/
-public class MemoryWebSocketStore implements WebSocketStore {
+public class MemoryWebSocketStore implements WebSocketStore, InMemoryStrategy {
private static final transient Logger LOG =
LoggerFactory.getLogger(MemoryWebSocketStore.class);
private Map<String, WebSocket> values;
@@ -38,6 +39,11 @@ public class MemoryWebSocketStore implements WebSocketStore {
keys = new ConcurrentHashMap<>();
}
+ @Override
+ public boolean isInMemory() {
+ return true;
+ }
+
/* (non-Javadoc)
* @see org.apache.camel.Service#start()
*/
diff --git
a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/MemoryWebSocketStoreTest.java
b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/MemoryWebSocketStoreTest.java
index 0e9845844afb..9814a25c543e 100644
---
a/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/MemoryWebSocketStoreTest.java
+++
b/components/camel-atmosphere-websocket/src/test/java/org/apache/camel/component/atmosphere/websocket/MemoryWebSocketStoreTest.java
@@ -25,9 +25,16 @@ import org.mockito.Mockito;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
public class MemoryWebSocketStoreTest {
+ @Test
+ void testInMemory() {
+ // the open web sockets are lost when the application stops
+ assertTrue(new MemoryWebSocketStore().isInMemory());
+ }
+
@Test
void testAddAndRemove() {
MemoryWebSocketStore store = new MemoryWebSocketStore();
diff --git
a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/CaffeineKeyValueRepository.java
b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/CaffeineKeyValueRepository.java
index 5e1ea90c326f..5e5315dae6ee 100644
---
a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/CaffeineKeyValueRepository.java
+++
b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/CaffeineKeyValueRepository.java
@@ -28,6 +28,7 @@ import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedOperation;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.KeyValueRepository;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceSupport;
@@ -48,7 +49,7 @@ import org.apache.camel.support.service.ServiceSupport;
annotations = {
"interfaceName=org.apache.camel.spi.KeyValueRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "Caffeine based key-value repository")
-public class CaffeineKeyValueRepository extends ServiceSupport implements
KeyValueRepository {
+public class CaffeineKeyValueRepository extends ServiceSupport implements
KeyValueRepository, InMemoryStrategy {
/**
* Internal value wrapper that carries the per-entry TTL so the custom
{@link Expiry} can read it at insertion time.
@@ -187,6 +188,13 @@ public class CaffeineKeyValueRepository extends
ServiceSupport implements KeyVal
return (int) cache.estimatedSize();
}
+ @Override
+ @ManagedAttribute(description = "Whether the entries are kept only in
memory (lost when the application stops)")
+ public boolean isInMemory() {
+ // a Caffeine cache lives in the heap of this JVM
+ return true;
+ }
+
private static long toTtlNanos(Duration ttl) {
if (ttl == null || ttl.isZero() || ttl.isNegative()) {
return Long.MAX_VALUE;
diff --git
a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/aggregate/CaffeineAggregationRepository.java
b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/aggregate/CaffeineAggregationRepository.java
index eb7b6f200885..1e2d3b7c1b05 100644
---
a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/aggregate/CaffeineAggregationRepository.java
+++
b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/aggregate/CaffeineAggregationRepository.java
@@ -25,8 +25,10 @@ import com.github.benmanes.caffeine.cache.Cache;
import com.github.benmanes.caffeine.cache.Caffeine;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
+import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.RecoverableAggregationRepository;
import org.apache.camel.support.DefaultExchange;
@@ -40,7 +42,8 @@ import org.slf4j.LoggerFactory;
annotations = {
"interfaceName=org.apache.camel.spi.AggregationRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "Caffeine based aggregation repository")
-public class CaffeineAggregationRepository extends ServiceSupport implements
RecoverableAggregationRepository {
+public class CaffeineAggregationRepository extends ServiceSupport
+ implements RecoverableAggregationRepository, InMemoryStrategy {
private static final Logger LOG =
LoggerFactory.getLogger(CaffeineAggregationRepository.class);
@@ -67,6 +70,13 @@ public class CaffeineAggregationRepository extends
ServiceSupport implements Rec
description = "Whether headers on the Exchange that are Java
objects and Serializable should be included and saved to the repository")
private boolean allowSerializedHeaders;
+ @Override
+ @ManagedAttribute(description = "Whether the aggregates are kept only in
memory (lost when the application stops)")
+ public boolean isInMemory() {
+ // a Caffeine cache lives in the heap of this JVM
+ return true;
+ }
+
public CamelContext getCamelContext() {
return camelContext;
}
diff --git
a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/idempotent/CaffeineIdempotentRepository.java
b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/idempotent/CaffeineIdempotentRepository.java
index eb7d4bb944b7..1a0411701cfa 100644
---
a/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/idempotent/CaffeineIdempotentRepository.java
+++
b/components/camel-caffeine/src/main/java/org/apache/camel/component/caffeine/processor/idempotent/CaffeineIdempotentRepository.java
@@ -23,6 +23,7 @@ import org.apache.camel.api.management.ManagedOperation;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceSupport;
@@ -31,7 +32,7 @@ import org.apache.camel.support.service.ServiceSupport;
annotations = {
"interfaceName=org.apache.camel.spi.IdempotentRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "Caffeine based message id repository")
-public class CaffeineIdempotentRepository extends ServiceSupport implements
IdempotentRepository {
+public class CaffeineIdempotentRepository extends ServiceSupport implements
IdempotentRepository, InMemoryStrategy {
private Cache<String, Boolean> cache;
@@ -55,6 +56,13 @@ public class CaffeineIdempotentRepository extends
ServiceSupport implements Idem
return cacheName;
}
+ @Override
+ @ManagedAttribute(description = "Whether the keys are kept only in memory
(lost when the application stops)")
+ public boolean isInMemory() {
+ // a Caffeine cache lives in the heap of this JVM
+ return true;
+ }
+
@Override
@ManagedOperation(description = "Adds the key to the store")
public boolean add(String key) {
diff --git
a/components/camel-caffeine/src/test/java/org/apache/camel/component/caffeine/processor/idempotent/CaffeineIdempotentRepositoryTest.java
b/components/camel-caffeine/src/test/java/org/apache/camel/component/caffeine/processor/idempotent/CaffeineIdempotentRepositoryTest.java
index 5ac84dd2c3ac..a0c5ed3fce63 100644
---
a/components/camel-caffeine/src/test/java/org/apache/camel/component/caffeine/processor/idempotent/CaffeineIdempotentRepositoryTest.java
+++
b/components/camel-caffeine/src/test/java/org/apache/camel/component/caffeine/processor/idempotent/CaffeineIdempotentRepositoryTest.java
@@ -20,6 +20,8 @@ import java.util.UUID;
import com.github.benmanes.caffeine.cache.Cache;
import org.apache.camel.builder.RouteBuilder;
+import
org.apache.camel.component.caffeine.processor.CaffeineKeyValueRepository;
+import
org.apache.camel.component.caffeine.processor.aggregate.CaffeineAggregationRepository;
import org.apache.camel.component.mock.MockEndpoint;
import org.apache.camel.test.junit6.CamelTestSupport;
import org.junit.jupiter.api.Test;
@@ -44,6 +46,14 @@ public class CaffeineIdempotentRepositoryTest extends
CamelTestSupport {
key02 = generateRandomString();
}
+ @Test
+ void testInMemory() {
+ // a Caffeine cache lives in the heap, so the keys are lost when the
application stops
+ assertTrue(repo.isInMemory());
+ assertTrue(new CaffeineAggregationRepository().isInMemory());
+ assertTrue(new CaffeineKeyValueRepository().isInMemory());
+ }
+
@Test
void testAdd() {
// add first key
diff --git
a/components/camel-oauth/src/main/java/org/apache/camel/oauth/InMemorySessionStore.java
b/components/camel-oauth/src/main/java/org/apache/camel/oauth/InMemorySessionStore.java
index 7b6ee0e809e0..883af36d81c9 100644
---
a/components/camel-oauth/src/main/java/org/apache/camel/oauth/InMemorySessionStore.java
+++
b/components/camel-oauth/src/main/java/org/apache/camel/oauth/InMemorySessionStore.java
@@ -25,18 +25,24 @@ import java.util.stream.Collectors;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
+import org.apache.camel.spi.InMemoryStrategy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static org.apache.camel.oauth.OAuth.CAMEL_OAUTH_COOKIE;
import static org.apache.camel.oauth.OAuth.CAMEL_OAUTH_SESSION_ID;
-public class InMemorySessionStore implements OAuthSessionStore {
+public class InMemorySessionStore implements OAuthSessionStore,
InMemoryStrategy {
protected final Logger log = LoggerFactory.getLogger(getClass());
private final Map<String, OAuthSession> sessions = new
ConcurrentHashMap<>();
+ @Override
+ public boolean isInMemory() {
+ return true;
+ }
+
@Override
public Optional<OAuthSession> getSession(Exchange exchange) {
var msg = exchange.getMessage();
diff --git
a/components/camel-oauth/src/test/java/org/apache/camel/oauth/InMemorySessionStoreTest.java
b/components/camel-oauth/src/test/java/org/apache/camel/oauth/InMemorySessionStoreTest.java
new file mode 100644
index 000000000000..d80a11735c29
--- /dev/null
+++
b/components/camel-oauth/src/test/java/org/apache/camel/oauth/InMemorySessionStoreTest.java
@@ -0,0 +1,29 @@
+/*
+ * 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.oauth;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+class InMemorySessionStoreTest {
+
+ @Test
+ void theSessionsAreLostWhenTheApplicationStops() {
+ assertThat(new InMemorySessionStore().isInMemory()).isTrue();
+ }
+}
diff --git
a/core/camel-api/src/main/java/org/apache/camel/spi/InMemoryStrategy.java
b/core/camel-api/src/main/java/org/apache/camel/spi/InMemoryStrategy.java
new file mode 100644
index 000000000000..0f3d380459e5
--- /dev/null
+++ b/core/camel-api/src/main/java/org/apache/camel/spi/InMemoryStrategy.java
@@ -0,0 +1,38 @@
+/*
+ * 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.spi;
+
+/**
+ * A store of state, such as an {@link IdempotentRepository} or an {@link
AggregationRepository}, that tells whether it
+ * keeps its data only in the memory of this JVM. Such data is lost when the
application stops: after a restart an
+ * idempotent consumer lets the same messages through again, a file consumer
with noop=true reads the same files again,
+ * and an aggregator has lost the groups it was building.
+ * <p/>
+ * Only true counts: false means that the data is kept elsewhere, or that the
store cannot tell, such as a cache whose
+ * provider does not say where it keeps its entries. A store that can be
configured either way, such as a cache with or
+ * without a disk tier, or a store that delegates to another store, answers
for the configuration in use.
+ *
+ * @since 4.24
+ */
+public interface InMemoryStrategy {
+
+ /**
+ * Whether the data is kept only in the memory of this JVM, so it is lost
when the application stops; false when the
+ * data is kept elsewhere, or when the store cannot tell.
+ */
+ boolean isInMemory();
+}
diff --git
a/core/camel-console/src/generated/resources/META-INF/org/apache/camel/dev-console/processor-detail.json
b/core/camel-console/src/generated/resources/META-INF/org/apache/camel/dev-console/processor-detail.json
index 097481df5898..3a5d2d148c75 100644
---
a/core/camel-console/src/generated/resources/META-INF/org/apache/camel/dev-console/processor-detail.json
+++
b/core/camel-console/src/generated/resources/META-INF/org/apache/camel/dev-console/processor-detail.json
@@ -62,6 +62,27 @@
"type": "string"
},
"description": "The processor's configured options, as
attribute\/child-element name to string value"
+ },
+ "state": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The option that holds the state, such as
idempotentRepository"
+ },
+ "type": {
+ "type": "string",
+ "description": "The class name of the repository"
+ },
+ "inMemory": {
+ "type": "boolean",
+ "description": "True when the repository keeps the state
only in memory, so it is lost when the integration stops (only present when
true)"
+ }
+ }
+ },
+ "description": "Where the processor or route input keeps its
state, such as the repository of an idempotent consumer, an aggregator, or a
file consumer with noop=true (only present when it keeps state)"
}
}
},
@@ -103,6 +124,27 @@
"type": "string"
},
"description": "The processor's configured options, as
attribute\/child-element name to string value"
+ },
+ "state": {
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties": {
+ "name": {
+ "type": "string",
+ "description": "The option that holds the state,
such as idempotentRepository"
+ },
+ "type": {
+ "type": "string",
+ "description": "The class name of the repository"
+ },
+ "inMemory": {
+ "type": "boolean",
+ "description": "True when the repository keeps the
state only in memory, so it is lost when the integration stops (only present
when true)"
+ }
+ }
+ },
+ "description": "Where the processor or route input keeps
its state, such as the repository of an idempotent consumer, an aggregator, or
a file consumer with noop=true (only present when it keeps state)"
}
}
},
diff --git
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDetailDevConsole.java
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDetailDevConsole.java
index 858f41feebff..db4d31b25cb9 100644
---
a/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDetailDevConsole.java
+++
b/core/camel-console/src/main/java/org/apache/camel/impl/console/ProcessorDetailDevConsole.java
@@ -35,28 +35,52 @@ import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import org.apache.camel.Exchange;
+import org.apache.camel.Route;
import org.apache.camel.api.management.ManagedCamelContext;
+import org.apache.camel.api.management.mbean.ManagedAggregateProcessorMBean;
+import org.apache.camel.api.management.mbean.ManagedIdempotentConsumerMBean;
import org.apache.camel.api.management.mbean.ManagedRouteMBean;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
+import org.apache.camel.spi.PropertyConfigurerGetter;
import org.apache.camel.spi.annotations.DevConsole;
+import org.apache.camel.support.DefaultEndpoint;
import org.apache.camel.support.console.AbstractDevConsole;
import org.apache.camel.util.StringHelper;
import org.apache.camel.util.json.JsonRecordSupport;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
@DevConsole(name = "processor-detail", description = "Show configured options
for all processors in a route")
public class ProcessorDetailDevConsole extends AbstractDevConsole {
+ private static final Logger LOG =
LoggerFactory.getLogger(ProcessorDetailDevConsole.class);
+
@Metadata(label = "query",
description = "The route id to get processor details for (use *
for all routes)",
javaType = "java.lang.String")
public static final String ROUTE_ID = "routeId";
+ /**
+ * The options of a route input that hold the state of its consumer from
one message to the next: the names of the
+ * files a file consumer has read (noop=true, or idempotent=true), the
offsets of a consumer. They are read through
+ * the generated configurer of the endpoint, as camel-console does not
depend on the components.
+ */
+ private static final String[] ENDPOINT_STATE_OPTIONS = {
"idempotentRepository", "offsetRepository" };
+
public record ProcessorEntry(
@Metadata(description = "The processor ID (the id of the from for
the route input, as in the trace and message history)") String id,
@Metadata(description = "The processor type (the XML element name,
or 'from' for the route input)") String type,
@Metadata(description = "The endpoint URI (only present for the
route input entry)") String endpointUri,
@Metadata(description = "The source line number (only present when
known)") Integer line,
- @Metadata(description = "The processor's configured options, as
attribute/child-element name to string value") Map<String, String> options) {
+ @Metadata(description = "The processor's configured options, as
attribute/child-element name to string value") Map<String, String> options,
+ @Metadata(description = "Where the processor or route input keeps
its state, such as the repository of an idempotent consumer, an aggregator, or
a file consumer with noop=true (only present when it keeps state)")
List<StateEntry> state) {
+ }
+
+ public record StateEntry(
+ @Metadata(description = "The option that holds the state, such as
idempotentRepository") String name,
+ @Metadata(description = "The class name of the repository") String
type,
+ @Metadata(description = "True when the repository keeps the state
only in memory, so it is lost when the integration stops (only present when
true)") Boolean inMemory) {
}
public record RouteDetail(
@@ -101,6 +125,12 @@ public class ProcessorDetailDevConsole extends
AbstractDevConsole {
sb.append(String.format(" %s = %s%n",
e.getKey(), e.getValue()));
}
}
+ if (p.state() != null) {
+ for (StateEntry s : p.state()) {
+ sb.append(String.format(" state: %s = %s%s%n",
s.name(), s.type(),
+ Boolean.TRUE.equals(s.inMemory()) ? " (in
memory: lost when the integration stops)" : ""));
+ }
+ }
}
}
}
@@ -139,7 +169,7 @@ public class ProcessorDetailDevConsole extends
AbstractDevConsole {
if (mr == null) {
continue;
}
- RouteDetail routeDetail = buildRouteDetail(mr);
+ RouteDetail routeDetail = buildRouteDetail(mcc, mr);
if (routeDetail != null) {
routes.add(routeDetail);
}
@@ -151,11 +181,11 @@ public class ProcessorDetailDevConsole extends
AbstractDevConsole {
if (mr == null) {
return new Response(null, null, null);
}
- RouteDetail routeDetail = buildRouteDetail(mr);
+ RouteDetail routeDetail = buildRouteDetail(mcc, mr);
return new Response(routeDetail.routeId(), routeDetail.processors(),
null);
}
- private static RouteDetail buildRouteDetail(ManagedRouteMBean mr) {
+ private RouteDetail buildRouteDetail(ManagedCamelContext mcc,
ManagedRouteMBean mr) {
String routeId = mr.getRouteId();
List<ProcessorEntry> processors = new ArrayList<>();
@@ -190,12 +220,79 @@ public class ProcessorDetailDevConsole extends
AbstractDevConsole {
// ignore
}
- ProcessorEntry fromEntry = new ProcessorEntry(fromId, "from",
mr.getEndpointUri(), fromLine, new LinkedHashMap<>());
+ // the repositories the processors keep their state in, which the
route dump does not show when they are defaults
+ processors.replaceAll(p -> withState(p, processorState(mcc, p.id(),
p.type())));
+
+ ProcessorEntry fromEntry = new ProcessorEntry(
+ fromId, "from", mr.getEndpointUri(), fromLine, new
LinkedHashMap<>(), endpointState(routeId));
processors.add(0, fromEntry);
return new RouteDetail(routeId, processors);
}
+ private static ProcessorEntry withState(ProcessorEntry p, List<StateEntry>
state) {
+ return state == null ? p : new ProcessorEntry(p.id(), p.type(),
p.endpointUri(), p.line(), p.options(), state);
+ }
+
+ /**
+ * The repository of an idempotent consumer or an aggregator, from its
managed object: the aggregator creates an
+ * in-memory one when none is configured.
+ */
+ private static List<StateEntry> processorState(ManagedCamelContext mcc,
String id, String type) {
+ try {
+ if ("idempotentConsumer".equals(type)) {
+ ManagedIdempotentConsumerMBean mp =
mcc.getManagedProcessor(id, ManagedIdempotentConsumerMBean.class);
+ if (mp != null && mp.getIdempotentRepositoryClassName() !=
null) {
+ return List.of(new StateEntry(
+ "idempotentRepository",
mp.getIdempotentRepositoryClassName(),
+ onlyTrue(mp.isIdempotentRepositoryInMemory())));
+ }
+ } else if ("aggregate".equals(type)) {
+ ManagedAggregateProcessorMBean mp =
mcc.getManagedProcessor(id, ManagedAggregateProcessorMBean.class);
+ if (mp != null && mp.getAggregationRepositoryClassName() !=
null) {
+ return List.of(new StateEntry(
+ "aggregationRepository",
mp.getAggregationRepositoryClassName(),
+ onlyTrue(mp.isAggregationRepositoryInMemory())));
+ }
+ }
+ } catch (RuntimeException e) {
+ // the JMX proxy wraps what goes wrong, such as a processor that
is not managed, in a runtime exception;
+ // the console still answers, without the state of this processor
+ LOG.debug("Cannot read the state of processor {}: {}", id,
e.getMessage(), e);
+ }
+ return null;
+ }
+
+ /**
+ * The repositories of the route input, such as the one a file consumer
with noop=true creates when none is
+ * configured.
+ */
+ private List<StateEntry> endpointState(String routeId) {
+ Route route = getCamelContext().getRoute(routeId);
+ if (route == null || !(route.getEndpoint() instanceof DefaultEndpoint
endpoint) || endpoint.getComponent() == null
+ || !(endpoint.getComponent().getEndpointPropertyConfigurer()
instanceof PropertyConfigurerGetter getter)) {
+ return null;
+ }
+ List<StateEntry> answer = new ArrayList<>();
+ for (String name : ENDPOINT_STATE_OPTIONS) {
+ Object repository = getter.getOptionValue(endpoint, name, false);
+ if (repository != null) {
+ answer.add(new StateEntry(
+ name, repository.getClass().getName(),
+ onlyTrue(repository instanceof InMemoryStrategy s &&
s.isInMemory())));
+ }
+ }
+ return answer.isEmpty() ? null : answer;
+ }
+
+ /**
+ * Only true counts: false means that the state is kept elsewhere, or that
the repository cannot tell, so it is left
+ * out rather than shown as persistent.
+ */
+ private static Boolean onlyTrue(boolean inMemory) {
+ return inMemory ? Boolean.TRUE : null;
+ }
+
private static void collectProcessors(Element parent, List<ProcessorEntry>
processors) {
NodeList children = parent.getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
@@ -234,7 +331,7 @@ public class ProcessorDetailDevConsole extends
AbstractDevConsole {
// <correlationExpression>, <completionPredicate>, etc.)
collectExpressionChildren(elem, opts);
- processors.add(new ProcessorEntry(id, type, null, line, opts));
+ processors.add(new ProcessorEntry(id, type, null, line, opts,
null));
// recurse into child elements (nested EIPs like split > to,
choice > when > to)
collectProcessors(elem, processors);
diff --git
a/core/camel-console/src/test/java/org/apache/camel/impl/console/ProcessorDetailStateTest.java
b/core/camel-console/src/test/java/org/apache/camel/impl/console/ProcessorDetailStateTest.java
new file mode 100644
index 000000000000..6d3596d1a227
--- /dev/null
+++
b/core/camel-console/src/test/java/org/apache/camel/impl/console/ProcessorDetailStateTest.java
@@ -0,0 +1,188 @@
+/*
+ * 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.impl.console;
+
+import java.util.Map;
+
+import org.apache.camel.ContextTestSupport;
+import org.apache.camel.builder.AggregationStrategies;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.console.DevConsole;
+import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.support.KeyValueIdempotentRepository;
+import org.apache.camel.support.MemoryKeyValueRepository;
+import org.apache.camel.support.PluginHelper;
+import org.apache.camel.support.service.ServiceSupport;
+import org.apache.camel.util.json.JsonArray;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+/**
+ * The processor detail tells where a processor or a route input keeps its
state, and whether the state is kept only in
+ * memory, so it is lost when the integration stops. This includes a
repository that the route does not configure, such
+ * as the one of a file consumer with noop=true (CAMEL-27006).
+ */
+class ProcessorDetailStateTest extends ContextTestSupport {
+
+ @Override
+ protected boolean useJmx() {
+ // the processor-detail console reads the routes and the processors
from JMX
+ return true;
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() {
+ return new RouteBuilder() {
+ @Override
+ public void configure() {
+ from("direct:dedupe").routeId("dedupe")
+ .idempotentConsumer(header("id"), new
KeyValueIdempotentRepository()).id("dedupe1")
+ .to("mock:dedupe");
+ from("direct:custom").routeId("custom")
+ .idempotentConsumer(header("id"), new
MyRepository()).id("custom1")
+ .to("mock:custom");
+ from("direct:persistent").routeId("persistent")
+ .idempotentConsumer(header("id"), new
KeyValueIdempotentRepository(new PersistentStore()))
+ .id("persistent1")
+ .to("mock:persistent");
+ from("direct:aggregate").routeId("aggregate")
+ .aggregate(header("id"),
AggregationStrategies.groupedBody()).completionSize(2).id("aggregate1")
+ .to("mock:aggregate");
+
from(fileUri("?noop=true&initialDelay=0&delay=10")).routeId("files")
+ .to("mock:files");
+ }
+ };
+ }
+
+ @Test
+ void anIdempotentConsumerNamesItsRepository() {
+ JsonObject state = state("dedupe", "dedupe1");
+ Assertions.assertEquals("idempotentRepository",
state.getString("name"));
+ Assertions.assertEquals(KeyValueIdempotentRepository.class.getName(),
state.getString("type"));
+ Assertions.assertEquals(Boolean.TRUE, state.getBoolean("inMemory"));
+ }
+
+ @Test
+ void aRepositoryThatDoesNotTellHasNoInMemory() {
+ JsonObject state = state("custom", "custom1");
+ Assertions.assertEquals(MyRepository.class.getName(),
state.getString("type"));
+ Assertions.assertNull(state.get("inMemory"));
+ }
+
+ @Test
+ void onlyTrueCountsSoARepositoryThatKeepsItsDataElsewhereHasNoInMemory() {
+ // false means kept elsewhere, or cannot tell: it is left out rather
than shown as persistent
+ JsonObject state = state("persistent", "persistent1");
+ Assertions.assertEquals(KeyValueIdempotentRepository.class.getName(),
state.getString("type"));
+ Assertions.assertNull(state.get("inMemory"));
+ }
+
+ @Test
+ void anAggregatorWithoutARepositoryKeepsItsGroupsInMemory() {
+ JsonObject state = state("aggregate", "aggregate1");
+ Assertions.assertEquals("aggregationRepository",
state.getString("name"));
+ Assertions.assertEquals(Boolean.TRUE, state.getBoolean("inMemory"));
+ }
+
+ @Test
+ void aFileConsumerWithNoopKeepsTheNamesOfTheFilesInMemory() {
+ // the route configures no repository: the file consumer creates one
in memory
+ JsonObject from = (JsonObject) processors("files").get(0);
+ Assertions.assertEquals("from", from.getString("type"));
+ JsonObject state = (JsonObject) ((JsonArray) from.get("state")).get(0);
+ Assertions.assertEquals("idempotentRepository",
state.getString("name"));
+
Assertions.assertTrue(state.getString("type").endsWith("MemoryIdempotentRepository"),
state.getString("type"));
+ Assertions.assertEquals(Boolean.TRUE, state.getBoolean("inMemory"));
+ }
+
+ @Test
+ void aProcessorWithoutStateHasNone() {
+ for (Object o : processors("dedupe")) {
+ JsonObject p = (JsonObject) o;
+ if ("to".equals(p.getString("type")) ||
"from".equals(p.getString("type"))) {
+ Assertions.assertNull(p.get("state"), p.getString("type"));
+ }
+ }
+ }
+
+ @Test
+ void theTextSaysThatTheStateIsLostWhenTheIntegrationStops() {
+ DevConsole con =
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("processor-detail");
+ String out = (String) con.call(DevConsole.MediaType.TEXT,
Map.of("routeId", "files"));
+ Assertions.assertTrue(out.contains("state: idempotentRepository = "),
out);
+ Assertions.assertTrue(out.contains("(in memory: lost when the
integration stops)"), out);
+ }
+
+ private JsonArray processors(String routeId) {
+ DevConsole con =
PluginHelper.getDevConsoleResolver(context).resolveDevConsole("processor-detail");
+ JsonObject out = (JsonObject) con.call(DevConsole.MediaType.JSON,
Map.of("routeId", routeId));
+ return (JsonArray) out.get("processors");
+ }
+
+ private JsonObject state(String routeId, String processorId) {
+ for (Object o : processors(routeId)) {
+ JsonObject p = (JsonObject) o;
+ if (processorId.equals(p.getString("id"))) {
+ JsonArray state = (JsonArray) p.get("state");
+ Assertions.assertNotNull(state, processorId + " has no state");
+ return (JsonObject) state.get(0);
+ }
+ }
+ return Assertions.fail("no processor " + processorId + " in route " +
routeId);
+ }
+
+ /**
+ * A key-value store that keeps its data elsewhere, as one with a disk
tier or a database would.
+ */
+ private static class PersistentStore extends MemoryKeyValueRepository {
+ @Override
+ public boolean isInMemory() {
+ return false;
+ }
+ }
+
+ /**
+ * A repository that does not tell whether it keeps its keys only in
memory.
+ */
+ private static class MyRepository extends ServiceSupport implements
IdempotentRepository {
+
+ @Override
+ public boolean add(String key) {
+ return true;
+ }
+
+ @Override
+ public boolean contains(String key) {
+ return false;
+ }
+
+ @Override
+ public boolean remove(String key) {
+ return true;
+ }
+
+ @Override
+ public boolean confirm(String key) {
+ return true;
+ }
+
+ @Override
+ public void clear() {
+ }
+ }
+}
diff --git
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/MemoryAggregationRepository.java
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/MemoryAggregationRepository.java
index 47344e2f87b7..f47b5ce2d9bd 100644
---
a/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/MemoryAggregationRepository.java
+++
b/core/camel-core-processor/src/main/java/org/apache/camel/processor/aggregate/MemoryAggregationRepository.java
@@ -24,6 +24,7 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.OptimisticLockingAggregationRepository;
import org.apache.camel.support.service.ServiceSupport;
@@ -41,7 +42,8 @@ import org.apache.camel.support.service.ServiceSupport;
description = "A memory based AggregationRepository which stores
Exchange in memory only.",
annotations = {
"interfaceName=org.apache.camel.spi.AggregationRepository" })
@Configurer(metadataOnly = true)
-public class MemoryAggregationRepository extends ServiceSupport implements
OptimisticLockingAggregationRepository {
+public class MemoryAggregationRepository extends ServiceSupport
+ implements OptimisticLockingAggregationRepository, InMemoryStrategy {
private final ConcurrentMap<String, Exchange> cache = new
ConcurrentHashMap<>();
@Metadata(description = "Whether to use optimistic locking")
@@ -55,6 +57,11 @@ public class MemoryAggregationRepository extends
ServiceSupport implements Optim
this.optimisticLocking = optimisticLocking;
}
+ @Override
+ public boolean isInMemory() {
+ return true;
+ }
+
public boolean isOptimisticLocking() {
return optimisticLocking;
}
diff --git
a/core/camel-core/src/test/java/org/apache/camel/support/InMemoryStrategyTest.java
b/core/camel-core/src/test/java/org/apache/camel/support/InMemoryStrategyTest.java
new file mode 100644
index 000000000000..dbeeb4f86bb6
--- /dev/null
+++
b/core/camel-core/src/test/java/org/apache/camel/support/InMemoryStrategyTest.java
@@ -0,0 +1,82 @@
+/*
+ * 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.support;
+
+import org.apache.camel.processor.aggregate.MemoryAggregationRepository;
+import org.apache.camel.saga.InMemorySagaService;
+import org.apache.camel.spi.InMemoryStrategy;
+import
org.apache.camel.support.processor.idempotent.MemoryIdempotentRepository;
+import org.apache.camel.support.processor.state.MemoryStateRepository;
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The stores that keep their data only in memory say so, and a store that
delegates answers as the store it delegates
+ * to (CAMEL-27006).
+ */
+class InMemoryStrategyTest {
+
+ /**
+ * A key-value repository that keeps its data elsewhere, as a store
configured with a disk tier or a database would.
+ */
+ private static class PersistentKeyValueRepository extends
MemoryKeyValueRepository {
+ @Override
+ public boolean isInMemory() {
+ return false;
+ }
+ }
+
+ @Test
+ void theMemoryStoresAreInMemory() {
+ assertThat(new MemoryKeyValueRepository().isInMemory()).isTrue();
+ assertThat(new MemoryIdempotentRepository().isInMemory()).isTrue();
+ assertThat(new MemoryAggregationRepository().isInMemory()).isTrue();
+ assertThat(new MemoryStateRepository().isInMemory()).isTrue();
+ assertThat(new InMemorySagaService().isInMemory()).isTrue();
+ }
+
+ @Test
+ void aKeyValueIdempotentRepositoryAnswersAsItsStore() {
+ // without a store of its own it creates a MemoryKeyValueRepository
when it starts
+ assertThat(new KeyValueIdempotentRepository().isInMemory()).isTrue();
+ assertThat(new KeyValueIdempotentRepository(new
MemoryKeyValueRepository()).isInMemory()).isTrue();
+ assertThat(new KeyValueIdempotentRepository(new
PersistentKeyValueRepository()).isInMemory()).isFalse();
+ }
+
+ @Test
+ void aKeyValueAggregationRepositoryAnswersAsItsStore() {
+ assertThat(new KeyValueAggregationRepository().isInMemory()).isTrue();
+ assertThat(new KeyValueAggregationRepository(new
MemoryKeyValueRepository()).isInMemory()).isTrue();
+ assertThat(new KeyValueAggregationRepository(new
PersistentKeyValueRepository()).isInMemory()).isFalse();
+ }
+
+ @Test
+ void aNamespacedRepositoryAnswersAsItsDelegate() {
+ assertThat(new NamespacedKeyValueRepository(new
MemoryKeyValueRepository(), "a").isInMemory()).isTrue();
+ assertThat(new NamespacedKeyValueRepository(new
PersistentKeyValueRepository(), "a").isInMemory()).isFalse();
+ // a store that does not tell is not reported as in memory
+ assertThat(new NamespacedKeyValueRepository().isInMemory()).isFalse();
+ }
+
+ @Test
+ void theAnswerGoesThroughSeveralDelegates() {
+ InMemoryStrategy store = new KeyValueIdempotentRepository(
+ NamespacedKeyValueRepository.namespaced(new
PersistentKeyValueRepository(), "orders"));
+ assertThat(store.isInMemory()).isFalse();
+ }
+}
diff --git
a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedAggregateProcessorMBean.java
b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedAggregateProcessorMBean.java
index 9d8f4704cd1d..42882f0e7a0c 100644
---
a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedAggregateProcessorMBean.java
+++
b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedAggregateProcessorMBean.java
@@ -93,6 +93,12 @@ public interface ManagedAggregateProcessorMBean extends
ManagedProcessorMBean {
@ManagedOperation(description = "Number of groups currently in the
aggregation repository")
int aggregationRepositoryGroups();
+ @ManagedAttribute(description = "The class name of the aggregation
repository")
+ String getAggregationRepositoryClassName();
+
+ @ManagedAttribute(description = "Whether the repository keeps the groups
only in memory (lost when the application stops)")
+ boolean isAggregationRepositoryInMemory();
+
@ManagedOperation(description = "To force completing a specific group by
its key")
int forceCompletionOfGroup(String key);
diff --git
a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedIdempotentConsumerMBean.java
b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedIdempotentConsumerMBean.java
index 2889a3d4a98c..fd0eeacd2813 100644
---
a/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedIdempotentConsumerMBean.java
+++
b/core/camel-management-api/src/main/java/org/apache/camel/api/management/mbean/ManagedIdempotentConsumerMBean.java
@@ -39,6 +39,12 @@ public interface ManagedIdempotentConsumerMBean extends
ManagedProcessorMBean {
@ManagedAttribute(description = "whether to remove or keep the key on
failure")
Boolean isRemoveOnFailure();
+ @ManagedAttribute(description = "The class name of the idempotent
repository")
+ String getIdempotentRepositoryClassName();
+
+ @ManagedAttribute(description = "Whether the repository keeps the keys
only in memory (lost when the application stops)")
+ boolean isIdempotentRepositoryInMemory();
+
@ManagedAttribute(description = "Current count of duplicate Messages")
long getDuplicateMessageCount();
diff --git
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedAggregateProcessor.java
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedAggregateProcessor.java
index dddf5d16c079..85d695d8d7d7 100644
---
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedAggregateProcessor.java
+++
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedAggregateProcessor.java
@@ -23,6 +23,8 @@ import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.api.management.mbean.ManagedAggregateProcessorMBean;
import org.apache.camel.model.AggregateDefinition;
import org.apache.camel.processor.aggregate.AggregateProcessor;
+import org.apache.camel.spi.AggregationRepository;
+import org.apache.camel.spi.InMemoryStrategy;
@ManagedResource(description = "Managed AggregateProcessor")
public class ManagedAggregateProcessor extends ManagedProcessor implements
ManagedAggregateProcessorMBean {
@@ -198,6 +200,17 @@ public class ManagedAggregateProcessor extends
ManagedProcessor implements Manag
}
}
+ @Override
+ public String getAggregationRepositoryClassName() {
+ AggregationRepository repository =
getProcessor().getAggregationRepository();
+ return repository != null ? repository.getClass().getName() : null;
+ }
+
+ @Override
+ public boolean isAggregationRepositoryInMemory() {
+ return getProcessor().getAggregationRepository() instanceof
InMemoryStrategy s && s.isInMemory();
+ }
+
@Override
public int forceCompletionOfGroup(String key) {
if (getProcessor().getAggregateController() != null) {
diff --git
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedIdempotentConsumer.java
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedIdempotentConsumer.java
index 64341bf4c194..df61a97a5612 100644
---
a/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedIdempotentConsumer.java
+++
b/core/camel-management/src/main/java/org/apache/camel/management/mbean/ManagedIdempotentConsumer.java
@@ -21,6 +21,8 @@ import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.api.management.mbean.ManagedIdempotentConsumerMBean;
import org.apache.camel.model.IdempotentConsumerDefinition;
import org.apache.camel.processor.idempotent.IdempotentConsumer;
+import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.spi.InMemoryStrategy;
@ManagedResource(description = "Managed Idempotent Consumer")
public class ManagedIdempotentConsumer extends ManagedProcessor implements
ManagedIdempotentConsumerMBean {
@@ -70,6 +72,17 @@ public class ManagedIdempotentConsumer extends
ManagedProcessor implements Manag
return getProcessor().isRemoveOnFailure();
}
+ @Override
+ public String getIdempotentRepositoryClassName() {
+ IdempotentRepository repository =
getProcessor().getIdempotentRepository();
+ return repository != null ? repository.getClass().getName() : null;
+ }
+
+ @Override
+ public boolean isIdempotentRepositoryInMemory() {
+ return getProcessor().getIdempotentRepository() instanceof
InMemoryStrategy s && s.isInMemory();
+ }
+
@Override
public long getDuplicateMessageCount() {
return getProcessor().getDuplicateMessageCount();
diff --git
a/core/camel-management/src/test/java/org/apache/camel/management/ManagedAggregateControllerTest.java
b/core/camel-management/src/test/java/org/apache/camel/management/ManagedAggregateControllerTest.java
index cdce64023024..f2b8594dc2e3 100644
---
a/core/camel-management/src/test/java/org/apache/camel/management/ManagedAggregateControllerTest.java
+++
b/core/camel-management/src/test/java/org/apache/camel/management/ManagedAggregateControllerTest.java
@@ -106,6 +106,11 @@ public class ManagedAggregateControllerTest extends
ManagementTestSupport {
Integer inflight = (Integer) mbeanServer.getAttribute(on,
"InProgressCompleteExchanges");
assertEquals(0, inflight.intValue());
+ // no repository is configured, so the aggregator keeps the groups in
memory, and says so
+
assertEquals("org.apache.camel.processor.aggregate.MemoryAggregationRepository",
+ mbeanServer.getAttribute(on,
"AggregationRepositoryClassName"));
+ assertEquals(Boolean.TRUE, mbeanServer.getAttribute(on,
"AggregationRepositoryInMemory"));
+
Integer pending = (Integer) mbeanServer.invoke(on,
"aggregationRepositoryGroups", null, null);
assertEquals(0, pending.intValue());
}
diff --git
a/core/camel-management/src/test/java/org/apache/camel/management/ManagedMemoryIdempotentConsumerTest.java
b/core/camel-management/src/test/java/org/apache/camel/management/ManagedMemoryIdempotentConsumerTest.java
index 73b962baf3a8..e7dfd1e2a54f 100644
---
a/core/camel-management/src/test/java/org/apache/camel/management/ManagedMemoryIdempotentConsumerTest.java
+++
b/core/camel-management/src/test/java/org/apache/camel/management/ManagedMemoryIdempotentConsumerTest.java
@@ -59,6 +59,8 @@ public class ManagedMemoryIdempotentConsumerTest extends
ManagementTestSupport {
Integer size = (Integer) mbeanServer.getAttribute(on, "CacheSize");
assertEquals(1, size.intValue());
+ // the keys are lost when the application stops
+ assertEquals(Boolean.TRUE, mbeanServer.getAttribute(on, "InMemory"));
assertFalse(repo.contains("1"));
assertFalse(repo.contains("2"));
@@ -116,6 +118,11 @@ public class ManagedMemoryIdempotentConsumerTest extends
ManagementTestSupport {
Long count = (Long) mbeanServer.getAttribute(on,
"DuplicateMessageCount");
assertEquals(0L, count.longValue());
+ // the idempotent consumer names its repository and says that it keeps
the keys only in memory
+ assertEquals(MemoryIdempotentRepository.class.getName(),
+ mbeanServer.getAttribute(on, "IdempotentRepositoryClassName"));
+ assertEquals(Boolean.TRUE, mbeanServer.getAttribute(on,
"IdempotentRepositoryInMemory"));
+
resultEndpoint.expectedBodiesReceived("one", "two");
sendMessage("1", "one");
diff --git
a/core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaService.java
b/core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaService.java
index bdeef298e2db..63cf81f158c9 100644
---
a/core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaService.java
+++
b/core/camel-support/src/main/java/org/apache/camel/saga/InMemorySagaService.java
@@ -24,6 +24,7 @@ import java.util.concurrent.ScheduledExecutorService;
import org.apache.camel.CamelContext;
import org.apache.camel.Exchange;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.support.service.ServiceSupport;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
@@ -32,7 +33,7 @@ import org.slf4j.LoggerFactory;
/**
* An in-memory implementation of a saga service.
*/
-public class InMemorySagaService extends ServiceSupport implements
CamelSagaService {
+public class InMemorySagaService extends ServiceSupport implements
CamelSagaService, InMemoryStrategy {
private static final Logger LOG =
LoggerFactory.getLogger(InMemorySagaService.class);
@@ -106,6 +107,11 @@ public class InMemorySagaService extends ServiceSupport
implements CamelSagaServ
}
}
+ @Override
+ public boolean isInMemory() {
+ return true;
+ }
+
public ScheduledExecutorService getExecutorService() {
return executorService;
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/KeyValueAggregationRepository.java
b/core/camel-support/src/main/java/org/apache/camel/support/KeyValueAggregationRepository.java
index c8e4028c63e8..09803b9fc18b 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/KeyValueAggregationRepository.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/KeyValueAggregationRepository.java
@@ -25,6 +25,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.Exchange;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.KeyValueRepository;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.RecoverableAggregationRepository;
@@ -53,7 +54,7 @@ import org.slf4j.LoggerFactory;
annotations = {
"interfaceName=org.apache.camel.spi.AggregationRepository" })
@Configurer(metadataOnly = true)
public class KeyValueAggregationRepository extends ServiceSupport
- implements RecoverableAggregationRepository, CamelContextAware {
+ implements RecoverableAggregationRepository, CamelContextAware,
InMemoryStrategy {
private static final Logger LOG =
LoggerFactory.getLogger(KeyValueAggregationRepository.class);
@@ -246,6 +247,16 @@ public class KeyValueAggregationRepository extends
ServiceSupport
this.allowSerializedHeaders = allowSerializedHeaders;
}
+ /**
+ * Whether the aggregates are kept only in memory: when the underlying
{@link KeyValueRepository} keeps its data
+ * only in memory, or when none is set, as the service then creates a
{@link MemoryKeyValueRepository} when it
+ * starts.
+ */
+ @Override
+ public boolean isInMemory() {
+ return repository == null || (repository instanceof InMemoryStrategy s
&& s.isInMemory());
+ }
+
/**
* Returns the underlying {@link KeyValueRepository}.
*/
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/KeyValueIdempotentRepository.java
b/core/camel-support/src/main/java/org/apache/camel/support/KeyValueIdempotentRepository.java
index 8b63359dc89a..14c09fa6cc14 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/KeyValueIdempotentRepository.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/KeyValueIdempotentRepository.java
@@ -18,6 +18,7 @@ package org.apache.camel.support;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.KeyValueRepository;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceHelper;
@@ -41,7 +42,7 @@ import org.apache.camel.util.ObjectHelper;
description = "An IdempotentRepository backed by a
KeyValueRepository (defaults to in-memory).",
annotations = {
"interfaceName=org.apache.camel.spi.IdempotentRepository" })
@Configurer(metadataOnly = true)
-public class KeyValueIdempotentRepository extends ServiceSupport implements
IdempotentRepository {
+public class KeyValueIdempotentRepository extends ServiceSupport implements
IdempotentRepository, InMemoryStrategy {
/**
* Prefix used to namespace idempotent entries, preventing key collisions
when this adapter shares the same
@@ -113,6 +114,15 @@ public class KeyValueIdempotentRepository extends
ServiceSupport implements Idem
}
}
+ /**
+ * Whether the keys are kept only in memory: when the underlying {@link
KeyValueRepository} keeps its data only in
+ * memory, or when none is set, as the service then creates a {@link
MemoryKeyValueRepository} when it starts.
+ */
+ @Override
+ public boolean isInMemory() {
+ return repository == null || (repository instanceof InMemoryStrategy s
&& s.isInMemory());
+ }
+
/**
* Returns the underlying {@link KeyValueRepository}.
*/
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/MemoryKeyValueRepository.java
b/core/camel-support/src/main/java/org/apache/camel/support/MemoryKeyValueRepository.java
index a2b63e82f2b4..d29b8cdec4f9 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/MemoryKeyValueRepository.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/MemoryKeyValueRepository.java
@@ -30,6 +30,7 @@ import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedOperation;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.KeyValueRepository;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceSupport;
@@ -49,7 +50,7 @@ import org.apache.camel.support.service.ServiceSupport;
annotations = {
"interfaceName=org.apache.camel.spi.KeyValueRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "Memory based key-value repository")
-public class MemoryKeyValueRepository extends ServiceSupport implements
KeyValueRepository {
+public class MemoryKeyValueRepository extends ServiceSupport implements
KeyValueRepository, InMemoryStrategy {
private final ConcurrentHashMap<String, Entry> store = new
ConcurrentHashMap<>();
@@ -185,6 +186,12 @@ public class MemoryKeyValueRepository extends
ServiceSupport implements KeyValue
return store.size();
}
+ @Override
+ @ManagedAttribute(description = "Whether the entries are kept only in
memory (lost when the application stops)")
+ public boolean isInMemory() {
+ return true;
+ }
+
@Override
protected void doStop() throws Exception {
store.clear();
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/NamespacedKeyValueRepository.java
b/core/camel-support/src/main/java/org/apache/camel/support/NamespacedKeyValueRepository.java
index b1ba57abb23d..010d1c37aa53 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/NamespacedKeyValueRepository.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/NamespacedKeyValueRepository.java
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Set;
import org.apache.camel.spi.Configurer;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.KeyValueRepository;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.service.ServiceHelper;
@@ -44,7 +45,7 @@ import org.apache.camel.util.ObjectHelper;
description = "A KeyValueRepository that partitions keys using a
namespace prefix.",
annotations = {
"interfaceName=org.apache.camel.spi.KeyValueRepository" })
@Configurer(metadataOnly = true)
-public class NamespacedKeyValueRepository extends ServiceSupport implements
KeyValueRepository {
+public class NamespacedKeyValueRepository extends ServiceSupport implements
KeyValueRepository, InMemoryStrategy {
private KeyValueRepository delegate;
private String prefix;
@@ -103,6 +104,14 @@ public class NamespacedKeyValueRepository extends
ServiceSupport implements KeyV
this.delegate = delegate;
}
+ /**
+ * Whether the entries are kept only in memory, as the delegated {@link
KeyValueRepository} keeps them.
+ */
+ @Override
+ public boolean isInMemory() {
+ return delegate instanceof InMemoryStrategy s && s.isInMemory();
+ }
+
/**
* Returns the namespace applied to all keys.
*/
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 e1b7bfe43551..e1deb407ebfb 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
@@ -26,6 +26,7 @@ import org.apache.camel.api.management.ManagedOperation;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.spi.Configurer;
import org.apache.camel.spi.IdempotentRepository;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.Metadata;
import org.apache.camel.support.LRUCache;
import org.apache.camel.support.LRUCacheFactory;
@@ -47,7 +48,7 @@ import org.apache.camel.support.service.ServiceSupport;
annotations = {
"interfaceName=org.apache.camel.spi.IdempotentRepository" })
@Configurer(metadataOnly = true)
@ManagedResource(description = "Memory based idempotent repository")
-public class MemoryIdempotentRepository extends ServiceSupport implements
IdempotentRepository {
+public class MemoryIdempotentRepository extends ServiceSupport implements
IdempotentRepository, InMemoryStrategy {
private static final int MAX_CACHE_SIZE = 1000;
@@ -180,6 +181,12 @@ public class MemoryIdempotentRepository extends
ServiceSupport implements Idempo
return cacheSize;
}
+ @Override
+ @ManagedAttribute(description = "Whether the keys are kept only in memory
(lost when the application stops)")
+ public boolean isInMemory() {
+ return true;
+ }
+
public void setCacheSize(int cacheSize) {
this.cacheSize = cacheSize;
}
diff --git
a/core/camel-support/src/main/java/org/apache/camel/support/processor/state/MemoryStateRepository.java
b/core/camel-support/src/main/java/org/apache/camel/support/processor/state/MemoryStateRepository.java
index 918f88e16e1d..c45662387b45 100644
---
a/core/camel-support/src/main/java/org/apache/camel/support/processor/state/MemoryStateRepository.java
+++
b/core/camel-support/src/main/java/org/apache/camel/support/processor/state/MemoryStateRepository.java
@@ -19,8 +19,10 @@ package org.apache.camel.support.processor.state;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
+import org.apache.camel.api.management.ManagedAttribute;
import org.apache.camel.api.management.ManagedOperation;
import org.apache.camel.api.management.ManagedResource;
+import org.apache.camel.spi.InMemoryStrategy;
import org.apache.camel.spi.StateRepository;
import org.apache.camel.support.service.ServiceSupport;
@@ -28,10 +30,16 @@ import org.apache.camel.support.service.ServiceSupport;
* This {@link MemoryStateRepository} class is a memory-based implementation
of a {@link StateRepository}.
*/
@ManagedResource(description = "Memory based state repository")
-public class MemoryStateRepository extends ServiceSupport implements
StateRepository<String, String> {
+public class MemoryStateRepository extends ServiceSupport implements
StateRepository<String, String>, InMemoryStrategy {
private final ConcurrentMap<String, String> cache = new
ConcurrentHashMap<>();
+ @Override
+ @ManagedAttribute(description = "Whether the state is kept only in memory
(lost when the application stops)")
+ public boolean isInMemory() {
+ return true;
+ }
+
@Override
@ManagedOperation(description = "Adds the value of the given key to the
store")
public void setState(String key, String value) {