Skip to content

Commit 2f16497

Browse files
committed
Added utility method for custom map downlink stores.
Updated doc comments.
1 parent fdd2adb commit 2f16497

File tree

3 files changed

+31
-1
lines changed
  • server/swimos_agent/src

3 files changed

+31
-1
lines changed

server/swimos_agent/src/agent_lifecycle/utility/mod.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -897,6 +897,30 @@ impl<Agent: 'static> HandlerContext<Agent> {
897897
StatelessMapDownlinkBuilder::new(Address::text(host, node, lane), config)
898898
}
899899

900+
/// Create a builder to construct a request to open a map downlink, using the specified map type
901+
/// as the backing representation of the downlink.
902+
/// # Arguments
903+
/// * `host` - The remote host at which the agent resides (a local agent if not specified).
904+
/// * `node` - The node URI of the agent.
905+
/// * `lane` - The lane to downlink from.
906+
/// * `config` - Configuration parameters for the downlink.
907+
pub fn map_downlink_builder_for<K, V, M>(
908+
&self,
909+
host: Option<&str>,
910+
node: &str,
911+
lane: &str,
912+
config: MapDownlinkConfig,
913+
) -> StatelessMapDownlinkBuilder<Agent, K, V, M>
914+
where
915+
M: MapOpsWithEntry<K, V, K>,
916+
K: Form + Hash + Eq + Clone + Send + Sync + 'static,
917+
K::Rec: Send,
918+
V: Form + Send + Sync + 'static,
919+
V::Rec: Send,
920+
{
921+
StatelessMapDownlinkBuilder::new(Address::text(host, node, lane), config)
922+
}
923+
900924
/// Causes the agent to stop. If this is encountered during the `on_start` event of an agent it will
901925
/// fail to start at all. Otherwise, execution of the event handler will terminate and the agent will
902926
/// begin to shutdown. The 'on_stop' handler will still be run. If a stop is requested in

server/swimos_agent/src/downlink_lifecycle/map/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ mod on_update;
4444
/// # Type Parameters
4545
/// * `K` - The type of the keys of the downlink.
4646
/// * `V` - The type of the values of the downlink.
47+
/// * `M` - The map type underlying the downlink (i.e. [`std::collections::HashMap<K, V>`]).
4748
/// * `Context` - The context within which the event handlers execute (providing access to the agent lanes).
4849
pub trait MapDownlinkLifecycle<K, V, M, Context>:
4950
OnLinked<Context>
@@ -73,6 +74,7 @@ impl<LC, K, V, M, Context> MapDownlinkLifecycle<K, V, M, Context> for LC where
7374
/// * `Context` - The context within which the event handlers execute (providing access to the agent lanes).
7475
/// * `K` - The type of the keys for the map.
7576
/// * `V` - The type of the values for the map.
77+
/// * `M` - The map type underlying the downlink (i.e. [`std::collections::HashMap<K, V>`]).
7678
pub trait StatelessMapLifecycle<Context, K, V, M>: MapDownlinkLifecycle<K, V, M, Context> {
7779
type WithOnLinked<H>: StatelessMapLifecycle<Context, K, V, M>
7880
where
@@ -146,6 +148,7 @@ pub trait StatelessMapLifecycle<Context, K, V, M>: MapDownlinkLifecycle<K, V, M,
146148
/// * `Shared` - The type of the shared state.
147149
/// * `K` - The type of the keys for the map.
148150
/// * `V` - The type of the values for the map.
151+
/// * `M` - The map type underlying the downlink (i.e. [`std::collections::HashMap<K, V>`]).
149152
pub trait StatefulMapLifecycle<Context, Shared, K, V, M>:
150153
MapDownlinkLifecycle<K, V, M, Context>
151154
{
@@ -214,6 +217,7 @@ pub trait StatefulMapLifecycle<Context, Shared, K, V, M>:
214217
/// * `Context` - The context within which the event handlers execute (providing access to the agent lanes).
215218
/// * `K` - The type of the keys of the downlink.
216219
/// * `V` - The type of the values of the downlink.
220+
/// * `M` - The map type underlying the downlink (i.e. [`std::collections::HashMap<K, V>`]).
217221
/// * `FLinked` - The type of the 'on_linked' handler.
218222
/// * `FSynced` - The type of the 'on_synced' handler.
219223
/// * `FUnlinked` - The type of the 'on_unlinked' handler.
@@ -267,6 +271,7 @@ impl<Context, K, V, M> Default for StatelessMapDownlinkLifecycle<Context, K, V,
267271
/// * `State` - The type of the shared state.
268272
/// * `K` - The type of the keys of the downlink.
269273
/// * `V` - The type of the values of the downlink.
274+
/// * `M` - The map type underlying the downlink (i.e. [`std::collections::HashMap<K, V>`]).
270275
/// * `FLinked` - The type of the 'on_linked' handler.
271276
/// * `FSynced` - The type of the 'on_synced' handler.
272277
/// * `FUnlinked` - The type of the 'on_unlinked' handler.

server/swimos_agent/src/lanes/map/lifecycle/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub mod on_update;
3333
/// # Type Parameters
3434
/// * `K` - The type of the map keys.
3535
/// * `V` - The type of the map values.
36+
/// * `M` - The map type underlying the lane (i.e. [`std::collections::HashMap<K, V>`]).
3637
/// * `Context` - The context within which the event handlers execute (providing access to the agent lanes).
3738
pub trait MapLaneLifecycle<K, V, M, Context>:
3839
OnUpdate<K, V, M, Context> + OnRemove<K, V, M, Context> + OnClear<M, Context>
@@ -67,7 +68,7 @@ type LifecycleType<Context, Shared, K, V, M> = fn(Context, Shared, K, V, M);
6768
/// * `Shared` - The shared state to which the lifecycle has access.
6869
/// * `K` - The key type of the map.
6970
/// * `V` - The value type of the map.
70-
/// * `M` - The map type (for example `HashMap<K, V>`).
71+
/// * `M` - The map type underlying the lane (i.e. [`std::collections::HashMap<K, V>`]).
7172
/// * `FUpd` - The `on_update` event handler.
7273
/// * `FRem` - The `on_remove` event handler.
7374
/// * `FClr` - The `on_clear` event handler.

0 commit comments

Comments
 (0)