dynamo_runtime/
pipeline.rs1use serde::{Deserialize, Serialize};
7
8mod nodes;
9pub use nodes::{
10 Operator, PipelineNode, PipelineOperator, SegmentSink, SegmentSource, Service, ServiceBackend,
11 ServiceFrontend, Sink, Source,
12};
13
14pub mod context;
15pub mod error;
16pub mod network;
17pub use crate::routing_policy::{
18 BuiltinRoutePicker, OccupancyReservation, OccupancySelection, RouteTarget,
19 RoutingOccupancyState,
20};
21pub use network::egress::addressed_router::{
22 AddressedPushRouter, AddressedRequest, StreamingDispatch, attach_first_response_guard,
23 propagate_first_response_guard,
24};
25pub use network::egress::push_router::{
26 MultimodalCacheIndex, MultimodalCacheKeyExtractor, PushRouter, RouterMode, WorkerLoadMonitor,
27};
28pub mod registry;
29
30pub use crate::engine::{
31 self as engine, AsyncEngine, AsyncEngineContext, AsyncEngineContextProvider, AsyncEngineStream,
32 Data, DataStream, Engine, EngineStream, EngineUnary, ResponseStream, async_trait,
33};
34pub use anyhow::Error;
35pub use context::Context;
36pub use error::{PipelineError, PipelineErrorExt, TwoPartCodecError};
37
38pub type SingleIn<T> = Context<T>;
41
42pub struct RequestStream<T: Data> {
47 inner: std::sync::Mutex<Option<DataStream<T>>>,
48}
49
50impl<T: Data> RequestStream<T> {
51 pub fn new(stream: DataStream<T>) -> Self {
53 Self {
54 inner: std::sync::Mutex::new(Some(stream)),
55 }
56 }
57
58 pub fn take(&self) -> Option<DataStream<T>> {
63 self.inner.lock().unwrap().take()
64 }
65}
66
67impl<T: Data> std::fmt::Debug for RequestStream<T> {
68 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
69 let taken = self.inner.lock().map(|g| g.is_none()).unwrap_or(true);
70 f.debug_struct("RequestStream")
71 .field("taken", &taken)
72 .finish()
73 }
74}
75
76pub type ManyIn<T> = Context<RequestStream<T>>;
80
81pub type SingleOut<T> = EngineUnary<T>;
83
84pub type ManyOut<T> = EngineStream<T>;
86
87pub type ServiceEngine<T, U> = Engine<T, U, Error>;
88
89pub type UnaryEngine<T, U> = ServiceEngine<SingleIn<T>, SingleOut<U>>;
91
92pub type ClientStreamingEngine<T, U> = ServiceEngine<ManyIn<T>, SingleOut<U>>;
96
97pub type ServerStreamingEngine<T, U> = ServiceEngine<SingleIn<T>, ManyOut<U>>;
99
100pub type BidirectionalStreamingEngine<T, U> = ServiceEngine<ManyIn<T>, ManyOut<U>>;
103
104pub trait AsyncTransportEngine<T: Data + PipelineIO, U: Data + PipelineIO>:
105 AsyncEngine<T, U, Error> + Send + Sync + 'static
106{
107}
108
109mod sealed {
112 use super::*;
113
114 #[allow(dead_code)]
115 pub struct Token;
116
117 pub trait Connectable {
118 type DataType: Data;
119 }
120
121 impl<T: Data> Connectable for Context<T> {
122 type DataType = T;
123 }
124 impl<T: Data> Connectable for EngineUnary<T> {
125 type DataType = T;
126 }
127 impl<T: Data> Connectable for EngineStream<T> {
128 type DataType = T;
129 }
130}
131
132pub trait PipelineIO: sealed::Connectable + AsyncEngineContextProvider + 'static {
133 fn id(&self) -> String;
134}
135
136impl<T: Data> PipelineIO for Context<T> {
137 fn id(&self) -> String {
138 self.id().to_string()
139 }
140}
141impl<T: Data> PipelineIO for EngineUnary<T> {
142 fn id(&self) -> String {
143 self.context().id().to_string()
144 }
145}
146impl<T: Data> PipelineIO for EngineStream<T> {
147 fn id(&self) -> String {
148 self.context().id().to_string()
149 }
150}
151
152#[derive(Serialize, Deserialize, Debug, Clone)]
153pub struct Event {
154 pub id: String,
155}