Skip to main content

KompactConfig

Struct KompactConfig 

Source
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

Source

pub 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().

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.
Source

pub fn label<I>(&mut self, s: I) -> &mut KompactConfig
where I: Into<String>,

👎Deprecated since 0.11.0:

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.

Source

pub fn throughput(&mut self, n: usize) -> &mut KompactConfig

👎Deprecated since 0.11.0:

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.

Source

pub 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.

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.

Source

pub fn threads(&mut self, n: usize) -> &mut KompactConfig

👎Deprecated since 0.11.0:

Use KompactConfig::set_config_value(&kompact::config_keys::system::THREADS, ...) instead.

The number of threads in the Kompact thread pool

§Note

You must ensure that the selected scheduler implementation can manage the given number of threads, if you customise this value!

Source

pub fn scheduler<F>(&mut self, f: F) -> &mut KompactConfig
where F: Fn(usize) -> Box<dyn Scheduler> + 'static,

Set a particular scheduler implementation

Takes a function f from the number of threads to a concrete scheduler implementation as argument.

Source

pub fn executor<E, F>(&mut self, f: F) -> &mut KompactConfig
where E: FuturesExecutor + Sync + 'static, F: Fn(usize) -> E + 'static,

Set a particular scheduler implementation based on a FuturesExecutor

Takes a function f from the number of threads to a concrete executor as argument.

Source

pub fn timer<T, F>(&mut self, f: F) -> &mut KompactConfig
where T: TimerComponent + 'static, F: Fn() -> Box<dyn TimerComponent> + 'static,

Set a particular timer implementation

Source

pub fn system_components<B, C, FB, FC>( &mut self, deadletter_fn: FB, dispatcher_fn: FC, ) -> &mut KompactConfig
where 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");
Source

pub fn system_components_with_dedicated_dispatcher<B, C, FB, FC>( &mut self, deadletter_fn: FB, dispatcher_fn: FC, ) -> &mut KompactConfig
where 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.

Source

pub fn logger(&mut self, logger: Logger<Arc<Fuse<Async>>>) -> &mut KompactConfig

Set the logger implementation to use

Source

pub fn load_config_file<P>(&mut self, path: P) -> &mut KompactConfig
where P: Into<PathBuf>,

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.

Source

pub fn load_config_str<S>(&mut self, config: S) -> &mut KompactConfig
where S: Into<String>,

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.

Source

pub fn set_config_value<T>( &mut self, config: &ConfigEntry<T>, value: <T as ConfigValueType>::Value, ) -> &mut KompactConfig
where 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.

Source

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

Source§

fn clone(&self) -> KompactConfig

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
Source§

impl Debug for KompactConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl Default for KompactConfig

Source§

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.

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> TryClone for T
where T: Clone,

Source§

fn try_clone(&self) -> Result<T, SerError>

Tries to produce a copy of self or returns an error
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> Erased for T