Class SharedJvmMetricsCollector
- All Implemented Interfaces:
MetricsCollector
JvmMetricsCollector that ensures only one collector instance
exists per JVM process, even when multiple TelemetryReporter
instances are running.
Each TelemetryReporter creates a SharedJvmMetricsCollector via its Provider, but only the
"active" instance actually delegates collect(Emitter) to the underlying shared collector.
When the active instance is stopped (because its reporter is closing), ownership automatically
transfers to another registered instance so that JVM metrics collection continues uninterrupted.
-
Field Summary
Fields inherited from interface io.confluent.telemetry.collector.MetricsCollector
LABEL_LIBRARY, LABEL_ORIGINAL, LIBRARY_NONE -
Constructor Summary
Constructors -
Method Summary
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface io.confluent.telemetry.collector.MetricsCollector
start
-
Constructor Details
-
SharedJvmMetricsCollector
-
-
Method Details
-
collect
Collect JVM metrics if this is the active instance.Uses a local-copy idiom instead of synchronizing: we snapshot
sharedCollectorinto a local variable before checkingactiveInstance. This avoids taking a lock on every collection cycle (called every 60s per reporter), while a lock instop()is only taken during reporter shutdown—an infrequent event.Without the local copy, a concurrent
stop()could null outsharedCollectorbetween theactiveInstancecheck and thecollect()call, causing a NPE. The worst case with the local copy is one extra collection on a collector whose ownership was just released—harmless since it only reads JMX MXBeans and emits metrics.- Specified by:
collectin interfaceMetricsCollector
-
stop
public void stop()- Specified by:
stopin interfaceMetricsCollector
-
toString
-