pub struct FlowController { /* private fields */ }Expand description
Flow control for hierarchical message routing
Provides bandwidth limiting and backpressure for cell and zone level routing.
Implementations§
Source§impl FlowController
impl FlowController
Sourcepub fn new(
cell_limit: BandwidthLimit,
zone_limit: BandwidthLimit,
drop_policy: MessageDropPolicy,
) -> Self
pub fn new( cell_limit: BandwidthLimit, zone_limit: BandwidthLimit, drop_policy: MessageDropPolicy, ) -> Self
Create a new flow controller
Sourcepub async fn acquire_permit(
&self,
level: RoutingLevel,
message_size: usize,
priority: MessagePriority,
) -> Result<Permit>
pub async fn acquire_permit( &self, level: RoutingLevel, message_size: usize, priority: MessagePriority, ) -> Result<Permit>
Acquire permit to send a message
This will block if rate limits are exceeded, applying backpressure.
Sourcepub async fn has_backpressure(&self) -> bool
pub async fn has_backpressure(&self) -> bool
Check if backpressure is currently active
Sourcepub async fn acquire_permit_qos(
&self,
level: RoutingLevel,
message_size: usize,
qos_class: QoSClass,
) -> Result<Permit>
pub async fn acquire_permit_qos( &self, level: RoutingLevel, message_size: usize, qos_class: QoSClass, ) -> Result<Permit>
Acquire permit using QoSClass instead of MessagePriority
This method provides QoS-aware flow control by converting QoSClass to MessagePriority for the underlying rate limiter. Higher QoS classes (Critical, High) receive preferential treatment with lower token consumption.
§Arguments
level- The routing level (Cell or Zone)message_size- Size of the message in bytesqos_class- The QoS classification for priority handling
§Example
use peat_protocol::hierarchy::flow_control::{FlowController, RoutingLevel};
use peat_protocol::qos::QoSClass;
let controller = FlowController::new(/* ... */);
let permit = controller.acquire_permit_qos(
RoutingLevel::Cell,
1024,
QoSClass::Critical,
).await?;Sourcepub fn should_drop_qos(&self, qos_class: QoSClass) -> bool
pub fn should_drop_qos(&self, qos_class: QoSClass) -> bool
Determine if a message should be dropped based on QoS class
Higher priority classes (Critical, High) are never dropped. Lower priority classes may be dropped under backpressure.
Sourcepub async fn release_backpressure(&self)
pub async fn release_backpressure(&self)
Release backpressure
Sourcepub fn should_drop(&self, priority: MessagePriority) -> bool
pub fn should_drop(&self, priority: MessagePriority) -> bool
Determine if a message should be dropped based on policy
Sourcepub fn record_drop(&self)
pub fn record_drop(&self)
Record a dropped message
Sourcepub fn get_metrics(&self) -> FlowMetrics
pub fn get_metrics(&self) -> FlowMetrics
Get flow control metrics
Sourcepub async fn available_capacity(&self, level: RoutingLevel) -> CapacityInfo
pub async fn available_capacity(&self, level: RoutingLevel) -> CapacityInfo
Get current available capacity
Auto Trait Implementations§
impl Freeze for FlowController
impl !RefUnwindSafe for FlowController
impl Send for FlowController
impl Sync for FlowController
impl Unpin for FlowController
impl UnsafeUnpin for FlowController
impl !UnwindSafe for FlowController
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more