relay_server/services/buffer/stack_provider/
memory.rsuse crate::services::buffer::common::ProjectKeyPair;
use crate::services::buffer::envelope_stack::memory::MemoryEnvelopeStack;
use crate::services::buffer::stack_provider::{
InitializationState, StackCreationType, StackProvider,
};
use crate::utils::MemoryChecker;
use crate::EnvelopeStack;
#[derive(Debug)]
pub struct MemoryStackProvider {
memory_checker: MemoryChecker,
}
impl MemoryStackProvider {
pub fn new(memory_checker: MemoryChecker) -> Self {
Self { memory_checker }
}
}
impl StackProvider for MemoryStackProvider {
type Stack = MemoryEnvelopeStack;
async fn initialize(&self) -> InitializationState {
InitializationState::empty()
}
fn create_stack(&self, _: StackCreationType, _: ProjectKeyPair) -> Self::Stack {
MemoryEnvelopeStack::new()
}
fn has_store_capacity(&self) -> bool {
self.memory_checker.check_memory().has_capacity()
}
async fn store_total_count(&self) -> u64 {
0
}
fn stack_type<'a>(&self) -> &'a str {
"memory"
}
async fn flush(&mut self, envelope_stacks: impl IntoIterator<Item = Self::Stack>) {
for envelope_stack in envelope_stacks {
envelope_stack.flush().await;
}
}
}