Package com.tnsai.context.snapshot.impl
Class InMemorySnapshotStore
java.lang.Object
com.tnsai.context.snapshot.impl.InMemorySnapshotStore
- All Implemented Interfaces:
com.tnsai.context.snapshot.SnapshotStore
public class InMemorySnapshotStore
extends Object
implements com.tnsai.context.snapshot.SnapshotStore
In-memory implementation of SnapshotStore for development and testing.
This implementation stores snapshots in memory using thread-safe ConcurrentHashMap structures. It is suitable for development, testing, and scenarios where persistence is not required.
Thread Safety
All operations are thread-safe using ConcurrentHashMap.Usage Example
SnapshotStore store = new InMemorySnapshotStore();
// Store snapshot
ContextSnapshot snapshot = ContextSnapshot.builder()
.agentId("agent-1")
.trigger(SnapshotTrigger.PRE_DECISION)
.build();
store.save(snapshot);
// Retrieve
Optional<ContextSnapshot> retrieved = store.findById(snapshot.getSnapshotId());
// Query
List<ContextSnapshot> recent = store.findByAgent("agent-1");
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.tnsai.context.snapshot.SnapshotStore
com.tnsai.context.snapshot.SnapshotStore.SnapshotStoreStatistics -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears all snapshots.intcount()intcountByAgent(String agentId) booleanintdeleteByAgent(String agentId) intdeleteOlderThan(Instant before) List<com.tnsai.context.snapshot.ContextSnapshot> findByAgent(String agentId) List<com.tnsai.context.snapshot.ContextSnapshot> findByAgentAndTimeRange(String agentId, Instant start, Instant end) List<com.tnsai.context.snapshot.ContextSnapshot> findByConversation(String conversationId) Optional<com.tnsai.context.snapshot.ContextSnapshot> List<com.tnsai.context.snapshot.ContextSnapshot> findByTimeRange(Instant start, Instant end) List<com.tnsai.context.snapshot.ContextSnapshot> findByTrigger(com.tnsai.context.snapshot.SnapshotTrigger trigger) Optional<com.tnsai.context.snapshot.ContextSnapshot> findLatestByAgent(String agentId) com.tnsai.context.snapshot.SnapshotStore.SnapshotStoreStatisticsvoidsave(com.tnsai.context.snapshot.ContextSnapshot snapshot)
-
Constructor Details
-
InMemorySnapshotStore
public InMemorySnapshotStore()
-
-
Method Details
-
save
public void save(com.tnsai.context.snapshot.ContextSnapshot snapshot) - Specified by:
savein interfacecom.tnsai.context.snapshot.SnapshotStore
-
findById
- Specified by:
findByIdin interfacecom.tnsai.context.snapshot.SnapshotStore
-
findLatestByAgent
- Specified by:
findLatestByAgentin interfacecom.tnsai.context.snapshot.SnapshotStore
-
findByAgent
- Specified by:
findByAgentin interfacecom.tnsai.context.snapshot.SnapshotStore
-
findByTrigger
public List<com.tnsai.context.snapshot.ContextSnapshot> findByTrigger(com.tnsai.context.snapshot.SnapshotTrigger trigger) - Specified by:
findByTriggerin interfacecom.tnsai.context.snapshot.SnapshotStore
-
findByTimeRange
- Specified by:
findByTimeRangein interfacecom.tnsai.context.snapshot.SnapshotStore
-
findByAgentAndTimeRange
public List<com.tnsai.context.snapshot.ContextSnapshot> findByAgentAndTimeRange(String agentId, Instant start, Instant end) - Specified by:
findByAgentAndTimeRangein interfacecom.tnsai.context.snapshot.SnapshotStore
-
findByConversation
- Specified by:
findByConversationin interfacecom.tnsai.context.snapshot.SnapshotStore
-
delete
- Specified by:
deletein interfacecom.tnsai.context.snapshot.SnapshotStore
-
deleteByAgent
- Specified by:
deleteByAgentin interfacecom.tnsai.context.snapshot.SnapshotStore
-
deleteOlderThan
- Specified by:
deleteOlderThanin interfacecom.tnsai.context.snapshot.SnapshotStore
-
count
public int count()- Specified by:
countin interfacecom.tnsai.context.snapshot.SnapshotStore
-
countByAgent
- Specified by:
countByAgentin interfacecom.tnsai.context.snapshot.SnapshotStore
-
getStatistics
public com.tnsai.context.snapshot.SnapshotStore.SnapshotStoreStatistics getStatistics()- Specified by:
getStatisticsin interfacecom.tnsai.context.snapshot.SnapshotStore
-
clear
public void clear()Clears all snapshots. Useful for testing.
-