pub struct KompactConfig { /* private fields */ }Expand description
A configuration builder for Kompact systems
§Example
Set a custom label, and run up to 50 events or messages per scheduling of a component on a threadpool with 2 threads.
use kompact::prelude::*;
let mut conf = KompactConfig::default();
conf.label("My special system")
.throughput(50)
.threads(2);
let system = conf.build().wait().expect("system");Implementations§
Source§impl KompactConfig
impl KompactConfig
Sourcepub fn new() -> KompactConfig
👎Deprecated since 0.11.0: If you really want these exact parameters, use KompactConfig::load_config_str(kompact::runtime::MINIMAL_CONFIG) instead. Otherwise prefer KompactConfig::default().
pub fn new() -> KompactConfig
If you really want these exact parameters, use KompactConfig::load_config_str(kompact::runtime::MINIMAL_CONFIG) instead. Otherwise prefer KompactConfig::default().
Create a minimal Kompact config
- The minimal config uses the default label, i.e.
"kompact-runtime-{}"for some sequence number. - It sets the event/message throughput to 2, split evenly between events and messages.
- It runs with a single thread on a small pool.
- It uses all default components, without networking, with the default timer and default logger.
Sourcepub fn label<I>(&mut self, s: I) -> &mut KompactConfig
👎Deprecated since 0.11.0: Use KompactConfig::set_config_value(&kompact::config_keys::system::LABEL, ...) instead.
pub fn label<I>(&mut self, s: I) -> &mut KompactConfig
Use KompactConfig::set_config_value(&kompact::config_keys::system::LABEL, ...) instead.
Set the name of the system
The label is used as metadata for logging output.
Sourcepub fn throughput(&mut self, n: usize) -> &mut KompactConfig
👎Deprecated since 0.11.0: Use KompactConfig::set_config_value(&kompact::config_keys::system::THROUGHPUT, ...) instead.
pub fn throughput(&mut self, n: usize) -> &mut KompactConfig
Use KompactConfig::set_config_value(&kompact::config_keys::system::THROUGHPUT, ...) instead.
Set the maximum number of events/messages to handle before rescheduling a component
Larger values can increase throughput on highly loaded components, but at the cost of fairness between components.
Sourcepub fn msg_priority(&mut self, r: f32) -> &mut KompactConfig
👎Deprecated since 0.11.0: Use KompactConfig::set_config_value(&kompact::config_keys::system::MESSAGE_PRIORITY, ...) instead.
pub fn msg_priority(&mut self, r: f32) -> &mut KompactConfig
Use KompactConfig::set_config_value(&kompact::config_keys::system::MESSAGE_PRIORITY, ...) instead.
Set the ratio between handling messages and events.
A component will handle up to throughput * r messages and throughput * (1-r) events before rescheduling.
If there are less events or messages than alloted queued up the remaining allotment will be redistributed to the other type until all throughput is used up or no messages or events remain.
Sourcepub fn threads(&mut self, n: usize) -> &mut KompactConfig
👎Deprecated since 0.11.0: Use KompactConfig::set_config_value(&kompact::config_keys::system::THREADS, ...) instead.
pub fn threads(&mut self, n: usize) -> &mut KompactConfig
Use KompactConfig::set_config_value(&kompact::config_keys::system::THREADS, ...) instead.
Sourcepub fn scheduler<F>(&mut self, f: F) -> &mut KompactConfig
pub fn scheduler<F>(&mut self, f: F) -> &mut KompactConfig
Set a particular scheduler implementation
Takes a function f from the number of threads to a concrete scheduler implementation as argument.
Sourcepub fn executor<E, F>(&mut self, f: F) -> &mut KompactConfig
pub fn executor<E, F>(&mut self, f: F) -> &mut KompactConfig
Set a particular scheduler implementation based on a FuturesExecutor
Takes a function f from the number of threads to a concrete executor as argument.
Sourcepub fn timer<T, F>(&mut self, f: F) -> &mut KompactConfig
pub fn timer<T, F>(&mut self, f: F) -> &mut KompactConfig
Set a particular timer implementation
Sourcepub fn system_components<B, C, FB, FC>(
&mut self,
deadletter_fn: FB,
dispatcher_fn: FC,
) -> &mut KompactConfigwhere
B: ComponentDefinition<Message = !> + ActorRaw + 'static,
C: ComponentDefinition<Message = DispatchEnvelope> + ActorRaw + 'static + Dispatcher,
FB: Fn(KPromise<()>) -> B + 'static,
FC: Fn(KPromise<()>) -> C + 'static,
pub fn system_components<B, C, FB, FC>(
&mut self,
deadletter_fn: FB,
dispatcher_fn: FC,
) -> &mut KompactConfigwhere
B: ComponentDefinition<Message = !> + ActorRaw + 'static,
C: ComponentDefinition<Message = DispatchEnvelope> + ActorRaw + 'static + Dispatcher,
FB: Fn(KPromise<()>) -> B + 'static,
FC: Fn(KPromise<()>) -> C + 'static,
Set a particular set of system components
In particular, this allows exchanging the default dispatcher for a custom one.
The default transport-backed dispatcher lives in the separate kompact-net crate.
§Example
For configuring an explicit local dispatcher, with the default deadletter box:
use kompact::prelude::*;
let mut cfg = KompactConfig::new();
cfg.system_components(DeadletterBox::new, LocalDispatcher::new);
let system = cfg.build().wait().expect("KompactSystem");Sourcepub fn system_components_with_dedicated_dispatcher<B, C, FB, FC>(
&mut self,
deadletter_fn: FB,
dispatcher_fn: FC,
) -> &mut KompactConfigwhere
B: ComponentDefinition<Message = !> + ActorRaw + 'static,
C: ComponentDefinition<Message = DispatchEnvelope> + ActorRaw + 'static + Dispatcher,
FB: Fn(KPromise<()>) -> B + 'static,
FC: Fn(KPromise<()>) -> C + 'static,
pub fn system_components_with_dedicated_dispatcher<B, C, FB, FC>(
&mut self,
deadletter_fn: FB,
dispatcher_fn: FC,
) -> &mut KompactConfigwhere
B: ComponentDefinition<Message = !> + ActorRaw + 'static,
C: ComponentDefinition<Message = DispatchEnvelope> + ActorRaw + 'static + Dispatcher,
FB: Fn(KPromise<()>) -> B + 'static,
FC: Fn(KPromise<()>) -> C + 'static,
Set a particular set of system components
This function works just like system_components, except that it assigns the dispatcher to its own thread using create_dedicated_unsupervised.
Sourcepub fn logger(&mut self, logger: Logger<Arc<Fuse<Async>>>) -> &mut KompactConfig
pub fn logger(&mut self, logger: Logger<Arc<Fuse<Async>>>) -> &mut KompactConfig
Set the logger implementation to use
Sourcepub fn load_config_file<P>(&mut self, path: P) -> &mut KompactConfig
pub fn load_config_file<P>(&mut self, path: P) -> &mut KompactConfig
Load a TOML config from a file at path
This method can be called multiple times, and the resulting configurations will be merged.
It matters in which order configs are loaded and values are set.
The loaded config can be accessed via [system.config()](KompactSystem::config
or from within a component via [self.ctx().config()](ComponentContext::config.
Sourcepub fn load_config_str<S>(&mut self, config: S) -> &mut KompactConfig
pub fn load_config_str<S>(&mut self, config: S) -> &mut KompactConfig
Load a TOML config from a string
This method can be called multiple times, and the resulting configurations will be merged.
It matters in which order configs are loaded and values are set.
The loaded config can be accessed via [system.config()](KompactSystem::config
or from within a component via [self.ctx().config()](ComponentContext::config.
Sourcepub fn set_config_value<T>(
&mut self,
config: &ConfigEntry<T>,
value: <T as ConfigValueType>::Value,
) -> &mut KompactConfigwhere
T: ConfigValueType,
pub fn set_config_value<T>(
&mut self,
config: &ConfigEntry<T>,
value: <T as ConfigValueType>::Value,
) -> &mut KompactConfigwhere
T: ConfigValueType,
Override a single value in the config
This method can be called multiple times and the resulting configurations will be merged.
It matters in which order configs are loaded and values are set.
Sourcepub fn build(
self,
) -> impl Future<Output = Result<KompactSystem, KompactError>> + Unpin + 'static
pub fn build( self, ) -> impl Future<Output = Result<KompactSystem, KompactError>> + Unpin + 'static
Finalise the config and use it to create a KompactSystem.
This function returns a future that starts the system’s internal components
and completes once they are ready. Async callers should .await it, while
synchronous callers can use
BlockingFutureExt::wait or
BlockingFutureExt::wait_timeout.
Dropping the returned future before it completes may leave a partially started system running in the background, so callers should await it or block on it to completion.
§Example
Build a system with default settings with:
use kompact::prelude::*;
let system = KompactConfig::default().build().wait().expect("system");Trait Implementations§
Source§impl Clone for KompactConfig
impl Clone for KompactConfig
Source§fn clone(&self) -> KompactConfig
fn clone(&self) -> KompactConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KompactConfig
impl Debug for KompactConfig
Source§impl Default for KompactConfig
impl Default for KompactConfig
Source§fn default() -> KompactConfig
fn default() -> KompactConfig
Create a default Kompact config
§Defaults
See the following configuration keys for the default values:
It uses all default components, without networking, with the default timer and default logger.