Class InMemoryScheduleStore
- All Implemented Interfaces:
Monitored<List<SerializedMessage>>, HasMessageStore, MessageStore, SchedulingClient, AutoCloseable
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 Summary
ConstructorsConstructorDescriptionInMemoryScheduleStore(Duration messageExpiration) InMemoryScheduleStore(Duration messageExpiration, Clock clock) -
Method Summary
Modifier and TypeMethodDescriptionappend(SerializedMessage... messages) Appends the given messages to the store.append(List<SerializedMessage> messages) Appends a list of messages to the store.asList(Map<Long, String> scheduleIdsByIndex, Serializer serializer) bindScheduleParents(List<String> parentIds) Acquires opaque namespace-local lifetime bindings to existing parents.cancelSchedule(String scheduleId, Guarantee guarantee) Cancel a scheduled message using the provided delivery guarantee.protected voidvoidclose()Default no-op close method.voidconfigureParents(InMemoryEventStore modelStore, Consumer<ScheduleAutoCancelled> metrics) Links scheduling to the namespace's committed Model store and payload-free metrics sink.Returns a batch of schedules that are due for delivery.Returns a batch of schedules from the active schedule index.getFutureSchedules(Serializer serializer) Deserializes and returns schedules after the current clock-derived index boundary without removing them.getSchedule(String scheduleId) Retrieves the serialized schedule associated with the given ID.protected voidpurgeExpiredMessages(Duration messageExpiration) removeExpiredSchedules(Serializer serializer) Removes schedules due by the current clock time, clears their ownership records, and returns their deserialized values.scanBatch(Long minIndex, int maxSize, boolean inclusive, long maxBytes, Predicate<? super SerializedMessage> filter) Scans messages starting from the givenminIndex, returning messages accepted byfilterand metadata about the unfiltered source scan.schedule(Guarantee guarantee, SerializedSchedule... schedules) Schedule one or more serialized schedules with a specifiedGuarantee.scheduleBoundToParents(Guarantee guarantee, Map<String, Long> parents, SerializedSchedule... schedules) Stores schedules with previously acquired bindings, without rebinding recreated parents.voidReplaces the scheduling clock, refreshes clock-change monitoring, resets the minimum schedule index, and notifies monitors.toString()voidtruncate()Removes all messages from this store while keeping the logical log available for future appends.Methods inherited from class InMemoryMessageStore
appendMessages, filterMessages, getBatch, getMessage, messagesFrom, monitorNotificationLock, notifyMonitors, notifyMonitors, registerMonitor, truncateMessagesMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface MessageStore
getBatch, getBatch, getMessageStore, scanBatch, setRetentionTime, unwrapMethods inherited from interface SchedulingClient
cancelSchedule, hasSchedule, schedule, scheduleWithParents
-
Constructor Details
-
InMemoryScheduleStore
public InMemoryScheduleStore() -
InMemoryScheduleStore
-
InMemoryScheduleStore
-
-
Method Details
-
configureParents
public void configureParents(InMemoryEventStore modelStore, Consumer<ScheduleAutoCancelled> metrics) Links scheduling to the namespace's committed Model store and payload-free metrics sink. -
append
Description copied from interface:MessageStoreAppends the given messages to the store.- Specified by:
appendin interfaceMessageStore- Parameters:
messages- messages to append- Returns:
- a
CompletableFuturethat completes when the messages have been successfully appended
-
schedule
Description copied from interface:SchedulingClientSchedule one or more serialized schedules with a specifiedGuarantee.- Specified by:
schedulein interfaceSchedulingClient- 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 selected delivery guarantee is reached.
-
bindScheduleParents
Description copied from interface:SchedulingClientAcquires opaque namespace-local lifetime bindings to existing parents.- Specified by:
bindScheduleParentsin interfaceSchedulingClient
-
scheduleBoundToParents
public CompletableFuture<Void> scheduleBoundToParents(Guarantee guarantee, Map<String, Long> parents, SerializedSchedule... schedules) Description copied from interface:SchedulingClientStores schedules with previously acquired bindings, without rebinding recreated parents.- Specified by:
scheduleBoundToParentsin interfaceSchedulingClient
-
cancelSchedule
Description copied from interface:SchedulingClientCancel a scheduled message using the provided delivery guarantee.- Specified by:
cancelSchedulein interfaceSchedulingClient- Parameters:
scheduleId- The identifier of the schedule to cancel.guarantee- Delivery guarantee for the cancellation request.- Returns:
- A future that completes when the selected delivery guarantee is reached.
-
getSchedule
Description copied from interface:SchedulingClientRetrieves the serialized schedule associated with the given ID.- Specified by:
getSchedulein interfaceSchedulingClient- Parameters:
scheduleId- The ID of the schedule to retrieve.- Returns:
- The matching
SerializedSchedule, ornullif none is found.
-
append
Description copied from interface:MessageStoreAppends a list of messages to the store.- Specified by:
appendin interfaceMessageStore- Overrides:
appendin classInMemoryMessageStore- Parameters:
messages- messages to append- Returns:
- a
CompletableFuturethat completes when the messages have been successfully appended
-
getBatch
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:
getBatchin interfaceMessageStore- Overrides:
getBatchin classInMemoryMessageStore- Parameters:
minIndex- minimum message index to start frommaxSize- maximum number of messages to retrieveinclusive- whether to include the message atminIndex- Returns:
- a list of
SerializedMessageinstances
-
getBatch
public List<SerializedMessage> getBatch(Long minIndex, int maxSize, boolean inclusive, boolean includeFuture) Returns a batch of schedules from the active schedule index.When
includeFutureisfalse, only schedules whose deadline has passed are returned. When it istrue, 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. -
scanBatch
public MessageStoreBatch scanBatch(Long minIndex, int maxSize, boolean inclusive, long maxBytes, Predicate<? super SerializedMessage> filter) Description copied from interface:MessageStoreScans messages starting from the givenminIndex, returning messages accepted byfilterand metadata about the unfiltered source scan.maxSizelimits the number of source messages scanned.maxByteslimits the cumulative complete serialized bytes of accepted messages. If the first accepted message is larger thanmaxBytes, it is still returned so consumers can make progress.- Specified by:
scanBatchin interfaceMessageStore- Overrides:
scanBatchin classInMemoryMessageStore- Parameters:
minIndex- minimum message index to start frommaxSize- maximum number of source messages to scaninclusive- whether to include the message atminIndexmaxBytes- maximum number of accepted complete serialized message bytes, or0for no byte limitfilter- predicate deciding which messages enter the returned batch- Returns:
- accepted messages and source scan metadata
-
setClock
Replaces the scheduling clock, refreshes clock-change monitoring, resets the minimum schedule index, and notifies monitors. -
clockChanged
protected void clockChanged() -
truncate
public void truncate()Description copied from interface:MessageStoreRemoves all messages from this store while keeping the logical log available for future appends.- Specified by:
truncatein interfaceMessageStore- Overrides:
truncatein classInMemoryMessageStore
-
getFutureSchedules
Deserializes and returns schedules after the current clock-derived index boundary without removing them. -
removeExpiredSchedules
Removes schedules due by the current clock time, clears their ownership records, and returns their deserialized values. -
asList
-
purgeExpiredMessages
- Overrides:
purgeExpiredMessagesin classInMemoryMessageStore
-
toString
- Overrides:
toStringin classInMemoryMessageStore
-
close
public void close()Description copied from interface:MessageStoreDefault no-op close method. Override if resources need cleanup.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceMessageStore- Specified by:
closein interfaceSchedulingClient- Overrides:
closein classInMemoryMessageStore
-