use std::collections::HashMap;
use std::fmt::Display;
use std::fmt::Formatter;
use std::sync::mpsc;
use std::sync::mpsc::Receiver;
use std::sync::mpsc::Sender;
use std::sync::Arc;
use parking_lot::Mutex;
use tracing::error;
use crate::log_file::mapped_file::default_mapped_file_impl::DefaultMappedFile;
pub struct AllocateMappedFileService {
tx: Sender<AllocateRequest>,
rx: Arc<Mutex<Receiver<AllocateRequest>>>,
request_table: Arc<parking_lot::Mutex<HashMap<String, AllocateRequest>>>,
}
impl AllocateMappedFileService {
pub fn new() -> Self {
let (tx, rx) = mpsc::channel();
Self {
tx,
rx: Arc::new(parking_lot::Mutex::new(rx)),
request_table: Arc::new(Default::default()),
}
}
}
impl Default for AllocateMappedFileService {
fn default() -> Self {
Self::new()
}
}
impl AllocateMappedFileService {
pub fn put_request_and_return_mapped_file(
&self,
next_file_path: String,
next_next_file_path: String,
file_size: i32,
) -> DefaultMappedFile {
unimplemented!()
}
pub fn start(&self) {
error!("AllocateMappedFileService start failed, not implement yet");
}
pub fn shutdown(&self) {
error!("AllocateMappedFileService shutdown failed, not implement yet");
}
}
struct AllocateRequest {
file_path: String,
file_size: i32,
mapped_file: Option<DefaultMappedFile>,
}
impl Display for AllocateRequest {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
write!(
f,
"AllocateRequest[file_path={},file_size={}]",
self.file_path, self.file_size
)
}
}
impl PartialEq<Self> for AllocateRequest {
fn eq(&self, other: &Self) -> bool {
self.file_path == other.file_path && self.file_size == other.file_size
}
}
impl Eq for AllocateRequest {}