pub struct MessageBasedFileSystem { /* private fields */ }Expand description
This is the primary struct for running a message based file system. Upon construction, this struct will create a set of workers, each listening for new read requests.
When a worker receives a read request, it will first check to see if there are any existing pages for the file. If no pages exists, then a new entry is made. Otherwise, the head of the list will be returned.
Finally, this struct also contains a flag wich can be used to stop all workers. Usually this is done when the program must terminate.
Implementations§
Source§impl MessageBasedFileSystem
impl MessageBasedFileSystem
Sourcepub fn new(max_pages: usize, page_size: usize, max_messages: usize) -> Self
pub fn new(max_pages: usize, page_size: usize, max_messages: usize) -> Self
Instantiates a new MessageBasedFileSystem.
§Parameters:
max_pages- The maximum number of pages each file reference may hold.page_size: The size of each page.max_messages: The maximum capacity of the request queue. Additional requests will be blocked until there is space in the queue.
Sourcepub fn open(&self, path: String) -> FileHandle
pub fn open(&self, path: String) -> FileHandle
Returns a new file handle.
§Parameters
path: The path to the file.
§Returns
FileHandle- A new file handle object.
§Examples
let file_reader = Arc::new(Mutex::new(MessageBasedFileSystem::new()));
/* Spawn thread to run mbfs */
let file = file_reader.lock().unwrap().open("/test/file.txt".to_owned());Sourcepub fn get_run_signal(&self) -> Arc<AtomicBool>
pub fn get_run_signal(&self) -> Arc<AtomicBool>
Sourcepub fn run(&self) -> Result<(), RecvError>
pub fn run(&self) -> Result<(), RecvError>
Runs the message based file system.
§Examples
let file_reader = Arc::new(Mutex::new(MessageBasedFileSystem::new()));
let fr2 = file_reader.clone();
let read_thr = thread::spawn(move || {
loop {
{
fr2.lock().unwrap().run().unwrap();
}
thread::sleep(Duration::from_millis(1));
}
});
// Do work with `file_reader`
read_thr.join()?;Auto Trait Implementations§
impl Freeze for MessageBasedFileSystem
impl !RefUnwindSafe for MessageBasedFileSystem
impl Send for MessageBasedFileSystem
impl Sync for MessageBasedFileSystem
impl Unpin for MessageBasedFileSystem
impl !UnwindSafe for MessageBasedFileSystem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more