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
impl Muse
Sourcepub fn new(config: &Config) -> MuseResult<Self>
pub fn new(config: &Config) -> MuseResult<Self>
Creates a new Muse
client instance.
§Arguments
config
: A reference to theConfig
object.
§Errors
Returns a MuseError::Configuration
if the client cannot be created with the provided configuration.
Sourcepub async fn initialize(&mut self, timeout: Option<Duration>) -> MuseResult<()>
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.
Sourcepub fn get_finest_resolution(&self) -> TimestampResolution
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.
Sourcepub fn get_client(&self) -> Arc<dyn Transport + Send + Sync>
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
.
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Sourcepub async fn register_element(
&self,
kind_code: &str,
name: String,
metadata: HashMap<String, String>,
parent_id: Option<ElementId>,
) -> MuseResult<LocalElementId>
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.
Sourcepub fn get_remote_element_id(
&self,
local_elem_id: &LocalElementId,
) -> Option<ElementId>
pub fn get_remote_element_id( &self, local_elem_id: &LocalElementId, ) -> Option<ElementId>
Sourcepub async fn send_metric(
&self,
local_elem_id: LocalElementId,
metric_code: &str,
value: MetricValue,
) -> MuseResult<()>
pub async fn send_metric( &self, local_elem_id: LocalElementId, metric_code: &str, value: MetricValue, ) -> MuseResult<()>
Sourcepub async fn get_metrics(
&self,
query: &MetricQuery,
) -> MuseResult<Vec<MetricPayload>>
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
: TheMetricQuery
specifying the criteria for retrieving metrics.
§Returns
A vector of MetricPayload
s matching the query.
§Errors
Returns a MuseError
if the metrics cannot be retrieved.
Sourcepub async fn replay(&self, replay_path: &Path) -> MuseResult<()>
pub async fn replay(&self, replay_path: &Path) -> MuseResult<()>
Sourcepub async fn from_replay(replay_path: &Path) -> MuseResult<Self>
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.