Class TransactionBus
java.lang.Object
dev.engine.core.transaction.TransactionBus
Multi-consumer transaction bus with per-subscriber filtering and double-buffered swap.
Logic thread emits transactions via emit(Transaction).
Each subscriber registers interest in specific Component types.
On drain(Object), the subscriber's buffer is swapped and returned —
one lightweight lock per subscriber, minimal contention between emit and drain.
For Transaction.ComponentChanged transactions, the bus filters by the
component's Component.slotType() against the subscriber's registered types.
All other transaction types (e.g., Transaction.EntityAdded) are delivered
to all subscribers.
Thread safety: emit() and drain() are synchronized per-subscriber via the SubscriberState lock. This ensures the logic thread (emit) and render thread (drain/swap) never access the write buffer concurrently.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionDrains all pending transactions for the given subscriber.voidemit(Transaction txn) Emits a transaction.final voidRegisters a subscriber with interest in the given component types.voidunsubscribe(Object subscriberKey) Removes a subscriber, freeing its buffers.
-
Constructor Details
-
TransactionBus
public TransactionBus()
-
-
Method Details
-
subscribe
@SafeVarargs public final void subscribe(Object subscriberKey, Class<? extends Component>... componentTypes) Registers a subscriber with interest in the given component types. ComponentChanged transactions are filtered by these types. EntityAdded/EntityRemoved and all other types are always delivered. If no component types are specified, all transactions are delivered. -
unsubscribe
Removes a subscriber, freeing its buffers. -
emit
Emits a transaction. For ComponentChanged, only subscribers interested in that component's slotType receive it (unless the subscriber has no filter). All other types go to all subscribers. -
drain
Drains all pending transactions for the given subscriber. Swaps the double buffer under a lock, returns the read buffer. The returned list is safe to iterate while the logic thread continues emitting.
-