Skip to main content

ListenerPipelines

Struct ListenerPipelines 

Source
pub struct ListenerPipelines { /* private fields */ }
Expand description

Maps listener names to their resolved FilterPipelines.

Each pipeline is wrapped in ArcSwap so it can be atomically replaced at runtime without blocking in-flight requests.

use std::{collections::HashMap, sync::Arc};

use praxis_filter::{FilterPipeline, FilterRegistry};
use praxis_protocol::ListenerPipelines;

let registry = FilterRegistry::with_builtins();
let pipeline = Arc::new(FilterPipeline::build(&mut [], &registry).unwrap());

let mut map = HashMap::new();
map.insert("web".to_owned(), pipeline);
let pipelines = ListenerPipelines::new(map);

assert!(pipelines.get("web").is_some());
assert!(pipelines.get("missing").is_none());

Implementations§

Source§

impl ListenerPipelines

Source

pub fn new(pipelines: HashMap<String, Arc<FilterPipeline>>) -> Self

Create from a map of listener name to pipeline.

Called by the server during startup after building filter pipelines from the loaded configuration. Each pipeline is wrapped in ArcSwap for atomic replacement during hot reloads.

Source

pub fn with_protocols( pipelines: HashMap<String, Arc<FilterPipeline>>, protocols: HashMap<String, ProtocolKind>, ) -> Self

Create from a map of listener name to pipeline, recording the protocol each listener’s pipeline was resolved for.

use std::{collections::HashMap, sync::Arc};

use praxis_core::config::ProtocolKind;
use praxis_filter::{FilterPipeline, FilterRegistry};
use praxis_protocol::ListenerPipelines;

let registry = FilterRegistry::with_builtins();
let pipeline = Arc::new(FilterPipeline::build(&mut [], &registry).unwrap());

let mut map = HashMap::new();
map.insert("db".to_owned(), pipeline);
let mut protocols = HashMap::new();
protocols.insert("db".to_owned(), ProtocolKind::Tcp);
let pipelines = ListenerPipelines::with_protocols(map, protocols);

assert_eq!(pipelines.protocol("db"), Some(ProtocolKind::Tcp));
Source

pub fn protocol(&self, listener_name: &str) -> Option<ProtocolKind>

The protocol a listener’s pipelines are resolved for, if recorded.

Fixed at construction: a swap never changes it.

Source

pub fn get(&self, listener_name: &str) -> Option<&Arc<ArcSwap<FilterPipeline>>>

Get the swappable pipeline for a listener by name.

Called by protocol adapters on every request to access the filter pipeline. The returned ArcSwap reference allows protocol adapters to load the current pipeline without blocking reload operations.

Source

pub fn swap(&self, listener_name: &str, new_pipeline: Arc<FilterPipeline>)

Atomically replace the pipeline for a listener.

No-op if the listener name is not present.

use std::{collections::HashMap, sync::Arc};

use praxis_filter::{FilterPipeline, FilterRegistry};
use praxis_protocol::ListenerPipelines;

let registry = FilterRegistry::with_builtins();
let old = Arc::new(FilterPipeline::build(&mut [], &registry).unwrap());
let new = Arc::new(FilterPipeline::build(&mut [], &registry).unwrap());

let mut map = HashMap::new();
map.insert("web".to_owned(), old);
let pipelines = ListenerPipelines::new(map);

pipelines.swap("web", new);
pipelines.swap(
    "nonexistent",
    Arc::new(FilterPipeline::build(&mut [], &registry).unwrap()),
);
Source

pub fn referenced_files(&self) -> Vec<PathBuf>

Every filesystem path any filter in any listener’s pipeline reads configuration from, de-duplicated.

Two listeners can share a filter chain, so the same document would otherwise appear more than once and be watched and hashed repeatedly.

Source

pub fn listener_names(&self) -> impl Iterator<Item = &str>

Returns an iterator over listener names.

Used during config reload to iterate over all listeners when swapping pipelines or collecting referenced files for watching.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more