Class InMemoryScheduleStore

java.lang.Object
io.fluxzero.sdk.tracking.client.InMemoryMessageStore
io.fluxzero.sdk.scheduling.client.InMemoryScheduleStore
All Implemented Interfaces:
Monitored<List<SerializedMessage>>, HasMessageStore, MessageStore, 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(SerializedMessage... messages)
      Description copied from interface: MessageStore
      Appends the given messages to the store.
      Specified by:
      append in interface MessageStore
      Parameters:
      messages - messages to append
      Returns:
      a CompletableFuture that completes when the messages have been successfully appended
    • schedule

      public CompletableFuture<Void> schedule(Guarantee guarantee, 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, 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 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<SerializedMessage> messages)
      Description copied from interface: MessageStore
      Appends a list of messages to the store.
      Specified by:
      append in interface MessageStore
      Overrides:
      append in class InMemoryMessageStore
      Parameters:
      messages - messages to append
      Returns:
      a CompletableFuture that completes when the messages have been successfully appended
    • getBatch

      public List<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.

      Specified by:
      getBatch in interface MessageStore
      Overrides:
      getBatch in class InMemoryMessageStore
      Parameters:
      minIndex - minimum message index to start from
      maxSize - maximum number of messages to retrieve
      inclusive - whether to include the message at minIndex
      Returns:
      a list of SerializedMessage instances
    • getBatch

      public List<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)
    • 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