pub struct InMemorySubscriber { /* private fields */ }
Expand description
A Subscriber
which keeps all information about registered subscription change handlers in memory.
The subscriber requires a (client) implementation of USubscription
in order to inform the local
USubscription service about newly subscribed and unsubscribed topics. It also needs a Notifier
for receiving notifications about subscription status updates from the local USubscription service.
Finally, it needs a UTransport
for receiving events that have been published to subscribed topics.
During startup the subscriber uses the Notifier to register a generic UListener
for receiving notifications from the USubscription service. The listener maintains an in-memory mapping
of subscribed topics to corresponding subscription change handlers.
When a client subscribes to a topic
, the local USubscription service is informed
about the new subscription and a (client provided) subscription change handler is registered with the
listener. When a subscription change notification arrives from the USubscription service, the corresponding
handler is being looked up and invoked.
Implementations§
Source§impl InMemorySubscriber
impl InMemorySubscriber
Sourcepub async fn new(
transport: Arc<dyn UTransport>,
uri_provider: Arc<dyn LocalUriProvider>,
) -> Result<Self, RegistrationError>
pub async fn new( transport: Arc<dyn UTransport>, uri_provider: Arc<dyn LocalUriProvider>, ) -> Result<Self, RegistrationError>
Creates a new Subscriber for a given transport.
The subscriber keeps track of subscription change handlers in memory only.
This function uses the given transport to create an RpcClientUSubscription
and a SimpleNotifier
and then delegate to Self::for_clients
to create the Subscriber.
§Errors
Returns an error if the Notifier cannot register a listener for notifications from the USubscription service.
Sourcepub async fn for_clients(
transport: Arc<dyn UTransport>,
uri_provider: Arc<dyn LocalUriProvider>,
usubscription: Arc<dyn USubscription>,
notifier: Arc<dyn Notifier>,
) -> Result<Self, RegistrationError>
pub async fn for_clients( transport: Arc<dyn UTransport>, uri_provider: Arc<dyn LocalUriProvider>, usubscription: Arc<dyn USubscription>, notifier: Arc<dyn Notifier>, ) -> Result<Self, RegistrationError>
Creates a new Subscriber for given clients.
§Arguments
transport
- The transport to use for registering the event listeners for subscribed topics.uri-provider
- The service to use for creating topic addresses.usubscription
- The client to use for interacting with the (local) USubscription service.notifier
- The client to use for registering the listener for subscription updates from USubscription.
§Errors
Returns an error if the Notifier cannot register a listener for notifications from the USubscription service.
Sourcepub async fn stop(&self) -> Result<(), RegistrationError>
pub async fn stop(&self) -> Result<(), RegistrationError>
Stops this client.
Clears all internal state and deregisters the listener for subscription updates from the USubscription service.
§Errors
Returns an error if the listener could not be unregistered. In this case the internal state remains intact.