@@ -145,6 +145,8 @@ enum Event {
145145
146146// Core business logic of subscription management - includes container data types for tracking subscriptions and remote subscriptions.
147147// Interfacing with this purely works via channels, so we do not have to deal with mutexes and similar concepts.
148+ // [impl->req~usubscription-unsubscribe-notifications~1]
149+ // [impl->dsn~usubscription-state-machine~1]
148150pub ( crate ) async fn handle_message (
149151 configuration : Arc < USubscriptionConfiguration > ,
150152 transport : Arc < dyn UTransport > ,
@@ -165,6 +167,8 @@ pub(crate) async fn handle_message(
165167 mpsc:: channel :: < InternalSubscriptionEvent > ( INTERNAL_COMMAND_BUFFER_SIZE ) ;
166168
167169 // At startup, set up timed unsubscribe for any persisted subscriptions that define an expiration timestamp
170+ // [impl->req~usubscription-subscribe-expiration~1]
171+ // [impl->req~usubscription-subscribe-no-expiration~1]
168172 match subscriptions. get_and_prune_expiring_subscriptions ( ) {
169173 Ok ( list) => {
170174 for ( subscriber, topic, expiry_millis) in list {
@@ -210,6 +214,7 @@ pub(crate) async fn handle_message(
210214 expiry,
211215 respond_to,
212216 } => {
217+ // [impl->req~usubscription-subscribe~1]
213218 match add_subscription (
214219 configuration. clone ( ) ,
215220 transport. clone ( ) ,
@@ -220,6 +225,7 @@ pub(crate) async fn handle_message(
220225 topic. clone ( ) ,
221226 expiry,
222227 ) {
228+ // [impl->req~usubscription-subscribe-notifications~1]
223229 Ok ( result) => {
224230 // Send topic state change notification
225231 notification_manager:: notify (
@@ -244,6 +250,7 @@ pub(crate) async fn handle_message(
244250 topic,
245251 respond_to,
246252 } => {
253+ // [impl->req~usubscription-unsubscribe~1]
247254 match remove_subscription (
248255 configuration. clone ( ) ,
249256 transport. clone ( ) ,
@@ -277,6 +284,7 @@ pub(crate) async fn handle_message(
277284 offset,
278285 respond_to,
279286 } => match fetch_subscribers ( & subscriptions, topic, offset) {
287+ // [impl->req~usubscription-fetch-subscribers~1]
280288 Ok ( result) => {
281289 if respond_to. send ( result) . is_err ( ) {
282290 error ! ( "Problem with internal communication" ) ;
@@ -422,10 +430,13 @@ fn add_subscription(
422430 let _ = topic_subscribers. add_subscription ( & subscriber, & topic, expiry) ?;
423431
424432 // For REMOTE topics, we explicitly track state due to _PENDING scenarios
433+ // [impl->req~usubscription-subscribe-multiple~1]
425434 let state = if topic. is_remote_authority ( & uri_provider. get_authority ( ) ) {
426435 let state = remote_topics. add_topic_or_get_state ( & topic) ?;
427436
428437 // if this remote topic is not yet SUBSCRIBED, perform remote subscription
438+ // [impl->req~usubscription-subscribe-remote~1]
439+ // [impl->req~usubscription-subscribe-unsubscribe-pending~1]
429440 if state != TopicState :: SUBSCRIBED {
430441 let topic_clone = topic. clone ( ) ;
431442 let internal_cmd_sender_clone = internal_cmd_sender. clone ( ) ;
@@ -447,6 +458,8 @@ fn add_subscription(
447458 } ;
448459
449460 // Set up timed unsubscribe in case expiration timestamp is set
461+ // [impl->req~usubscription-subscribe-expiration~1]
462+ // [impl->req~usubscription-subscribe-no-expiration~1]
450463 if let Some ( expiry_millis) = expiry {
451464 schedule_unsubscribe (
452465 expiry_millis,
@@ -473,6 +486,8 @@ fn remove_subscription(
473486 topic : TopicUUri ,
474487) -> Result < SubscriptionStatus , persistency:: PersistencyError > {
475488 // if this was the last subscriber to topic and topic is remote
489+ // [impl->req~usubscription-unsubscribe-last-remote~1]
490+ // [impl->req~usubscription-unsubscribe-subscribe-pending~1]
476491 if topic_subscribers. remove_subscription ( & subscriber, & topic) ?
477492 && topic. is_remote_authority ( & uri_provider. get_authority ( ) )
478493 {
@@ -486,6 +501,8 @@ fn remove_subscription(
486501 } ) ;
487502 }
488503
504+ // [impl->req~usubscription-unsubscribe-multiple~1]
505+ // [impl->req~usubscription-unsubscribe-remote-unsubscribed~1]
489506 Ok ( SubscriptionStatus {
490507 // Whatever happens with the remote topic state - as far as the local client is concerned, it has now UNSUBSCRIBED from this topic
491508 state : TopicState :: UNSUBSCRIBED . into ( ) ,
@@ -503,11 +520,13 @@ fn fetch_subscribers(
503520 // the remote topic is already fully SUBSCRIBED, of still SUSBCRIBED_PENDING
504521 let mut subscribers = topic_subscribers. get_topic_subscribers ( & topic) ?;
505522
523+ // [impl->req~usubscription-fetch-subscribers-offset~1]
506524 if let Some ( offset) = offset {
507525 subscribers. drain ( ..offset as usize ) ;
508526 }
509527
510528 // split up result list, to make sense of has_more_records field
529+ // [impl->req~usubscription-fetch-subscribers-has-more-records~1]
511530 let has_more = if subscribers. len ( ) > UP_MAX_FETCH_SUBSCRIBERS_LEN {
512531 subscribers. truncate ( UP_MAX_FETCH_SUBSCRIBERS_LEN ) ;
513532 true
@@ -526,6 +545,7 @@ fn fetch_subscriptions(
526545 offset : Option < u32 > ,
527546) -> Result < SubscriptionsResponse , persistency:: PersistencyError > {
528547 let mut results: Vec < SubscriptionEntry > = match request {
548+ // [impl->req~usubscription-fetch-subscriptions-by-subscriber~1]
529549 RequestKind :: Subscriber ( subscriber) => topic_subscribers
530550 . get_subscriber_topics ( & subscriber) ?
531551 . iter ( )
@@ -543,6 +563,7 @@ fn fetch_subscriptions(
543563 } )
544564 . collect ( ) ,
545565
566+ // [impl->req~usubscription-fetch-subscriptions-by-topic~1]
546567 RequestKind :: Topic ( topic) => topic_subscribers
547568 . get_topic_subscribers ( & topic) ?
548569 . iter ( )
@@ -561,11 +582,13 @@ fn fetch_subscriptions(
561582 . collect ( ) ,
562583 } ;
563584
585+ // [impl->req~usubscription-fetch-subscriptions-offset~1]
564586 if let Some ( offset) = offset {
565587 results. drain ( ..offset as usize ) ;
566588 }
567589
568590 // split up result list, to make sense of has_more_records field
591+ // [impl->req~usubscription-fetch-subscriptions-has-more-records~1]
569592 let mut has_more = false ;
570593 if results. len ( ) > UP_MAX_FETCH_SUBSCRIPTIONS_LEN {
571594 results. truncate ( UP_MAX_FETCH_SUBSCRIPTIONS_LEN ) ;
@@ -582,6 +605,7 @@ async fn remote_subscribe(
582605 transport : Arc < dyn UTransport > ,
583606 internal_cmd_sender : Sender < InternalSubscriptionEvent > ,
584607) -> Result < ( ) , UStatus > {
608+ // [impl->dsn~usubscription-subscribe-remote-subscriber-change~1]
585609 let rpc_client: Arc < dyn RpcClient > = Arc :: new (
586610 InMemoryRpcClient :: new ( transport, uri_provider)
587611 . await
@@ -595,6 +619,7 @@ async fn remote_subscribe(
595619 } ;
596620
597621 // send request
622+ // [impl->req~usubscription-remote-max-timeout~1]
598623 let subscription_response: SubscriptionResponse = rpc_client
599624 . invoke_proto_method (
600625 make_remote_subscribe_uuri ( & subscription_request. topic ) ,
@@ -610,6 +635,7 @@ async fn remote_subscribe(
610635 } ) ?;
611636
612637 // deal with response
638+ // [impl->req~usubscription-subscribe-remote-response~1]
613639 if subscription_response. is_state ( TopicState :: SUBSCRIBED ) {
614640 debug ! ( "Got remote subscription response, state SUBSCRIBED" ) ;
615641
@@ -634,6 +660,7 @@ async fn remote_unsubscribe(
634660 internal_cmd_sender : Sender < InternalSubscriptionEvent > ,
635661) -> Result < ( ) , UStatus > {
636662 let rpc_client: Arc < dyn RpcClient > = Arc :: new (
663+ // [impl->dsn~usubscription-unsubscribe-remote-subscriber-change~1]
637664 InMemoryRpcClient :: new ( transport, uri_provider)
638665 . await
639666 . map_err ( |e| UStatus :: fail_with_code ( UCode :: INTERNAL , e. to_string ( ) ) ) ?,
@@ -751,6 +778,7 @@ mod tests {
751778 mock_provider
752779 }
753780
781+ // [utest->req~usubscription-subscribe-expiration~1]
754782 #[ tokio:: test]
755783 async fn test_schedule_future_unsubscribe ( ) {
756784 let ( internal_cmd_sender, mut internal_cmd_receiver) =
@@ -786,6 +814,7 @@ mod tests {
786814 }
787815 }
788816
817+ // [utest->req~usubscription-subscribe-expiration~1]
789818 #[ tokio:: test]
790819 async fn test_schedule_past_unsubscribe ( ) {
791820 let ( internal_cmd_sender, mut internal_cmd_receiver) =
0 commit comments