pub struct TopicRouter { /* private fields */ }Expand description
Pub/sub topic router for kernel IPC.
Manages subscriptions as a mapping from topic name to list of
subscriber PIDs. Uses DashMap for lock-free concurrent access.
§Dead subscriber cleanup
When a message is published, the router checks each subscriber’s state in the process table. Subscribers that have exited are automatically removed from the subscription list (lazy cleanup).
Implementations§
Source§impl TopicRouter
impl TopicRouter
Sourcepub fn new(process_table: Arc<ProcessTable>) -> Self
pub fn new(process_table: Arc<ProcessTable>) -> Self
Create a new topic router.
Sourcepub fn subscribe(&self, pid: Pid, topic: &str)
pub fn subscribe(&self, pid: Pid, topic: &str)
Subscribe a process to a topic.
If the process is already subscribed, this is a no-op.
Sourcepub fn unsubscribe(&self, pid: Pid, topic: &str)
pub fn unsubscribe(&self, pid: Pid, topic: &str)
Unsubscribe a process from a topic.
If the process is not subscribed, this is a no-op. Empty subscription lists are removed.
Sourcepub fn live_subscribers(&self, topic: &str) -> Vec<Pid> ⓘ
pub fn live_subscribers(&self, topic: &str) -> Vec<Pid> ⓘ
Get the list of running subscribers for a topic.
Performs lazy cleanup: removes PIDs for processes that have exited. Returns only PIDs of running processes.
Sourcepub fn subscribers(&self, topic: &str) -> Vec<Pid> ⓘ
pub fn subscribers(&self, topic: &str) -> Vec<Pid> ⓘ
Get all subscribers for a topic (including potentially dead ones).
Use TopicRouter::live_subscribers for a filtered list.
Sourcepub fn list_topics(&self) -> Vec<(String, usize)>
pub fn list_topics(&self) -> Vec<(String, usize)>
List all topics with their subscriber counts.
Sourcepub fn topics_for_pid(&self, pid: Pid) -> Vec<String>
pub fn topics_for_pid(&self, pid: Pid) -> Vec<String>
List all topics a specific PID is subscribed to.
Sourcepub fn topic_count(&self) -> usize
pub fn topic_count(&self) -> usize
Get the total number of active topics.
Sourcepub fn has_subscribers(&self, topic: &str) -> bool
pub fn has_subscribers(&self, topic: &str) -> bool
Check whether a topic has any subscribers.
Sourcepub fn unsubscribe_all(&self, pid: Pid)
pub fn unsubscribe_all(&self, pid: Pid)
Remove all subscriptions for a PID (used during process cleanup).
Auto Trait Implementations§
impl Freeze for TopicRouter
impl !RefUnwindSafe for TopicRouter
impl Send for TopicRouter
impl Sync for TopicRouter
impl Unpin for TopicRouter
impl UnsafeUnpin for TopicRouter
impl !UnwindSafe for TopicRouter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more