@@ -60,6 +60,8 @@ use self::{
60
60
} ,
61
61
} ;
62
62
63
+ /// Describes the metrics the the agent runtime task reports as it runs. These are subscribed to by the
64
+ /// introspection API to report on the internal state of server application.
63
65
pub mod reporting;
64
66
mod store;
65
67
mod task;
@@ -69,26 +71,40 @@ mod tests;
69
71
use task:: AgentRuntimeRequest ;
70
72
use tracing:: { error, info_span, Instrument } ;
71
73
74
+ /// A message type that can be sent to the agent runtime to request a link to one of its lanes.
72
75
#[ derive( Debug ) ]
73
76
pub enum LinkRequest {
77
+ /// A request to open a downlink to one of the lanes.
74
78
Downlink ( DownlinkRequest ) ,
79
+ /// A request to open a one way connection to send commands to a lane.
75
80
Commander ( CommanderRequest ) ,
76
81
}
77
82
83
+ /// A description of an endpoint to which commands can be sent.
78
84
#[ derive( Debug , PartialEq , Eq , Hash , Clone ) ]
79
85
pub enum CommanderKey {
86
+ /// An endpoint on an explicit remote host.
80
87
Remote ( SchemeHostPort ) ,
88
+ /// An endpoint that is locally resolved.
81
89
Local ( RelativeAddress < Text > ) ,
82
90
}
83
91
92
+ /// A request to the runtime to open a channel to send commands to a remote lane.
84
93
#[ derive( Debug ) ]
85
94
pub struct CommanderRequest {
95
+ /// The ID of the agent making the request.
86
96
pub agent_id : Uuid ,
97
+ /// The target end point for the channel.
87
98
pub key : CommanderKey ,
99
+ /// A promise to be satisfied with the channel.
88
100
pub promise : oneshot:: Sender < Result < ByteWriter , DownlinkRuntimeError > > ,
89
101
}
90
102
91
103
impl CommanderRequest {
104
+ /// # Arguments
105
+ /// * `agent_id` - The ID of the agent making the request.
106
+ /// * `key` - The target end point for the channel.
107
+ /// * `promise` - A promise to be satisfied with the channel.
92
108
pub fn new (
93
109
agent_id : Uuid ,
94
110
key : CommanderKey ,
@@ -102,31 +118,28 @@ impl CommanderRequest {
102
118
}
103
119
}
104
120
121
+ /// A request to the runtime to open a downlink to a lane on another agent.
105
122
#[ derive( Debug ) ]
106
123
pub struct DownlinkRequest {
124
+ /// An explicit host for the agent, if defined.
107
125
pub remote : Option < SchemeHostPort > ,
126
+ /// The node URI and name of the lane.
108
127
pub address : RelativeAddress < Text > ,
128
+ /// The kind of the downlink to open.
109
129
pub kind : DownlinkKind ,
130
+ /// Configuration parameters for the downlink.
110
131
pub options : DownlinkOptions ,
132
+ /// A promise to be satisfied with a channel to the downlink.
111
133
pub promise : oneshot:: Sender < Result < Io , DownlinkRuntimeError > > ,
112
134
}
113
135
114
136
impl DownlinkRequest {
115
- pub fn replace_promise (
116
- & self ,
117
- replacement : oneshot:: Sender < Result < Io , DownlinkRuntimeError > > ,
118
- ) -> Self {
119
- DownlinkRequest {
120
- remote : self . remote . clone ( ) ,
121
- address : self . address . clone ( ) ,
122
- kind : self . kind ,
123
- options : self . options ,
124
- promise : replacement,
125
- }
126
- }
127
- }
128
-
129
- impl DownlinkRequest {
137
+ /// # Arguments
138
+ ///
139
+ /// * `remote` - An explicit host for the agent, if defined.
140
+ /// * `kind` - The kind of the downlink to open.
141
+ /// * `options` - Configuration parameters for the downlink.
142
+ /// * `promise` - A promise to be satisfied with a channel to the downlink.
130
143
pub fn new (
131
144
remote : Option < SchemeHostPort > ,
132
145
address : RelativeAddress < Text > ,
@@ -144,6 +157,21 @@ impl DownlinkRequest {
144
157
}
145
158
}
146
159
160
+ impl DownlinkRequest {
161
+ fn replace_promise (
162
+ & self ,
163
+ replacement : oneshot:: Sender < Result < Io , DownlinkRuntimeError > > ,
164
+ ) -> Self {
165
+ DownlinkRequest {
166
+ remote : self . remote . clone ( ) ,
167
+ address : self . address . clone ( ) ,
168
+ kind : self . kind ,
169
+ options : self . options ,
170
+ promise : replacement,
171
+ }
172
+ }
173
+ }
174
+
147
175
/// Implementation of [`AgentContext`] that communicates with with another task over a channel
148
176
/// to perform the supported operations.
149
177
#[ derive( Clone ) ]
@@ -338,19 +366,23 @@ pub enum AgentAttachmentRequest {
338
366
339
367
/// A request from an agent to register a new lane for metadata reporting.
340
368
pub struct UplinkReporterRegistration {
369
+ /// The ID of the agent making the request.
341
370
pub agent_id : Uuid ,
371
+ /// The name of the lane.
342
372
pub lane_name : Text ,
373
+ /// The kind of the lane.
343
374
pub kind : LaneKind ,
375
+ /// Receiver for the uplink statistics.
344
376
pub reader : UplinkReportReader ,
345
377
}
346
378
347
379
impl UplinkReporterRegistration {
348
- pub fn new (
349
- agent_id : Uuid ,
350
- lane_name : Text ,
351
- kind : LaneKind ,
352
- reader : UplinkReportReader ,
353
- ) -> Self {
380
+ /// # Arguments
381
+ /// * `agent_id` - The ID of the agent making the request.
382
+ /// * `lane_name` - The name of the lane.
383
+ /// * `kind` - The kind of the lane.
384
+ /// * `reader` - Receiver for the uplink statistics.
385
+ fn new ( agent_id : Uuid , lane_name : Text , kind : LaneKind , reader : UplinkReportReader ) -> Self {
354
386
UplinkReporterRegistration {
355
387
agent_id,
356
388
lane_name,
@@ -415,16 +447,13 @@ impl NodeReporting {
415
447
}
416
448
417
449
impl AgentAttachmentRequest {
418
- pub fn downlink ( id : Uuid , io : Io , completion : promise:: Sender < DisconnectionReason > ) -> Self {
419
- AgentAttachmentRequest :: TwoWay {
420
- id,
421
- io,
422
- completion,
423
- on_attached : None ,
424
- }
425
- }
426
-
427
- /// Constructs a request with a trigger that will be called when the registration completes.
450
+ /// Constructs a downlink request with a trigger that will be called when the request is completed.
451
+ ///
452
+ /// # Arguments
453
+ /// * `id` - The ID of the remote endpoint requesting the downlink.
454
+ /// * `io` - The bidirectional channel.
455
+ /// * `completion` - Called for when the downlink closes.
456
+ /// * `on_attached` - Called when the request is completed.
428
457
pub fn with_confirmation (
429
458
id : Uuid ,
430
459
io : Io ,
@@ -439,6 +468,13 @@ impl AgentAttachmentRequest {
439
468
}
440
469
}
441
470
471
+ /// Constructs a request to open a one way channel to send commands to the agent.
472
+ ///
473
+ /// # Arguments
474
+ /// * `id` - The ID of the remote endpoint requesting the channel.
475
+ /// * `io` - The reader to receive the commands.
476
+ /// * `on_attached` - Called when the channel is established.
477
+ ///
442
478
pub fn commander ( id : Uuid , io : ByteReader , on_attached : trigger:: Sender ) -> Self {
443
479
AgentAttachmentRequest :: OneWay {
444
480
id,
@@ -522,18 +558,24 @@ pub enum AgentExecError {
522
558
PersistenceFailure ( #[ from] StoreError ) ,
523
559
}
524
560
525
- pub struct AgentRoute {
561
+ /// Descriptor of an agent route.
562
+ pub struct AgentRouteDescriptor {
563
+ /// The unique ID of the agent instance.
526
564
pub identity : Uuid ,
565
+ /// The route URI of the instance.
527
566
pub route : RouteUri ,
567
+ /// Parameters extracted from the route URI of the instance.
528
568
pub route_params : HashMap < String , String > ,
529
569
}
530
570
571
+ /// All configuration parameters associated with an agent instance.
531
572
#[ derive( Debug , Default , Clone , Copy ) ]
532
573
pub struct CombinedAgentConfig {
533
574
pub agent_config : AgentConfig ,
534
575
pub runtime_config : AgentRuntimeConfig ,
535
576
}
536
577
578
+ /// Channels used by an agent instance to communicate with the runtime.
537
579
pub struct AgentRouteChannels {
538
580
attachment_rx : mpsc:: Receiver < AgentAttachmentRequest > ,
539
581
http_rx : mpsc:: Receiver < HttpLaneRequest > ,
@@ -558,6 +600,8 @@ impl AgentRouteChannels {
558
600
}
559
601
}
560
602
603
+ /// The agent runtime task. This mediates between the the user defined agent state and event handlers
604
+ /// and the other entities within the Swim server application.
561
605
pub struct AgentRouteTask < ' a , A > {
562
606
agent : & ' a A ,
563
607
identity : Uuid ,
@@ -584,7 +628,7 @@ impl<'a, A: Agent + 'static> AgentRouteTask<'a, A> {
584
628
/// * `reporting` - Uplink metrics reporters.
585
629
pub fn new (
586
630
agent : & ' a A ,
587
- identity : AgentRoute ,
631
+ identity : AgentRouteDescriptor ,
588
632
channels : AgentRouteChannels ,
589
633
stopping : trigger:: Receiver ,
590
634
config : CombinedAgentConfig ,
@@ -605,6 +649,7 @@ impl<'a, A: Agent + 'static> AgentRouteTask<'a, A> {
605
649
}
606
650
}
607
651
652
+ /// Run the agent task without persistence.
608
653
pub fn run_agent ( self ) -> impl Future < Output = Result < ( ) , AgentExecError > > + Send + ' static {
609
654
let AgentRouteTask {
610
655
agent,
@@ -675,6 +720,10 @@ impl<'a, A: Agent + 'static> AgentRouteTask<'a, A> {
675
720
}
676
721
}
677
722
723
+ /// Run the agent task with persistence support.
724
+ ///
725
+ /// # Arguments
726
+ /// * `store_fut` - A future that will resolve to the persistence implementation.
678
727
pub fn run_agent_with_store < Store , Fut > (
679
728
self ,
680
729
store_fut : Fut ,
0 commit comments