pub trait Model: Sized {
type Msg: Message;
type Dis: Dispatcher;
type Log: LoggerProps<Msg = Self::Msg>;
type Ded: DeadLetterProps<Msg = Self::Msg>;
type Tmr: TimerFactory<Msg = Self::Msg>;
type Evs: EventStore<Msg = Self::Msg>;
type Tcp: IoManagerProps<Msg = Self::Msg>;
type Udp: IoManagerProps<Msg = Self::Msg>;
}
Expand description
Riker’s system and module configuration.
Riker requires a Model
to set the message type used
throughout the system and specify modules that provide
core services.
A default model is provided by the riker-default
crate that
allows you to specify your message type (protocol).
If you prefer to use your own module for any of the core services
you can do so easily by creating your own model by implementing Model
.
Examples
Using the default model:
extern crate riker;
extern crate riker_default;
use riker::actors::*;
use riker_default::DefaultModel;
// Get a default model with String as the message type
let model: DefaultModel<String> = DefaultModel::new();
let sys = ActorSystem::new(&model).unwrap();
Implementing your own model:
ⓘ
extern crate riker;
extern crate riker_default;
use riker::actors::*;
use riker_default::*; // <-- we're going to use some default modules
struct MyModel;
impl Model for MyModel {
type Msg = String;
type Dis = ThreadPoolDispatcher;
type Ded = DeadLettersActor<Self::Msg>;
type Tmr = BasicTimer<Self::Msg>;
type Evs = Redis<Self::Msg>; // <-- we're using a module to provide Redis storage
type Tcp = TcpManager<Self::Msg>;
type Udp = TcpManager<Self::Msg>;
type Log = MyLogger<Self::Msg>; // <-- we're using our own Log module
}
let sys = ActorSystem::new(&MyModel).unwrap();
Required Associated Types§
sourcetype Dis: Dispatcher
type Dis: Dispatcher
Dispatcher executes actors and futures
sourcetype Log: LoggerProps<Msg = Self::Msg>
type Log: LoggerProps<Msg = Self::Msg>
Logger provides global logging, e.g. info!(“hello”);
sourcetype Ded: DeadLetterProps<Msg = Self::Msg>
type Ded: DeadLetterProps<Msg = Self::Msg>
Dead letters subscribes to the dead letters channel
sourcetype Tmr: TimerFactory<Msg = Self::Msg>
type Tmr: TimerFactory<Msg = Self::Msg>
Timer provides message scheduling, e.g. ctx.schedule_once
sourcetype Evs: EventStore<Msg = Self::Msg>
type Evs: EventStore<Msg = Self::Msg>
Event store provides the storage system for events/messages