#[non_exhaustive]pub struct MetricsView { /* private fields */ }Expand description
A live, read-only view of the metrics of a client, indexed by metric name:
what Java’s clients return from metrics() as
Collections.unmodifiableMap(metrics.metrics()).
Every lookup reads the registry as it is at the time of the call, so a
metric registered after the view was returned is visible through it and a
removed one is not. Self::snapshot gives the whole map as it is now, to
iterate without blocking the registry, as Java’s weakly consistent iteration
does. A view stays valid after its client is closed.
A view can also stand alone, built from a map (From) or empty
(Default), for a test double or a user implementation of Producer or
Consumer.
A clone is a second view of the same map, as copying a Java reference is.
Java’s Map interface lets unmodifiableMap stand for a live map; Rust has
no read-only map trait in its standard library, and returning a HashMap
would copy the registry on every call.
Implementations§
Source§impl MetricsView
impl MetricsView
Sourcepub fn get(&self, name: &MetricName) -> Option<Arc<KafkaMetric>>
pub fn get(&self, name: &MetricName) -> Option<Arc<KafkaMetric>>
Returns the metric registered under name, if any, as the registry is
at the time of the call.
§Arguments
name- the name of the metric
Sourcepub fn contains_key(&self, name: &MetricName) -> bool
pub fn contains_key(&self, name: &MetricName) -> bool
Returns whether a metric is registered under name, as the registry is
at the time of the call.
§Arguments
name- the name of the metric
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns how many metrics the registry holds at the time of the call.
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns whether the registry holds no metric at the time of the call.
Sourcepub fn snapshot(&self) -> Arc<HashMap<MetricName, Arc<KafkaMetric>>>
pub fn snapshot(&self) -> Arc<HashMap<MetricName, Arc<KafkaMetric>>>
Returns the map as it is now, indexed by metric name.
The returned map never changes: a metric registered or removed later shows in the view, not in the snapshot. Taking it copies no entry and never blocks the registry; a later registration copies the map once while a snapshot of the old version is held.
Trait Implementations§
Source§impl Clone for MetricsView
impl Clone for MetricsView
Source§fn clone(&self) -> MetricsView
fn clone(&self) -> MetricsView
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MetricsView
impl Debug for MetricsView
Source§impl Default for MetricsView
impl Default for MetricsView
Source§fn default() -> MetricsView
fn default() -> MetricsView
Source§impl From<HashMap<MetricName, Arc<KafkaMetric>>> for MetricsView
impl From<HashMap<MetricName, Arc<KafkaMetric>>> for MetricsView
Source§fn from(metrics: HashMap<MetricName, Arc<KafkaMetric>>) -> Self
fn from(metrics: HashMap<MetricName, Arc<KafkaMetric>>) -> Self
A view of metrics, tied to no registry.
§Arguments
metrics- the metrics the view holds, indexed by metric name