Skip to content

Commit dc696f2

Browse files
authored
Merge pull request #735 from swimos/describe
Improvies debugability of event handlers.
2 parents f7018ce + 2410096 commit dc696f2

File tree

61 files changed

+2639
-434
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+2639
-434
lines changed

server/swimos_agent/src/agent_lifecycle/item_event/demand/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use futures::future::Either;
1616

1717
use crate::{
1818
agent_lifecycle::HandlerContext,
19+
agent_model::AgentDescription,
1920
lanes::demand::{
2021
lifecycle::{
2122
on_cue::{OnCue, OnCueShared},
@@ -139,6 +140,7 @@ impl<Context, T, LC, L: HTree, R: HTree> HTree for DemandBranch<Context, T, LC,
139140

140141
impl<Context, T, LC, L, R> ItemEvent<Context> for DemandBranch<Context, T, LC, L, R>
141142
where
143+
Context: AgentDescription,
142144
LC: DemandLaneLifecycle<T, Context>,
143145
L: HTree + ItemEvent<Context>,
144146
R: HTree + ItemEvent<Context>,
@@ -175,6 +177,7 @@ where
175177
impl<Context, Shared, T, LC, L, R> ItemEventShared<Context, Shared>
176178
for DemandBranch<Context, T, LC, L, R>
177179
where
180+
Context: AgentDescription,
178181
LC: DemandLaneLifecycleShared<T, Context, Shared>,
179182
L: HTree + ItemEventShared<Context, Shared>,
180183
R: HTree + ItemEventShared<Context, Shared>,

server/swimos_agent/src/agent_lifecycle/item_event/demand/tests.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{collections::HashMap, sync::Arc};
15+
use std::{borrow::Cow, collections::HashMap, sync::Arc};
1616

1717
use bytes::BytesMut;
1818
use parking_lot::Mutex;
@@ -28,7 +28,7 @@ use crate::{
2828
agent_lifecycle::item_event::{
2929
tests::run_handler_expect_mod, DemandBranch, DemandLeaf, HLeaf, ItemEvent,
3030
},
31-
agent_model::WriteResult,
31+
agent_model::{AgentDescription, WriteResult},
3232
event_handler::{ActionContext, HandlerAction, Modification, StepResult},
3333
lanes::{
3434
demand::{lifecycle::on_cue::OnCue, DemandLane},
@@ -43,6 +43,17 @@ struct TestAgent {
4343
third: DemandLane<bool>,
4444
}
4545

46+
impl AgentDescription for TestAgent {
47+
fn item_name(&self, id: u64) -> Option<Cow<'_, str>> {
48+
match id {
49+
LANE_ID1 => Some(Cow::Borrowed("first")),
50+
LANE_ID2 => Some(Cow::Borrowed("second")),
51+
LANE_ID3 => Some(Cow::Borrowed("third")),
52+
_ => None,
53+
}
54+
}
55+
}
56+
4657
const LANE_ID1: u64 = 0;
4758
const LANE_ID2: u64 = 1;
4859
const LANE_ID3: u64 = 2;

server/swimos_agent/src/agent_lifecycle/item_event/demand_map/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use futures::future::Either;
1616

1717
use crate::{
1818
agent_lifecycle::HandlerContext,
19+
agent_model::AgentDescription,
1920
lanes::{
2021
demand_map::{
2122
demand_map_handler, demand_map_handler_shared,
@@ -156,6 +157,7 @@ impl<Context, K, V, LC, L: HTree, R: HTree> HTree for DemandMapBranch<Context, K
156157

157158
impl<Context, K, V, LC, L, R> ItemEvent<Context> for DemandMapBranch<Context, K, V, LC, L, R>
158159
where
160+
Context: AgentDescription,
159161
K: Clone + Eq + Hash,
160162
LC: DemandMapLaneLifecycle<K, V, Context>,
161163
L: HTree + ItemEvent<Context>,
@@ -193,6 +195,7 @@ where
193195
impl<Context, Shared, K, V, LC, L, R> ItemEventShared<Context, Shared>
194196
for DemandMapBranch<Context, K, V, LC, L, R>
195197
where
198+
Context: AgentDescription,
196199
K: Clone + Eq + Hash,
197200
LC: DemandMapLaneLifecycleShared<K, V, Context, Shared>,
198201
L: HTree + ItemEventShared<Context, Shared>,

server/swimos_agent/src/agent_lifecycle/item_event/demand_map/tests.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::{
16+
borrow::Cow,
1617
collections::{HashMap, HashSet},
1718
fmt::Debug,
1819
hash::Hash,
@@ -31,7 +32,7 @@ use uuid::Uuid;
3132

3233
use crate::{
3334
agent_lifecycle::item_event::{DemandMapBranch, DemandMapLeaf, HLeaf, ItemEvent},
34-
agent_model::WriteResult,
35+
agent_model::{AgentDescription, WriteResult},
3536
event_handler::{ActionContext, HandlerAction, Modification, ModificationFlags, StepResult},
3637
lanes::{
3738
demand_map::lifecycle::{keys::Keys, on_cue_key::OnCueKey},
@@ -47,6 +48,17 @@ struct TestAgent {
4748
third: DemandMapLane<i32, bool>,
4849
}
4950

51+
impl AgentDescription for TestAgent {
52+
fn item_name(&self, id: u64) -> Option<Cow<'_, str>> {
53+
match id {
54+
LANE_ID1 => Some(Cow::Borrowed("first")),
55+
LANE_ID2 => Some(Cow::Borrowed("second")),
56+
LANE_ID3 => Some(Cow::Borrowed("third")),
57+
_ => None,
58+
}
59+
}
60+
}
61+
5062
const LANE_ID1: u64 = 0;
5163
const LANE_ID2: u64 = 1;
5264
const LANE_ID3: u64 = 2;

server/swimos_agent/src/agent_lifecycle/item_event/http/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use futures::future::Either;
1818

1919
use crate::{
2020
agent_lifecycle::HandlerContext,
21+
agent_model::AgentDescription,
2122
lanes::http::{
2223
lifecycle::{
2324
HttpLaneLifecycle, HttpLaneLifecycleShared, HttpLifecycleHandler,
@@ -147,6 +148,7 @@ where
147148
impl<Context, Get, Post, Put, Codec, LC, L, R> ItemEvent<Context>
148149
for HttpBranch<Context, Get, Post, Put, Codec, LC, L, R>
149150
where
151+
Context: AgentDescription,
150152
Codec: HttpLaneCodec<Get>,
151153
LC: HttpLaneLifecycle<Get, Post, Put, Context>,
152154
L: HTree + ItemEvent<Context>,
@@ -190,6 +192,7 @@ where
190192
impl<Context, Shared, Get, Post, Put, Codec, LC, L, R> ItemEventShared<Context, Shared>
191193
for HttpBranch<Context, Get, Post, Put, Codec, LC, L, R>
192194
where
195+
Context: AgentDescription,
193196
LC: HttpLaneLifecycleShared<Get, Post, Put, Context, Shared>,
194197
Codec: HttpLaneCodec<Get>,
195198
L: HTree + ItemEventShared<Context, Shared>,

server/swimos_agent/src/agent_lifecycle/item_event/http/tests.rs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
use std::{collections::HashMap, sync::Arc};
15+
use std::{borrow::Cow, collections::HashMap, sync::Arc};
1616

1717
use parking_lot::Mutex;
1818
use swimos_api::{
@@ -21,8 +21,11 @@ use swimos_api::{
2121
};
2222
use swimos_utilities::routing::RouteUri;
2323

24-
use crate::agent_lifecycle::item_event::{HLeaf, HttpBranch};
2524
use crate::lanes::http::Request;
25+
use crate::{
26+
agent_lifecycle::item_event::{HLeaf, HttpBranch},
27+
agent_model::AgentDescription,
28+
};
2629
use crate::{
2730
agent_lifecycle::{
2831
item_event::{tests::run_handler, ItemEventShared},
@@ -49,6 +52,17 @@ struct TestAgent {
4952
third: SimpleHttpLane<bool, Recon>,
5053
}
5154

55+
impl AgentDescription for TestAgent {
56+
fn item_name(&self, id: u64) -> Option<Cow<'_, str>> {
57+
match id {
58+
LANE_ID1 => Some(Cow::Borrowed("first")),
59+
LANE_ID2 => Some(Cow::Borrowed("second")),
60+
LANE_ID3 => Some(Cow::Borrowed("third")),
61+
_ => None,
62+
}
63+
}
64+
}
65+
5266
const LANE_ID1: u64 = 0;
5367
const LANE_ID2: u64 = 1;
5468
const LANE_ID3: u64 = 2;

server/swimos_agent/src/agent_lifecycle/on_init.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use swimos_form::Form;
1818
use swimos_utilities::handlers::{FnHandler, NoHandler};
1919

2020
use crate::{
21+
agent_model::AgentDescription,
2122
event_handler::{ActionContext, BoxJoinLaneInit},
2223
item::AgentItem,
2324
lanes::{
@@ -197,7 +198,7 @@ impl<Context, Shared, K, V, F> RegisterJoinValue<Context, Shared, K, V, F> {
197198
impl<Context, Shared, K, V, F, LC> OnInitShared<Context, Shared>
198199
for RegisterJoinValue<Context, Shared, K, V, F>
199200
where
200-
Context: 'static,
201+
Context: AgentDescription + 'static,
201202
K: Clone + Eq + Hash + Send + 'static,
202203
V: Form + Send + Sync + 'static,
203204
V::Rec: Send,
@@ -262,7 +263,7 @@ impl<Context, Shared, L, K, V, F> RegisterJoinMap<Context, Shared, L, K, V, F> {
262263
impl<Context, Shared, L, K, V, F, LC> OnInitShared<Context, Shared>
263264
for RegisterJoinMap<Context, Shared, L, K, V, F>
264265
where
265-
Context: 'static,
266+
Context: AgentDescription + 'static,
266267
L: Clone + Eq + Hash + Send + 'static,
267268
K: Clone + Form + Eq + Hash + Ord + Send + 'static,
268269
V: Form + Send + Sync + 'static,

server/swimos_agent/src/agent_lifecycle/utility/downlink_builder/event.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ use swimos_model::Text;
2121
use swimos_utilities::handlers::FnHandler;
2222

2323
use crate::{
24-
agent_model::downlink::{EventDownlinkHandle, OpenEventDownlinkAction},
24+
agent_model::{
25+
downlink::{EventDownlinkHandle, OpenEventDownlinkAction},
26+
AgentDescription,
27+
},
2528
config::SimpleDownlinkConfig,
2629
downlink_lifecycle::{
2730
OnConsumeEvent, OnConsumeEventShared, OnFailed, OnFailedShared, OnLinked, OnLinkedShared,
@@ -266,7 +269,7 @@ where
266269

267270
impl<Context, T, LC> StatelessEventDownlinkBuilder<Context, T, LC>
268271
where
269-
Context: 'static,
272+
Context: AgentDescription + 'static,
270273
LC: StatelessEventLifecycle<Context, T> + 'static,
271274
T: RecognizerReadable + Send + 'static,
272275
T::Rec: Send,
@@ -429,7 +432,7 @@ where
429432

430433
impl<Context, State, T, LC> StatefulEventDownlinkBuilder<Context, T, State, LC>
431434
where
432-
Context: 'static,
435+
Context: AgentDescription + 'static,
433436
LC: StatefulEventLifecycle<Context, State, T> + 'static,
434437
T: RecognizerReadable + Send + 'static,
435438
T::Rec: Send,

server/swimos_agent/src/agent_lifecycle/utility/downlink_builder/map.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use swimos_form::Form;
2222
use swimos_model::Text;
2323
use swimos_utilities::handlers::{BorrowHandler, FnHandler};
2424

25+
use crate::agent_model::AgentDescription;
2526
use crate::downlink_lifecycle::{
2627
OnFailed, OnFailedShared, OnSynced, OnSyncedShared, StatefulMapLifecycle, StatelessMapLifecycle,
2728
};
@@ -278,7 +279,7 @@ where
278279

279280
impl<Context, K, V, LC> StatelessMapDownlinkBuilder<Context, K, V, LC>
280281
where
281-
Context: 'static,
282+
Context: AgentDescription + 'static,
282283
K: Form + Hash + Eq + Ord + Clone + Send + Sync + 'static,
283284
K::Rec: Send,
284285
V: Form + Send + Sync + 'static,
@@ -484,7 +485,7 @@ where
484485

485486
impl<Context, K, V, State, LC> StatefulMapDownlinkBuilder<Context, K, V, State, LC>
486487
where
487-
Context: 'static,
488+
Context: AgentDescription + 'static,
488489
K: Form + Hash + Eq + Ord + Clone + Send + Sync + 'static,
489490
K::Rec: Send,
490491
V: Form + Send + Sync + 'static,

server/swimos_agent/src/agent_lifecycle/utility/downlink_builder/value.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ use swimos_model::Text;
2020
use swimos_utilities::handlers::{BorrowHandler, FnHandler};
2121

2222
use crate::{
23-
agent_model::downlink::{OpenValueDownlinkAction, ValueDownlinkHandle},
23+
agent_model::{
24+
downlink::{OpenValueDownlinkAction, ValueDownlinkHandle},
25+
AgentDescription,
26+
},
2427
config::SimpleDownlinkConfig,
2528
downlink_lifecycle::{
2629
OnDownlinkEvent, OnDownlinkEventShared, OnDownlinkSet, OnDownlinkSetShared, OnFailed,
@@ -267,7 +270,7 @@ where
267270

268271
impl<Context, T, LC> StatelessValueDownlinkBuilder<Context, T, LC>
269272
where
270-
Context: 'static,
273+
Context: AgentDescription + 'static,
271274
LC: StatelessValueLifecycle<Context, T> + 'static,
272275
T: Form + Send + 'static,
273276
T::Rec: Send,
@@ -451,7 +454,7 @@ where
451454

452455
impl<Context, State, T, LC> StatefulValueDownlinkBuilder<Context, T, State, LC>
453456
where
454-
Context: 'static,
457+
Context: AgentDescription + 'static,
455458
LC: StatefulValueLifecycle<Context, State, T> + 'static,
456459
T: Form + Send + 'static,
457460
T::Rec: Send,

0 commit comments

Comments
 (0)