ih_muse::prelude

Struct Muse

Source
pub struct Muse {
    pub recorder: Option<Arc<Mutex<dyn Recorder + Send + Sync>>>,
    pub is_initialized: Arc<AtomicBool>,
    /* private fields */
}
Expand description

The main client for interacting with the Muse system.

The Muse struct provides methods to initialize the client, register elements, send metrics, and replay recorded events.

Fields§

§recorder: Option<Arc<Mutex<dyn Recorder + Send + Sync>>>§is_initialized: Arc<AtomicBool>

Indicates whether the Muse client has been initialized.

Implementations§

Source§

impl Muse

Source

pub fn new(config: &Config) -> MuseResult<Self>

Creates a new Muse client instance.

§Arguments
  • config: A reference to the Config object.
§Errors

Returns a MuseError::Configuration if the client cannot be created with the provided configuration.

Source

pub async fn initialize(&mut self, timeout: Option<Duration>) -> MuseResult<()>

Initializes the Muse client and starts background tasks.

Must be called before using other methods that interact with the Muse system.

§Arguments
  • timeout: Optional timeout duration for the initialization process.
§Errors

Returns a MuseError::MuseInitializationTimeout if initialization times out.

Source

pub fn get_state(&self) -> Arc<State>

Retrieves a reference to the internal State object.

§Returns

An Arc pointing to the internal State.

Source

pub fn get_finest_resolution(&self) -> TimestampResolution

Retrieves the finest resolution of timestamps from the state.

§Returns

The current TimestampResolution as set in the state.

Source

pub fn get_client(&self) -> Arc<dyn Transport + Send + Sync>

Retrieves a reference to the internal transport client.

§Returns

An Arc pointing to the transport client implementing Transport.

Source

pub fn is_initialized(&self) -> bool

Checks if the Muse client has been initialized.

§Returns

true if initialized, false otherwise.

Source

pub async fn register_element( &self, kind_code: &str, name: String, metadata: HashMap<String, String>, parent_id: Option<ElementId>, ) -> MuseResult<LocalElementId>

Registers a new element with the Muse system.

§Arguments
  • kind_code: The kind code of the element.
  • name: The name of the element.
  • metadata: A map of metadata key-value pairs.
  • parent_id: Optional parent element ID.
§Returns

A LocalElementId representing the registered element.

§Errors

Returns a MuseError if registration fails.

Source

pub fn get_remote_element_id( &self, local_elem_id: &LocalElementId, ) -> Option<ElementId>

Retrieves the remote ElementId associated with a given LocalElementId.

§Arguments
  • local_elem_id: The LocalElementId for which to retrieve the ElementId.
§Returns

An Option<ElementId> containing the associated ElementId if it exists.

Source

pub async fn send_metric( &self, local_elem_id: LocalElementId, metric_code: &str, value: MetricValue, ) -> MuseResult<()>

Sends a metric value associated with an element.

§Arguments
  • local_elem_id: The local ID of the element.
  • metric_code: The code identifying the metric.
  • value: The metric value to send.
§Errors

Returns a MuseError if the metric cannot be sent.

Source

pub async fn get_metrics( &self, query: &MetricQuery, ) -> MuseResult<Vec<MetricPayload>>

Retrieves metrics from the Muse system based on a query.

Note: The Muse client is primarily intended for sending metrics to the Muse system. This method is provided mainly for testing purposes and is not recommended for use in production code.

§Arguments
  • query: The MetricQuery specifying the criteria for retrieving metrics.
§Returns

A vector of MetricPayloads matching the query.

§Errors

Returns a MuseError if the metrics cannot be retrieved.

Source

pub async fn replay(&self, replay_path: &Path) -> MuseResult<()>

Replays events from a recording file.

Useful for testing or replaying historical data.

§Arguments
  • replay_path: The file path to the recording.
§Errors

Returns a MuseError if replaying fails.

Source

pub async fn from_replay(replay_path: &Path) -> MuseResult<Self>

Initializes a Muse instance using the Config recorded in a replay file. Sets recording_enabled in the Config to false to prevent re-recording during replay.

§Arguments
  • replay_path: The path to the replay file containing the Config.
§Returns

A new Muse instance initialized with the Config extracted from the replay file.

Source

pub async fn check_and_replay(replay_path: &Path) -> MuseResult<Self>

Checks if a replay should start based on the presence of a replay file. If the replay file exists and contains valid events, it will start the replay process.

§Arguments
  • replay_path: The path to the replay file.
§Returns

A Result indicating success or failure of the replay process.

Trait Implementations§

Source§

impl Drop for Muse

Source§

fn drop(&mut self)

Cleans up resources when the Muse instance is dropped.

Cancels any running tasks and releases resources. Flushes and Closes any running event recording.

Auto Trait Implementations§

§

impl Freeze for Muse

§

impl !RefUnwindSafe for Muse

§

impl Send for Muse

§

impl Sync for Muse

§

impl Unpin for Muse

§

impl !UnwindSafe for Muse

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T