Skip to main content

Context

Struct Context 

Source
pub struct Context<'a> { /* private fields */ }
Expand description

То, что модуль получает от инстанса при создании. Действует, пока выполняется точка создания.

Счётчик метрик действует только в точке создания: инструменты создаются в ней и остаются у модуля. Учёт нагрузки — дескриптор: его сохраняют на всё время жизни модуля.

Implementations§

Source§

impl<'a> Context<'a>

Source

pub fn name(&self) -> &'static str

Имя модуля.

Source

pub fn health(&mut self) -> Health

Здоровье модуля. Первый вызов создаёт дескриптор и регистрирует его в инстансе. Модуль без дескриптора считается работающим. Новый дескриптор сообщает фазу Starting.

Source

pub fn token(&self) -> CancellationToken

Токен модуля: под ним живёт его фоновая работа. Отменяется при остановке инстанса, после дренажа.

Source

pub fn dependency(&mut self, name: impl Into<String>) -> DependencyBuilder<'_>

Зарегистрировать зависимость от соседа.

Source

pub fn apoptosis(&self) -> Apoptosis

Отчёт о нехватке памяти, которую не исправить.

Source

pub fn stopper(&self) -> Stopper

Остановщик инстанса: штатная остановка (stop) и фатальная (fatal), когда продолжать работу опасно.

Source

pub fn grpc(&self) -> Grpc

Привязка gRPC-служб модуля. Служба привязывается в точке создания модуля: bind получает сервер службы, собранный кодогенерацией.

Source

pub fn clients(&self) -> &ClientFactory

Фабрика клиентов к соседям: единственный способ создать клиент.

Source

pub fn meter(&self) -> &Meter

Счётчик метрик: инструменты модуля создаются здесь, с префиксом службы.

Source

pub fn load(&self) -> Load

Учёт нагрузки: время фоновой работы модуля попадает в worker_load.

Source

pub fn http(&self) -> Http

HTTP-поверхности интеграции: модуль заявляет свой роутер на порт.

Source

pub fn in_process(&self) -> InProcess

Вызов gRPC-метода в процессе: тот же роутер, что у слушателя, без сети.

Source

pub fn call_guard(&self, guard: Arc<dyn CallGuard>)

Добавить проверку входящего gRPC-вызова: она выполняется до метода службы и может дополнить запрос своим результатом (например, принципалом).

Source

pub fn register_surface_guard( &self, name: &'static str, guard: Arc<dyn SurfaceGuard>, ) -> Result<(), SurfaceGuardError>

Поставить защиту HTTP-поверхности name; её забирает модуль интеграции.

§Ошибки

SurfaceGuardError::Duplicate — защита с таким именем уже поставлена.

Source

pub fn surface_guard(&self, name: &str) -> Option<Arc<dyn SurfaceGuard>>

Защита HTTP-поверхности name, если её поставил модуль-поставщик.

Source

pub fn service(&self) -> &Service

Служба инстанса: имя и версия для сведений и MCP-сервера.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Context<'a>

§

impl<'a> !UnwindSafe for Context<'a>

§

impl<'a> Forget for Context<'a>

§

impl<'a> Freeze for Context<'a>
where &'static str: Freeze, *const ArcInner<Inner> is !null: Freeze, PhantomData<ArcInner<Inner>>: Freeze, &'a mut Dependencies: Freeze, *const ArcInner<TreeNode> is !null: Freeze, PhantomData<ArcInner<TreeNode>>: Freeze, *const ArcInner<Shared<Option<Stop>>> is !null: Freeze, PhantomData<ArcInner<Shared<Option<Stop>>>>: Freeze, &'a Telemetry: Freeze, &'a Binder: Freeze, &'a ClientFactory: Freeze, &'a HttpSurfaces: Freeze, &'a InProcess: Freeze, &'a CallGuards: Freeze, &'a SurfaceGuards: Freeze, &'a Service: Freeze,

§

impl<'a> Move for Context<'a>

§

impl<'a> Send for Context<'a>
where &'static str: Send, Arc<Inner>: Send, RawVecInner: Send, Arc<TreeNode>: Send, JoinHandle<()>: Send, Arc<Shared<DependencyInfo>>: Send, Arc<Shared<Option<Stop>>>: Send, &'a Telemetry: Send, &'a Binder: Send, &'a ClientFactory: Send, &'a HttpSurfaces: Send, &'a InProcess: Send, &'a CallGuards: Send, &'a SurfaceGuards: Send, &'a Service: Send,

§

impl<'a> Sync for Context<'a>
where Arc<Inner>: Sync, RawVecInner: Sync, Arc<TreeNode>: Sync, JoinHandle<()>: Sync, Arc<Shared<DependencyInfo>>: Sync, Arc<Shared<Option<Stop>>>: Sync, Arc<Registry>: Sync, Arc<InstrumentState<Family<Labels, Counter>>>: Sync, Arc<InstrumentState<Family<Labels, Gauge<f64, Atomic<u64>>>>>: Sync, Arc<InstrumentState<Family<Labels, Histogram, HistogramConstructor>>>: Sync, Mutex<[u64; 6]>: Sync, NodeRef<Owned, String, Vec<f64>, LeafOrInternal>: Sync, BoxRaw<(String, Vec<f64>)>: Sync, Arc<Shared>: Sync, Arc<State>: Sync, Arc<Mutex<Inner>>: Sync, Arc<Settings>: Sync, Arc<dyn CallLoad>: Sync, Arc<ClientLog>: Sync, Arc<Inner>: Sync, Arc<Mutex<Inner>>: Sync, Arc<OnceLock<Router>>: Sync, Arc<Mutex<Vec<Arc<dyn CallGuard>>>>: Sync, Arc<Mutex<HashMap<&'static str, Arc<dyn SurfaceGuard>>>>: Sync,

§

impl<'a> Unpin for Context<'a>
where &'static str: Unpin, Arc<Inner>: Unpin, &'a mut Dependencies: Unpin, Arc<TreeNode>: Unpin, Arc<Shared<Option<Stop>>>: Unpin, &'a Telemetry: Unpin, &'a Binder: Unpin, &'a ClientFactory: Unpin, &'a HttpSurfaces: Unpin, &'a InProcess: Unpin, &'a CallGuards: Unpin, &'a SurfaceGuards: Unpin, &'a Service: Unpin,

§

impl<'a> UnsafeUnpin for Context<'a>
where &'static str: UnsafeUnpin, *const ArcInner<Inner> is !null: UnsafeUnpin, PhantomData<ArcInner<Inner>>: UnsafeUnpin, &'a mut Dependencies: UnsafeUnpin, *const ArcInner<TreeNode> is !null: UnsafeUnpin, PhantomData<ArcInner<TreeNode>>: UnsafeUnpin, *const ArcInner<Shared<Option<Stop>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Shared<Option<Stop>>>>: UnsafeUnpin, &'a Telemetry: UnsafeUnpin, &'a Binder: UnsafeUnpin, &'a ClientFactory: UnsafeUnpin, &'a HttpSurfaces: UnsafeUnpin, &'a InProcess: UnsafeUnpin, &'a CallGuards: UnsafeUnpin, &'a SurfaceGuards: UnsafeUnpin, &'a Service: UnsafeUnpin,

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

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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<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