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 network::egress::addressed_router::{AddressedPushRouter, AddressedRequest};
18pub use network::egress::push_router::{
19 MultimodalCacheIndex, MultimodalCacheKeyExtractor, PushRouter, RouterMode, WorkerLoadMonitor,
20};
21pub mod registry;
22
23pub use crate::engine::{
24 self as engine, AsyncEngine, AsyncEngineContext, AsyncEngineContextProvider, AsyncEngineStream,
25 Data, DataStream, Engine, EngineStream, EngineUnary, ResponseStream, async_trait,
26};
27pub use anyhow::Error;
28pub use context::Context;
29pub use error::{PipelineError, PipelineErrorExt, TwoPartCodecError};
30
31pub type SingleIn<T> = Context<T>;
34
35pub struct RequestStream<T: Data> {
40 inner: std::sync::Mutex<Option<DataStream<T>>>,
41}
42
43impl<T: Data> RequestStream<T> {
44 pub fn new(stream: DataStream<T>) -> Self {
46 Self {
47 inner: std::sync::Mutex::new(Some(stream)),
48 }
49 }
50
51 pub fn take(&self) -> Option<DataStream<T>> {
56 self.inner.lock().unwrap().take()
57 }
58}
59
60impl<T: Data> std::fmt::Debug for RequestStream<T> {
61 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
62 let taken = self.inner.lock().map(|g| g.is_none()).unwrap_or(true);
63 f.debug_struct("RequestStream")
64 .field("taken", &taken)
65 .finish()
66 }
67}
68
69pub type ManyIn<T> = Context<RequestStream<T>>;
73
74pub type SingleOut<T> = EngineUnary<T>;
76
77pub type ManyOut<T> = EngineStream<T>;
79
80pub type ServiceEngine<T, U> = Engine<T, U, Error>;
81
82pub type UnaryEngine<T, U> = ServiceEngine<SingleIn<T>, SingleOut<U>>;
84
85pub type ClientStreamingEngine<T, U> = ServiceEngine<ManyIn<T>, SingleOut<U>>;
89
90pub type ServerStreamingEngine<T, U> = ServiceEngine<SingleIn<T>, ManyOut<U>>;
92
93pub type BidirectionalStreamingEngine<T, U> = ServiceEngine<ManyIn<T>, ManyOut<U>>;
96
97pub trait AsyncTransportEngine<T: Data + PipelineIO, U: Data + PipelineIO>:
98 AsyncEngine<T, U, Error> + Send + Sync + 'static
99{
100}
101
102mod sealed {
105 use super::*;
106
107 #[allow(dead_code)]
108 pub struct Token;
109
110 pub trait Connectable {
111 type DataType: Data;
112 }
113
114 impl<T: Data> Connectable for Context<T> {
115 type DataType = T;
116 }
117 impl<T: Data> Connectable for EngineUnary<T> {
118 type DataType = T;
119 }
120 impl<T: Data> Connectable for EngineStream<T> {
121 type DataType = T;
122 }
123}
124
125pub trait PipelineIO: sealed::Connectable + AsyncEngineContextProvider + 'static {
126 fn id(&self) -> String;
127}
128
129impl<T: Data> PipelineIO for Context<T> {
130 fn id(&self) -> String {
131 self.id().to_string()
132 }
133}
134impl<T: Data> PipelineIO for EngineUnary<T> {
135 fn id(&self) -> String {
136 self.context().id().to_string()
137 }
138}
139impl<T: Data> PipelineIO for EngineStream<T> {
140 fn id(&self) -> String {
141 self.context().id().to_string()
142 }
143}
144
145#[derive(Serialize, Deserialize, Debug, Clone)]
146pub struct Event {
147 pub id: String,
148}