Skip to main content

AppState

Struct AppState 

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

线程安全的应用状态,包含服务标识、生命周期及流控所需的并发计数器。

历史上的 peak_processing / total_requests / error_requests 等 统计字段已迁移到 Prometheus(见 src/metrics.rstibba-middleware), 这里只保留流控判断必须的 processing 原子计数。

Implementations§

Source§

impl AppState

Source

pub fn new(processing_limit: i32, commit_id: impl Into<String>) -> Self

创建 AppState,传入最大并发限制和 Git 提交 ID,其余字段使用默认值。

Source

pub fn with_name(self, name: impl Into<String>) -> Self

设置服务名称,支持链式调用。

Source

pub fn with_version(self, version: impl Into<String>) -> Self

设置语义化版本号,支持链式调用。

Source

pub fn get_name(&self) -> &str

返回服务名称。

Source

pub fn get_version(&self) -> &str

返回语义化版本号。

Source

pub fn get_commit_id(&self) -> &str

返回 Git 提交 ID。

Source

pub fn get_processing_limit(&self) -> i32

返回配置的最大并发请求数。

Source

pub fn inc_processing(&self) -> i32

原子性地递增处理计数器,返回递增后的当前并发数。 仅用于 processing_limit 流控判断;统计指标由 Prometheus 负责。

Source

pub fn dec_processing(&self) -> i32

原子性地递减处理计数器,返回递减后的当前并发数。

Source

pub fn get_processing(&self) -> i32

返回当前正在处理的请求数。

Source

pub fn is_running(&self) -> bool

返回 true 表示应用当前处于运行状态。

Source

pub fn run(&self)

将应用状态设为运行中。

Source

pub fn stop(&self)

将应用状态设为已停止。

Source

pub fn get_started_at(&self) -> SystemTime

返回应用的启动时间。

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<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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<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