1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use std::sync::Arc;
use anyhow::Result;
use async_std::channel::{Receiver, Sender};
use dashmap::DashMap;
use hash_map_id::HashMapId;
use uuid::Uuid;
use wasmtime::Linker;
use crate::{
config::ProcessConfig,
mailbox::MessageMailbox,
runtimes::wasmtime::{WasmtimeCompiledModule, WasmtimeRuntime},
Process, Signal,
};
pub type ConfigResources<T> = HashMapId<T>;
pub trait ProcessState: Sized + Default {
type Config: ProcessConfig + Default + Send + Sync;
fn new(
runtime: WasmtimeRuntime,
module: WasmtimeCompiledModule<Self>,
config: Arc<Self::Config>,
registry: Arc<DashMap<String, Arc<dyn Process>>>,
) -> Result<Self>;
fn register(linker: &mut Linker<Self>) -> Result<()>;
fn initialize(&mut self);
fn is_initialized(&self) -> bool;
fn runtime(&self) -> &WasmtimeRuntime;
fn module(&self) -> &WasmtimeCompiledModule<Self>;
fn config(&self) -> &Arc<Self::Config>;
fn id(&self) -> Uuid;
fn signal_mailbox(&self) -> &(Sender<Signal>, Receiver<Signal>);
fn message_mailbox(&self) -> &MessageMailbox;
fn config_resources(&self) -> &ConfigResources<Self::Config>;
fn config_resources_mut(&mut self) -> &mut ConfigResources<Self::Config>;
fn registry(&self) -> &Arc<DashMap<String, Arc<dyn Process>>>;
}