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
63
64
65
66
67
68
69
use std::sync::Arc;
use anyhow::Result;
use dashmap::DashMap;
use hash_map_id::HashMapId;
use tokio::sync::{
mpsc::{UnboundedReceiver, UnboundedSender},
Mutex,
};
use wasmtime::Linker;
use crate::{
config::ProcessConfig,
mailbox::MessageMailbox,
runtimes::wasmtime::{WasmtimeCompiledModule, WasmtimeRuntime},
Signal,
};
pub type ConfigResources<T> = HashMapId<T>;
pub type SignalSender = UnboundedSender<Signal>;
pub type SignalReceiver = Arc<Mutex<UnboundedReceiver<Signal>>>;
pub trait ProcessState: Sized {
type Config: ProcessConfig + Default + Send + Sync;
fn new_state(
&self,
module: Arc<WasmtimeCompiledModule<Self>>,
config: Arc<Self::Config>,
) -> Result<Self>;
fn state_for_instantiation() -> Self;
fn register(linker: &mut Linker<Self>) -> Result<()>;
fn initialize(&mut self);
fn is_initialized(&self) -> bool;
fn runtime(&self) -> &WasmtimeRuntime;
fn module(&self) -> &Arc<WasmtimeCompiledModule<Self>>;
fn config(&self) -> &Arc<Self::Config>;
fn id(&self) -> u64;
fn signal_mailbox(&self) -> &(SignalSender, SignalReceiver);
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, (u64, u64)>>;
}