Class InMemoryEventStore

java.lang.Object
io.fluxzero.sdk.tracking.client.InMemoryMessageStore
io.fluxzero.sdk.persisting.eventsourcing.client.InMemoryEventStore
All Implemented Interfaces:
EventStoreClient, AutoCloseable

public class InMemoryEventStore extends InMemoryMessageStore implements EventStoreClient
An implementation of the EventStoreClient interface that provides an in-memory event storage solution. This class extends InMemoryMessageStore to inherit message store functionality and provides additional capabilities for storing, retrieving, updating, and managing aggregate event streams and relationships in memory.

It is designed for use cases where events and relationships are stored and maintained in the application memory, which makes it lightweight but volatile. The stored data will not persist beyond the lifetime of the application process and is typically used in test scenarios or for development purposes.

  • Constructor Details

    • InMemoryEventStore

      public InMemoryEventStore()
    • InMemoryEventStore

      public InMemoryEventStore(Duration messageExpiration)
  • Method Details

    • setModelGraphProjectionMaterializer

      public void setModelGraphProjectionMaterializer(InMemoryEventStore.ModelGraphProjectionMaterializer materializer)
      Links the SDK-only event store to its in-memory search materializer.
    • setModelCommitMaterializer

      public void setModelCommitMaterializer(InMemoryEventStore.ModelCommitMaterializer materializer)
      Links the SDK-only event store to the direct in-memory model materializer.
    • storeEvents

      public CompletableFuture<Void> storeEvents(String aggregateId, List<io.fluxzero.common.api.SerializedMessage> events, boolean storeOnly, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: EventStoreClient
      Stores events for a given aggregate with an explicit guarantee.
      Specified by:
      storeEvents in interface EventStoreClient
      Parameters:
      aggregateId - The aggregate ID.
      events - Events to store.
      storeOnly - If true, events will not be published.
      guarantee - The guarantee level for this operation.
      Returns:
      A future representing completion of the store operation.
    • commitModels

      public CompletableFuture<io.fluxzero.common.api.modeling.CommitModelsResult> commitModels(io.fluxzero.common.api.modeling.CommitModels commit)
      Description copied from interface: EventStoreClient
      Atomically commits the ordered state transitions of one independent-model commit.

      Unlike aggregate event appends, this operation returns the runtime-assigned state, event, and per-model stream positions. Implementations predating independent models remain source-compatible and fail only when this capability is invoked.

      Specified by:
      commitModels in interface EventStoreClient
      Parameters:
      commit - complete model commit with its durable idempotency key
      Returns:
      durable result containing the positions assigned by the event store
    • notifyMonitors

      protected void notifyMonitors(List<io.fluxzero.common.api.SerializedMessage> messages)
      Overrides:
      notifyMonitors in class InMemoryMessageStore
    • trackModelUpdates

      public CompletableFuture<io.fluxzero.common.api.modeling.TrackModelUpdatesResult> trackModelUpdates(io.fluxzero.common.api.modeling.TrackModelUpdates request)
      Description copied from interface: EventStoreClient
      Long-polls committed independent-model commit substeps after a client-controlled state cursor.
      Specified by:
      trackModelUpdates in interface EventStoreClient
    • registerModelGraphProjection

      public CompletableFuture<io.fluxzero.common.api.modeling.ModelGraphProjectionStatus> registerModelGraphProjection(io.fluxzero.common.api.modeling.RegisterModelGraphProjection request)
      Description copied from interface: EventStoreClient
      Idempotently registers an asynchronous materialized model-graph projection.
      Specified by:
      registerModelGraphProjection in interface EventStoreClient
    • getModelGraphProjectionStatus

      public io.fluxzero.common.api.modeling.ModelGraphProjectionStatus getModelGraphProjectionStatus(io.fluxzero.common.api.modeling.GetModelGraphProjectionStatus request)
      Description copied from interface: EventStoreClient
      Returns the current high-watermark and backlog for one materialized graph projection.
      Specified by:
      getModelGraphProjectionStatus in interface EventStoreClient
    • awaitModelGraphProjection

      public CompletableFuture<io.fluxzero.common.api.modeling.ModelGraphProjectionStatus> awaitModelGraphProjection(io.fluxzero.common.api.modeling.AwaitModelGraphProjection request)
      Description copied from interface: EventStoreClient
      Completes after every affected root in a graph projection has crossed the requested committed state boundary.
      Specified by:
      awaitModelGraphProjection in interface EventStoreClient
    • planModelDeletion

      public io.fluxzero.common.api.modeling.ModelDeletionPlan planModelDeletion(io.fluxzero.common.api.modeling.PlanModelDeletion request)
      Description copied from interface: EventStoreClient
      Creates a bounded, non-mutating plan for an explicit independent-model hard deletion.
      Specified by:
      planModelDeletion in interface EventStoreClient
    • deleteModel

      public CompletableFuture<io.fluxzero.common.api.modeling.ModelDeletionResult> deleteModel(io.fluxzero.common.api.modeling.DeleteModel request)
      Description copied from interface: EventStoreClient
      Executes or resumes an idempotent independent-model hard deletion.
      Specified by:
      deleteModel in interface EventStoreClient
    • getModelEvents

      public io.fluxzero.common.api.modeling.GetModelEventsResult getModelEvents(io.fluxzero.common.api.modeling.GetModelEvents request)
      Description copied from interface: EventStoreClient
      Batch-loads independent model heads and event memberships at one pinned state boundary.
      Specified by:
      getModelEvents in interface EventStoreClient
    • getModelGraph

      public io.fluxzero.common.api.modeling.GetModelGraphResult getModelGraph(io.fluxzero.common.api.modeling.GetModelGraph request)
      Description copied from interface: EventStoreClient
      Loads one bounded temporal model graph and an optional first page of its grouped model streams.
      Specified by:
      getModelGraph in interface EventStoreClient
    • getModelChange

      public io.fluxzero.common.api.modeling.GetModelChangeResult getModelChange(io.fluxzero.common.api.modeling.GetModelChange request)
      Description copied from interface: EventStoreClient
      Resolves the durable targets of one model-commit substep.
      Specified by:
      getModelChange in interface EventStoreClient
    • resolveRelatedModels

      public Set<String> resolveRelatedModels(Set<String> relatedModelIds, io.fluxzero.common.api.search.ModelRelationConstraint constraint)
      Resolves target model IDs from related document matches at the current relationship boundary.
    • resolveCurrentGraph

      public List<io.fluxzero.common.api.modeling.ModelGraphEdge> resolveCurrentGraph(Set<String> rootModelIds, io.fluxzero.common.api.search.ModelGraphComposition composition)
      Resolves explicitly placed current child edges for one page of root search results.
    • resolveModelDocumentCollections

      public Map<String,String> resolveModelDocumentCollections(Set<String> modelIds)
      Resolves the exact current-document collection for each requested model.
    • updateRelationships

      public CompletableFuture<Void> updateRelationships(io.fluxzero.common.api.modeling.UpdateRelationships request)
      Description copied from interface: EventStoreClient
      Updates entity relationships in the event store (e.g. parent-child, references).
      Specified by:
      updateRelationships in interface EventStoreClient
      Parameters:
      request - The update request.
      Returns:
      A future that completes when the operation is acknowledged.
    • repairRelationships

      public CompletableFuture<Void> repairRelationships(io.fluxzero.common.api.modeling.RepairRelationships request)
      Description copied from interface: EventStoreClient
      Repairs entity relationships, e.g. by forcing re-evaluation of existing relationships.
      Specified by:
      repairRelationships in interface EventStoreClient
      Parameters:
      request - The repair request.
      Returns:
      A future that completes when the repair is done.
    • getEvents

      public AggregateEventStream<io.fluxzero.common.api.SerializedMessage> getEvents(String aggregateId, long lastSequenceNumber, int maxSize)
      Description copied from interface: EventStoreClient
      Retrieves the event stream for an aggregate with control over size and offset.
      Specified by:
      getEvents in interface EventStoreClient
      Parameters:
      aggregateId - The aggregate ID.
      lastSequenceNumber - Sequence number to resume after.
      maxSize - Maximum number of events to return (or -1 for unlimited).
      Returns:
      A stream of serialized events.
    • deleteEvents

      public CompletableFuture<Void> deleteEvents(String aggregateId, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: EventStoreClient
      Deletes all events for a specific aggregate with a given delivery guarantee.
      Specified by:
      deleteEvents in interface EventStoreClient
      Parameters:
      aggregateId - The aggregate ID.
      guarantee - The guarantee to apply.
      Returns:
      A future that completes when deletion is acknowledged.
    • getAggregateIds

      public Map<String,String> getAggregateIds(io.fluxzero.common.api.modeling.GetAggregateIds request)
      Description copied from interface: EventStoreClient
      Gets aggregate IDs based on a GetAggregateIds request.
      Specified by:
      getAggregateIds in interface EventStoreClient
      Parameters:
      request - The request containing filtering options.
      Returns:
      A map of aggregate IDs referencing the target entity.
    • getRelationships

      public List<io.fluxzero.common.api.modeling.Relationship> getRelationships(io.fluxzero.common.api.modeling.GetRelationships request)
      Description copied from interface: EventStoreClient
      Gets relationships based on a GetRelationships request.
      Specified by:
      getRelationships in interface EventStoreClient
      Parameters:
      request - The request containing filter parameters.
      Returns:
      A list of matching relationships.
    • toString

      public String toString()
      Overrides:
      toString in class InMemoryMessageStore
    • append

      default CompletableFuture<Void> append(io.fluxzero.common.api.SerializedMessage... arg0)
    • getBatch

      default List<io.fluxzero.common.api.SerializedMessage> getBatch(Long arg0, int arg1)
    • getBatch

      default List<io.fluxzero.common.api.SerializedMessage> getBatch(Long arg0, int arg1, long arg2)
    • scanBatch

      default io.fluxzero.common.tracking.MessageStoreBatch scanBatch(Long arg0, int arg1, boolean arg2, long arg3, Predicate<? super io.fluxzero.common.api.SerializedMessage> arg4, boolean arg5)
    • setRetentionTime

      void setRetentionTime(Duration arg0)
    • unwrap

      default <T extends io.fluxzero.common.tracking.MessageStore> T unwrap(Class<T> arg0)
    • getMessageStore

      default io.fluxzero.common.tracking.MessageStore getMessageStore()