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");
 
  • Constructor Details

    • InMemorySnapshotStore

      public InMemorySnapshotStore()
  • Method Details

    • save

      public void save(com.tnsai.context.snapshot.ContextSnapshot snapshot)
      Specified by:
      save in interface com.tnsai.context.snapshot.SnapshotStore
    • findById

      public Optional<com.tnsai.context.snapshot.ContextSnapshot> findById(String snapshotId)
      Specified by:
      findById in interface com.tnsai.context.snapshot.SnapshotStore
    • findLatestByAgent

      public Optional<com.tnsai.context.snapshot.ContextSnapshot> findLatestByAgent(String agentId)
      Specified by:
      findLatestByAgent in interface com.tnsai.context.snapshot.SnapshotStore
    • findByAgent

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByAgent(String agentId)
      Specified by:
      findByAgent in interface com.tnsai.context.snapshot.SnapshotStore
    • findByTrigger

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByTrigger(com.tnsai.context.snapshot.SnapshotTrigger trigger)
      Specified by:
      findByTrigger in interface com.tnsai.context.snapshot.SnapshotStore
    • findByTimeRange

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByTimeRange(Instant start, Instant end)
      Specified by:
      findByTimeRange in interface com.tnsai.context.snapshot.SnapshotStore
    • findByAgentAndTimeRange

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByAgentAndTimeRange(String agentId, Instant start, Instant end)
      Specified by:
      findByAgentAndTimeRange in interface com.tnsai.context.snapshot.SnapshotStore
    • findByConversation

      public List<com.tnsai.context.snapshot.ContextSnapshot> findByConversation(String conversationId)
      Specified by:
      findByConversation in interface com.tnsai.context.snapshot.SnapshotStore
    • delete

      public boolean delete(String snapshotId)
      Specified by:
      delete in interface com.tnsai.context.snapshot.SnapshotStore
    • deleteByAgent

      public int deleteByAgent(String agentId)
      Specified by:
      deleteByAgent in interface com.tnsai.context.snapshot.SnapshotStore
    • deleteOlderThan

      public int deleteOlderThan(Instant before)
      Specified by:
      deleteOlderThan in interface com.tnsai.context.snapshot.SnapshotStore
    • count

      public int count()
      Specified by:
      count in interface com.tnsai.context.snapshot.SnapshotStore
    • countByAgent

      public int countByAgent(String agentId)
      Specified by:
      countByAgent in interface com.tnsai.context.snapshot.SnapshotStore
    • getStatistics

      public com.tnsai.context.snapshot.SnapshotStore.SnapshotStoreStatistics getStatistics()
      Specified by:
      getStatistics in interface com.tnsai.context.snapshot.SnapshotStore
    • clear

      public void clear()
      Clears all snapshots. Useful for testing.