pub trait EntityEventDispatcher: Send + Sync {
// Required method
fn dispatch(&self, event: EntityEvent) -> Result<(), Error>;
}Expand description
Trait for dispatchers that receive unified entity events.
This is the preferred way to receive entity lifecycle events. Implement this
trait and register with set_entity_dispatcher to receive notifications for
all entity types (actors, meshes, etc.) through a single callback.
The dispatcher pattern routes events to appropriate handlers based on the event type (Actor, Mesh, etc.), distinguishing this from TraceEventSink which handles tracing spans and events.
§Example
ⓘ
use hyperactor_telemetry::{set_entity_dispatcher, EntityEventDispatcher, EntityEvent};
struct MyEntityDispatcher;
impl EntityEventDispatcher for MyEntityDispatcher {
fn dispatch(&self, event: EntityEvent) -> Result<(), anyhow::Error> {
match event {
EntityEvent::Actor(actor) => println!("Actor: {}", actor.full_name),
EntityEvent::Mesh(mesh) => println!("Mesh: {}", mesh.full_name),
EntityEvent::ActorStatus(status) => println!("Status: {}", status.new_status),
EntityEvent::SentMessage(msg) => println!("Sent: {}", msg.id),
EntityEvent::Message(msg) => println!("Recv: {}", msg.id),
EntityEvent::MessageStatus(s) => println!("Status: {}", s.status),
}
Ok(())
}
}
set_entity_dispatcher(Box::new(MyEntityDispatcher));