Class InMemoryScheduleStore

java.lang.Object
io.fluxzero.sdk.tracking.client.InMemoryMessageStore
io.fluxzero.sdk.scheduling.client.InMemoryScheduleStore
All Implemented Interfaces:
SchedulingClient, AutoCloseable

public class InMemoryScheduleStore extends InMemoryMessageStore implements SchedulingClient
An in-memory implementation of a scheduling store that allows the scheduling, retrieval, and management of scheduled messages. It extends `InMemoryMessageStore` to reuse the functionalities for storing and managing messages and implements `SchedulingClient` to support scheduling-specific operations.

This implementation provides thread-safe mechanisms for scheduling, retrieving, and cancelling messages. Messages are scheduled to be processed at specific timestamps, with support for expiration and filtering of schedules.

  • Constructor Details

    • InMemoryScheduleStore

      public InMemoryScheduleStore()
    • InMemoryScheduleStore

      public InMemoryScheduleStore(Duration messageExpiration)
  • Method Details

    • append

      public CompletableFuture<Void> append(io.fluxzero.common.api.SerializedMessage... messages)
    • schedule

      public CompletableFuture<Void> schedule(io.fluxzero.common.Guarantee guarantee, io.fluxzero.common.api.scheduling.SerializedSchedule... schedules)
      Description copied from interface: SchedulingClient
      Schedule one or more serialized schedules with a specified Guarantee.
      Specified by:
      schedule in interface SchedulingClient
      Parameters:
      guarantee - Delivery guarantee to apply (e.g., none, sent, stored).
      schedules - One or more schedules to register.
      Returns:
      A future that completes when the scheduling is acknowledged.
    • cancelSchedule

      public CompletableFuture<Void> cancelSchedule(String scheduleId, io.fluxzero.common.Guarantee guarantee)
      Description copied from interface: SchedulingClient
      Cancel a scheduled message using the provided delivery guarantee.
      Specified by:
      cancelSchedule in interface SchedulingClient
      Parameters:
      scheduleId - The identifier of the schedule to cancel.
      guarantee - Delivery guarantee for the cancellation request.
      Returns:
      A future that completes when the cancellation is processed.
    • getSchedule

      public io.fluxzero.common.api.scheduling.SerializedSchedule getSchedule(String scheduleId)
      Description copied from interface: SchedulingClient
      Retrieves the serialized schedule associated with the given ID.
      Specified by:
      getSchedule in interface SchedulingClient
      Parameters:
      scheduleId - The ID of the schedule to retrieve.
      Returns:
      The matching SerializedSchedule, or null if none is found.
    • append

      public CompletableFuture<Void> append(List<io.fluxzero.common.api.SerializedMessage> messages)
      Overrides:
      append in class InMemoryMessageStore
    • getBatch

      public List<io.fluxzero.common.api.SerializedMessage> getBatch(Long minIndex, int maxSize, boolean inclusive)
      Returns a batch of schedules that are due for delivery.

      Unlike a regular message store, this schedule store only exposes entries whose deadline has passed and whose schedule id is still active.

      Overrides:
      getBatch in class InMemoryMessageStore
    • getBatch

      public List<io.fluxzero.common.api.SerializedMessage> getBatch(Long minIndex, int maxSize, boolean inclusive, boolean includeFuture)
      Returns a batch of schedules from the active schedule index.

      When includeFuture is false, only schedules whose deadline has passed are returned. When it is true, future schedules are also included. This is used by the test server to discover the next hidden deadline and wake waiting trackers as soon as that deadline expires.

    • setClock

      public void setClock(@NonNull @NonNull Clock clock)
    • truncate

      public void truncate()
      Overrides:
      truncate in class InMemoryMessageStore
    • getFutureSchedules

      public List<Schedule> getFutureSchedules(Serializer serializer)
    • removeExpiredSchedules

      public List<Schedule> removeExpiredSchedules(Serializer serializer)
    • asList

      protected List<Schedule> asList(Map<Long,String> scheduleIdsByIndex, Serializer serializer)
    • purgeExpiredMessages

      protected void purgeExpiredMessages(Duration messageExpiration)
      Overrides:
      purgeExpiredMessages in class InMemoryMessageStore
    • toString

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

      default List<io.fluxzero.common.api.SerializedMessage> getBatch(Long arg0, int arg1)
    • 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()