MessageBasedFileSystem

Struct MessageBasedFileSystem 

Source
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

Source

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.
Source

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());
Source

pub fn get_run_signal(&self) -> Arc<AtomicBool>

Provides a signal to use to stop the system.

§Returns
  • Arc<AtomicBool> - Stop signal.
Source

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Erased for T