pub struct AdapterRegistry<W: Workflow> { /* private fields */ }Expand description
Runtime registry of MessageAdapters for a single workflow type W.
Adapters are registered at startup via AdapterRegistry::register.
After all adapters are registered, call AdapterRegistry::validate_policy
to confirm that every format version declared in the workflow’s
WorkflowVersionPolicy is covered by at least one adapter.
§Example
use mako_engine::message_adapter::AdapterRegistry;
let mut registry: AdapterRegistry<MyWorkflow> = AdapterRegistry::new();
registry.register(MyFV2025Adapter);
registry.register(MyFV2026Adapter);
registry
.validate_policy(
&MyWorkflow::version_policy(),
&[
FormatVersion::new("FV2025-10-01"),
FormatVersion::new("FV2026-10-01"),
],
)
.expect("all format versions must have a registered adapter");Implementations§
Source§impl<W: Workflow> AdapterRegistry<W>
impl<W: Workflow> AdapterRegistry<W>
Sourcepub fn register(&mut self, adapter: impl MessageAdapter<W>)
pub fn register(&mut self, adapter: impl MessageAdapter<W>)
Register an adapter.
Multiple adapters can be registered. When AdapterRegistry::dispatch
is called, the first adapter that returns true from
accepts_format_version is used. Register the most specific adapters
first.
Sourcepub fn dispatch(
&self,
raw: &dyn Any,
fv: &FormatVersion,
) -> Result<W::Command, EngineError>
pub fn dispatch( &self, raw: &dyn Any, fv: &FormatVersion, ) -> Result<W::Command, EngineError>
Dispatch raw to the first adapter that accepts fv.
§Errors
Returns EngineError::Workflow wrapping
WorkflowError::other("no adapter registered for format version …")
when no registered adapter claims fv.
Propagates the adapter’s own error otherwise.
Sourcepub fn validate_policy(
&self,
policy: &WorkflowVersionPolicy,
known_fvs: &[FormatVersion],
) -> Result<(), Vec<FormatVersion>>
pub fn validate_policy( &self, policy: &WorkflowVersionPolicy, known_fvs: &[FormatVersion], ) -> Result<(), Vec<FormatVersion>>
Validate that every format version in known_fvs is covered by at
least one registered adapter, according to policy.
known_fvs is typically the set of all registered BDEW profiles for
the workflow’s message type. In practice, call this at engine startup
with the format versions returned by ReleaseRegistry::all_profiles().
§Behaviour per policy
| Policy | Validation rule |
|---|---|
Pinned | All known_fvs must be covered. A Pinned workflow can be |
| started under any known FV; every one of them must have an adapter. | |
ForwardCompatible | Same — all known_fvs must be covered so the |
| workflow can handle messages in every FV it may encounter. | |
Explicit(list) | Only the explicitly listed FVs must be covered. |
Passing an empty known_fvs slice skips all coverage checks and
always returns Ok(()).
§Errors
Returns a non-empty list of uncovered format versions. The engine should treat this as a startup error rather than a runtime error.
Sourcepub fn covered_versions<'a>(
&self,
candidate_fvs: &'a [FormatVersion],
) -> Vec<&'a FormatVersion>
pub fn covered_versions<'a>( &self, candidate_fvs: &'a [FormatVersion], ) -> Vec<&'a FormatVersion>
Returns a list of all format versions for which at least one adapter
returns true from accepts_format_version, out of the given
candidate_fvs set.