Skip to main content

PluginContext

Struct PluginContext 

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

发放到插件的上下文(on_init 传入;Clone 供插件自存)。

Implementations§

Source§

impl PluginContext

Source

pub fn name(&self) -> &str

本插件注册名。

Source

pub fn put(&self, event: Event) -> Result<(), PutError>

广播出口:插件自发事件(业务 broadcast / eTo / eLog 均经此)。

Source

pub fn write_log(&self, level: u8, msg: &str)

日志出口(eLog → 内置 LogPlugin)。

Source

pub fn notify(&self, target: &str, payload: Arc<dyn Any + Send + Sync>)

定向通知出口:eTo.,无回包;目标不在线时事件被静默分发为空(尽力而为)。

Source

pub fn ask<Req, Res>( &self, target: &str, req: Req, timeout: Duration, ) -> Result<Res, AskError>
where Req: Any + Send + Sync, Res: Any + Send + Sync,

请求出口:eReq. + Envelope{payload, reply} + std mpsc 一次性信道。

禁止自呼:ask 指向自身 target 会占满自己的 worker 直到超时 (自己阻塞等自己的回包,worker 无法转去处理请求)——需要自身逻辑请直调。

时序:预检目标 Running → put → recv_timeout。

  • 预检失败(不存在/未 Running/已 Quarantined)→ 立即 Err(TargetGone);
  • 回包 Ok(Res) 且契约类型匹配 → Ok(Res);
  • 回包 Err(InvalidPayload) 或 回包类型与本侧契约不一致 → Err(InvalidPayload);
  • 信道断连(handler panic/信封丢失/目标邮箱溢出被丢)→ Err(TargetGone)(尽快,不虚耗超时); 注:目标邮箱溢出时 forwarder 弃整个请求事件,信封随之 drop → 回包信道立即关闭, 发起方走 TargetGone 快失败;同时宿主侧有溢出丢弃 eLog 节流告警(可追溯);
  • 等满时限 → Err(Timeout);
  • put 失败(总线已停)→ Err(BusStopped)。

TargetGone 的即时性为「尽力而为」:预检 + 断连快失败覆盖绝大多数场合; 极端 TOCTOU 窗口(预检后瞬间目标下线且断连未被感知)由 Timeout 兜底。

Trait Implementations§

Source§

impl Clone for PluginContext

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.