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 均经此)。

日志纪律(0.3.0):宿主不提供日志载荷类型;要写业务日志,插件自造 载荷自理(业务链上用 ek-data 的 LogData 到 “eLog” 键后 put)。

Source

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

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

Source

pub fn plugins(&self) -> Vec<PluginInfo>

枚举宿主内全部插件(含 Ready;快照含版本)。

Source

pub fn services_of(&self, name: &str) -> Option<Arc<Vec<ServiceDesc>>>

某插件自报的完整服务目录(现场取 + 世代核对 + memoize)。 Ready 未 Running 亦可查(声明在注册时即静态可用)。 该插件不存在 → None。

Source

pub fn find_service(&self, svc: &str) -> Vec<ProviderRef>

按【服务 id】全宿主查找提供方(有序:注册序;含非 Running 状态 → 供消费方自裁)。 A 不需要预先知道提供方的注册名。

Source

pub fn publish_services(&self, list: Vec<ServiceDesc>)

运行期重新申报自己的服务目录:宿主重织索引、作废缓存,双发 eSrvChg.<名>(版本串) 与 eSrvChg(固定键,PlugNotice)。

⚠ 纪律(DV4 教训):先换插件 services() 当前返回,再调用本方法 —— 宿主细节是现场取的,只申报不改内容会造成索引与 live 细节脱节。

(0.2.0:Rust 无运行期代码热换;「更新」的运行期形态 = 目录随配置/状态改版。)

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 + std mpsc 一次性信道。

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

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

  • 预检失败(不存在/未 Running/已 Quarantined)→ 立即 Err(TargetGone);
  • 回包 Ok(Res) 且契约类型匹配 → Ok(Res);
  • 回包 Err(InvalidPayload) 或 回包类型与本侧契约不一致 → Err(InvalidPayload);
  • 信道断连(handler panic/信封丢失/目标邮箱溢出被丢)→ Err(TargetGone)(尽快,不虚耗超时);
  • 等满时限 → Err(Timeout);
  • put 失败(总线已停)→ Err(BusStopped)。
Source

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

按服务 id 的请求出口(0.2.0):index 命中 → 现场类型闸门 → 发 eReq。

  • 无人提供该服务 → 立即 Err(UnknownService)(零成本显错);
  • 有提供方但全都非 Running → 立即 Err(TargetGone);
  • Req 类型与服务声明的 req_type 不符 → 立即 Err(InvalidPayload) (把「绕一圈才发现错型」提前到发出之前);
  • 多提供方 → 取注册序第一个 Running 者;后续 failover 由发起方在收不到回包后自定。 其余失败面与 ask 完全一致。

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.