Class Heart
- All Implemented Interfaces:
JobObserver<HeartbeatEvent>, Stoppable
Heartbeats off the bus into
the HeartbeatStore, and fires due entries as ordinary job submissions under
the authority captured at schedule time. Two virtual threads by design - the bus's
per-subscriber queue thread does only fast in-memory store work, and the dispatch
thread parks until the next due instant (LockSupport.parkUntil), unparked by
the store's change notification. Spurious wakes cost one peek and a re-park.
Catch-up semantics: slots are fixed from the original anchor, so after a pause (GC, laptop sleep, suspended container) every overdue slot fires back-to-back. The burst is deliberate - a silently skipped slot would be behavior an operator has to reverse-engineer; the burst is self-explanatory in the HeartbeatFired timestamps.
Fires go through the REAL submission door: the captured ScopeGuard plays the caller-guard role in the same
judgment-and-merge every live submission passes, so a fired flow cannot hold wider
scope than its scheduler. A fire failure publishes HeartbeatFireFailed and,
for recurring entries, still enqueues the next instance - one bad fire never kills a
cadence. A Heart that is stopping drops every request and cancellation it is handed,
with a warning naming the message: the store is closing and a late schedule would
outlive it.
- Since:
- 0.1 (2026-08-29)
- Author:
- Andrey Santrosyan
-
Method Summary
Modifier and TypeMethodDescriptionprotected voiddoStop()Performs the actual shutdown logic.Returns a predicate for filtering events at the MessageBus level.getStore()The store, for operator inspection (inspect()) and cancellation surfaces.voidobserve(HeartbeatEvent event) Process a job event.Methods inherited from class AbstractStoppable
isStopping, stopMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface JobObserver
isStale
-
Method Details
-
getStore
The store, for operator inspection (inspect()) and cancellation surfaces. -
getPredicate
Description copied from interface:JobObserverReturns a predicate for filtering events at the MessageBus level. Called once during subscription.- Specified by:
getPredicatein interfaceJobObserver<HeartbeatEvent>- Returns:
- predicate to filter events, or null to accept all events of type T
-
observe
Description copied from interface:JobObserverProcess a job event. Runs in a separate virtual thread. Must handle its own resources and exceptions.- Specified by:
observein interfaceJobObserver<HeartbeatEvent>- Parameters:
event- the job event to process
-
doStop
protected void doStop()Description copied from class:AbstractStoppablePerforms the actual shutdown logic.Called exactly once when
AbstractStoppable.stop()is first invoked. At this pointAbstractStoppable.isStopping()already returns true.- Specified by:
doStopin classAbstractStoppable
-