OpenRoadCode
Public API reference for OpenRoadCode
Loading...
Searching...
No Matches
messaging.message_dispatcher.MessageDispatcher Class Reference

Receive subscribed messages and dispatch decoded objects to handlers. More...

Public Member Functions

None __init__ (self, SubscriberIf subscriber, *Executor|None executor=None, int max_workers=4, ErrorHandler|None error_handler=None)
 Create a dispatcher around one transport subscriber.
 
None register (self, str topic, Decoder decoder, Handler handler)
 Subscribe and register one decoder/handler pair for a topic.
 
None start (self)
 Start the single subscriber receive thread after registration is complete.
 
None close (self)
 Stop reception before shutting down handler workers.
 

Detailed Description

Receive subscribed messages and dispatch decoded objects to handlers.

Exactly one receiver thread owns the SubscriberIf. Handler execution is delegated to a shared Executor so slow consumers do not block reception. Register all topics before calling start(). Handlers run on executor worker threads and therefore must not directly mutate thread-affine UI toolkits.

Constructor & Destructor Documentation

◆ __init__()

None messaging.message_dispatcher.MessageDispatcher.__init__ (   self,
SubscriberIf  subscriber,
*Executor | None   executor = None,
int   max_workers = 4,
ErrorHandler | None   error_handler = None 
)

Create a dispatcher around one transport subscriber.

Parameters
subscriberTransport-independent subscriber owned by the receive loop.
executorOptional executor used for decoded message handlers.
max_workersWorker count used when the dispatcher creates its executor.
error_handlerOptional callback receiving topic and dispatch exceptions.

Member Function Documentation

◆ close()

None messaging.message_dispatcher.MessageDispatcher.close (   self)

Stop reception before shutting down handler workers.

The receive thread must be fully stopped before the owned executor is shut down. Otherwise a message received during teardown can race an executor shutdown and attempt to submit work after shutdown has begun.


The documentation for this class was generated from the following file: