[][src]Struct kompact::prelude::KompactConfig

pub struct KompactConfig { /* fields omitted */ }

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().expect("system");

Implementations

impl KompactConfig[src]

pub fn new() -> KompactConfig[src]

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.

pub fn label<I>(&mut self, s: I) -> &mut Self where
    I: Into<String>, 
[src]

Set the name of the system

The label is used as metadata for logging output.

pub fn throughput(&mut self, n: usize) -> &mut Self[src]

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.

pub fn msg_priority(&mut self, r: f32) -> &mut Self[src]

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.

pub fn threads(&mut self, n: usize) -> &mut Self[src]

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!

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

Set a particular scheduler implementation

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

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

Set a particular scheduler implementation based on a FuturesExecutor

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

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

Set a particular timer implementation

pub fn system_components<B, C, FB, FC>(
    &mut self,
    deadletter_fn: FB,
    dispatcher_fn: FC
) -> &mut Self where
    B: ComponentDefinition + ActorRaw<Message = Never> + Sized + 'static,
    C: ComponentDefinition + ActorRaw<Message = DispatchEnvelope> + Sized + 'static + Dispatcher,
    FB: Fn(KPromise<()>) -> B + 'static,
    FC: Fn(KPromise<()>) -> C + 'static, 
[src]

Set a particular set of system components

In particular, this allows exchanging the default dispatcher for the NetworkDispatcher, which enables the created Kompact system to perform network communication.

Example

For using the network dispatcher, with the default deadletter box:

use kompact::prelude::*;

let mut cfg = KompactConfig::new();
cfg.system_components(DeadletterBox::new, {
    let net_config = NetworkConfig::new("127.0.0.1:0".parse().expect("Address should work"));
    net_config.build()
});
let system = cfg.build().expect("KompactSystem");

pub fn system_components_with_dedicated_dispatcher<B, C, FB, FC>(
    &mut self,
    deadletter_fn: FB,
    dispatcher_fn: FC
) -> &mut Self where
    B: ComponentDefinition + ActorRaw<Message = Never> + Sized + 'static,
    C: ComponentDefinition + ActorRaw<Message = DispatchEnvelope> + Sized + 'static + Dispatcher,
    FB: Fn(KPromise<()>) -> B + 'static,
    FC: Fn(KPromise<()>) -> C + 'static, 
[src]

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.

pub fn logger(&mut self, logger: KompactLogger) -> &mut Self[src]

Set the logger implementation to use

pub fn load_config_file<P>(&mut self, path: P) -> &mut Self where
    P: Into<PathBuf>, 
[src]

Load a HOCON config from a file at path

This method can be called multiple times, and the resulting configurations will be merged. See HoconLoader for more information.

The loaded config can be accessed via [system.config()](KompactSystem::config or from within a component via [self.ctx().config()](ComponentContext::config.

pub fn load_config_str<S>(&mut self, config: S) -> &mut Self where
    S: Into<String>, 
[src]

Load a HOCON config from a string

This method can be called multiple times, and the resulting configurations will be merged. See HoconLoader for more information.

The loaded config can be accessed via [system.config()](KompactSystem::config or from within a component via [self.ctx().config()](ComponentContext::config.

pub fn build(self) -> Result<KompactSystem, KompactError>[src]

Finalise the config and use it create a KompactSystem

This function can fail, if the configuration sets up invalid schedulers or dispatchers, for example.

Example

Build a system with default settings with:

use kompact::prelude::*;

let system = KompactConfig::default().build().expect("system");

Trait Implementations

impl Clone for KompactConfig[src]

impl Debug for KompactConfig[src]

impl Default for KompactConfig[src]

fn default() -> Self[src]

Create a default Kompact config

The default config uses the default label, i.e. "kompact-runtime-{}" for some sequence number. It sets the event/message throughput to 50, split evenly between events and messages. It runs with one thread per cpu on an appropriately sized crossbeam_workstealing_pool implementation. It uses all default components, without networking, with the default timer and default logger.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erased for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,