|
lintel 0.2.0
|
#include <EventBus.h>
Static Public Member Functions | |
| static std::size_t | requiredSize (const EventBusConfig &config) |
Lock-free, IPC-capable event bus living inside a shared memory segment.
The bus offers two delivery modes:
All queues are strictly bounded, lock-free MPMC ring buffers with fixed capacity that live inside the shared memory segment. They are IPC-safe: the node buffers are addressed relative to the bus object, so they remain valid regardless of the virtual address a process mapped the segment at. The topic/subscriber registry is guarded by a short spin lock that tolerates crashed processes.
The class is stored inside the shared memory segment and therefore must not use virtual functions (vtable pointers would point into the process that constructed the bus). The abstract IEventBus is provided for the local service layer.
| lintel::EventBus::EventBus | ( | const std::string & | name, |
| const EventBusConfig & | config, | ||
| ShmSegmentAccessor | segment | ||
| ) |
Construct an EventBus. The constructor is only executed when the bus is created for the first time in the segment; later processes find the already constructed object.
| name | the name of the bus |
| config | the runtime configuration |
| segment | accessor to the segment to allocate the queues from |
| std::invalid_argument | if the configuration is invalid |
| lintel::EventBus::~EventBus | ( | ) |
Destroys the per-subscriber queues.
| std::uint64_t lintel::EventBus::droppedEventsOf | ( | ) | const |
| EventBusConfig lintel::EventBus::getConfig | ( | ) | const |
| bool lintel::EventBus::isEmpty | ( | ) | const |
| subscriber | the subscriber name |
| bool lintel::EventBus::isLockFree | ( | ) | const |
| bool lintel::EventBus::isSubscribed | ( | const std::string & | topic, |
| const std::string & | subscriber | ||
| ) | const |
| topic | the topic name |
| subscriber | the subscriber name |
| topic | the topic name |
| std::size_t lintel::EventBus::numberOfSubscribersOf | ( | const std::string & | topic | ) | const |
| topic | the topic name |
Publish an event into the point-to-point bus queue.
| event | the event to publish |
Publish an event to every subscriber of the event topic.
| event | the event to publish |
| std::optional< Event > lintel::EventBus::receive | ( | ) |
Receive the next event from the point-to-point bus queue.
Receive the next event of a subscriber queue.
| subscriber | the subscriber name |
Register a topic on the bus (idempotent).
| topic | the topic name |
|
static |
Compute the shared memory size needed for a given configuration.
| config | the runtime configuration |
| void lintel::EventBus::reset | ( | ) |
Drop all queued events on the bus and every subscriber queue.
| std::int64_t lintel::EventBus::sequenceOf | ( | ) | const |
Subscribe a named subscriber to a topic.
| topic | the topic name |
| subscriber | the subscriber name |
| std::size_t lintel::EventBus::subscriberCount | ( | ) | const |
| std::size_t lintel::EventBus::topicCount | ( | ) | const |
Unsubscribe a named subscriber from a topic.
| topic | the topic name |
| subscriber | the subscriber name |