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 InstanceSelector, ModeSelectors, 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, PushRouterOptions, RouterMode,
27 WorkerLoadMonitor,
28};
29pub mod registry;
30
31pub use crate::engine::{
32 self as engine, AsyncEngine, AsyncEngineContext, AsyncEngineContextProvider, AsyncEngineStream,
33 Data, DataStream, Engine, EngineStream, EngineUnary, ResponseStream, async_trait,
34};
35pub use anyhow::Error;
36pub use context::Context;
37pub use error::{PipelineError, PipelineErrorExt, TwoPartCodecError};
38
39pub type SingleIn<T> = Context<T>;
42
43pub struct RequestStream<T: Data> {
48 inner: std::sync::Mutex<Option<DataStream<T>>>,
49}
50
51impl<T: Data> RequestStream<T> {
52 pub fn new(stream: DataStream<T>) -> Self {
54 Self {
55 inner: std::sync::Mutex::new(Some(stream)),
56 }
57 }
58
59 pub fn take(&self) -> Option<DataStream<T>> {
64 self.inner.lock().unwrap().take()
65 }
66}
67
68impl<T: Data> std::fmt::Debug for RequestStream<T> {
69 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
70 let taken = self.inner.lock().map(|g| g.is_none()).unwrap_or(true);
71 f.debug_struct("RequestStream")
72 .field("taken", &taken)
73 .finish()
74 }
75}
76
77pub type ManyIn<T> = Context<RequestStream<T>>;
81
82pub type SingleOut<T> = EngineUnary<T>;
84
85pub type ManyOut<T> = EngineStream<T>;
87
88pub type ServiceEngine<T, U> = Engine<T, U, Error>;
89
90pub type UnaryEngine<T, U> = ServiceEngine<SingleIn<T>, SingleOut<U>>;
92
93pub type ClientStreamingEngine<T, U> = ServiceEngine<ManyIn<T>, SingleOut<U>>;
97
98pub type ServerStreamingEngine<T, U> = ServiceEngine<SingleIn<T>, ManyOut<U>>;
100
101pub type BidirectionalStreamingEngine<T, U> = ServiceEngine<ManyIn<T>, ManyOut<U>>;
104
105pub trait AsyncTransportEngine<T: Data + PipelineIO, U: Data + PipelineIO>:
106 AsyncEngine<T, U, Error> + Send + Sync + 'static
107{
108}
109
110mod sealed {
113 use super::*;
114
115 #[allow(dead_code)]
116 pub struct Token;
117
118 pub trait Connectable {
119 type DataType: Data;
120 }
121
122 impl<T: Data> Connectable for Context<T> {
123 type DataType = T;
124 }
125 impl<T: Data> Connectable for EngineUnary<T> {
126 type DataType = T;
127 }
128 impl<T: Data> Connectable for EngineStream<T> {
129 type DataType = T;
130 }
131}
132
133pub trait PipelineIO: sealed::Connectable + AsyncEngineContextProvider + 'static {
134 fn id(&self) -> String;
135}
136
137impl<T: Data> PipelineIO for Context<T> {
138 fn id(&self) -> String {
139 self.id().to_string()
140 }
141}
142impl<T: Data> PipelineIO for EngineUnary<T> {
143 fn id(&self) -> String {
144 self.context().id().to_string()
145 }
146}
147impl<T: Data> PipelineIO for EngineStream<T> {
148 fn id(&self) -> String {
149 self.context().id().to_string()
150 }
151}
152
153#[derive(Serialize, Deserialize, Debug, Clone)]
154pub struct Event {
155 pub id: String,
156}