Class EventBuffer
- All Implemented Interfaces:
QueryEventListener
QueryEventListener that retains what it observes
so the feed can be read back instead of only printed.
The listener seam is a push port: a producer calls
onEvent(QueryEvent) and the event is gone unless someone held on to
it. A buffer holds on to it, which is what lets a temporal feed be surfaced as
a relation — the bridge between "what happened during that run" and "what can
be queried now". Nothing here knows about relations or the catalog; it is a
listener that remembers, and the mapping to columns lives in the consumer.
Bounded by construction
A buffer never grows without limit: at capacity() events the
oldest is evicted to make room, and droppedCount() records how many
were lost that way. An unbounded collector attached to a long-lived session
would be a slow leak whose size is set by how much the user runs, so the cap
is not configurable per event — it is the point of the type. When events have
been dropped, the retained feed is the most recent window, not the
whole run.
Ordering
events() returns the retained events oldest-first, in the order
they were observed. A QueryEvent carries no timestamp, so this arrival
order is the only temporal fact the feed has; consumers that need a stable
sort key derive it from the position.
Thread safety
Every method is synchronized on the buffer, so producers may emit from any
thread — a REPL evaluating on a worker while the shell reads back, or an
executor emitting as a stream is drained. events() returns an
immutable snapshot, so a reader is never exposed to a concurrent append.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intRetained-event cap used byEventBuffer()(1000).Fields inherited from interface com.darkcollective.relix.events.QueryEventListener
NONE -
Constructor Summary
ConstructorsConstructorDescriptionCreates a buffer retaining up toDEFAULT_CAPACITYevents.EventBuffer(int capacity) Creates a buffer retaining up tocapacityevents. -
Method Summary
Modifier and TypeMethodDescriptionintcapacity()Returns the maximum number of events this buffer retains.voidclear()Discards every retained event and resetsdroppedCount()— used to start a fresh observation window.longReturns how many events were evicted to stay withincapacity()since the lastclear().events()Returns the retained events, oldest first.voidonEvent(QueryEvent event) Called once per observed decision.intsize()Returns the number of events currently retained.
-
Field Details
-
DEFAULT_CAPACITY
public static final int DEFAULT_CAPACITYRetained-event cap used byEventBuffer()(1000).- See Also:
-
-
Constructor Details
-
EventBuffer
public EventBuffer()Creates a buffer retaining up toDEFAULT_CAPACITYevents. -
EventBuffer
public EventBuffer(int capacity) Creates a buffer retaining up tocapacityevents.- Parameters:
capacity- the maximum number of events retained; must be positive- Throws:
IllegalArgumentException- ifcapacityis not positive
-
-
Method Details
-
onEvent
Description copied from interface:QueryEventListenerCalled once per observed decision. Implementations should be fast and must not throw — an emitter is not expected to guard against listener failures.- Specified by:
onEventin interfaceQueryEventListener- Parameters:
event- the event; never null
-
events
Returns the retained events, oldest first.- Returns:
- an immutable snapshot of the retained feed; never null
-
clear
public void clear()Discards every retained event and resetsdroppedCount()— used to start a fresh observation window. -
droppedCount
public long droppedCount()Returns how many events were evicted to stay withincapacity()since the lastclear().- Returns:
- the number of dropped events; zero when nothing overflowed
-
size
public int size()Returns the number of events currently retained.- Returns:
- the retained count, never greater than
capacity()
-
capacity
public int capacity()Returns the maximum number of events this buffer retains.- Returns:
- the capacity given at construction
-