All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.marschall.micrometer.jfr.JfrMeter Maven / Gradle / Ivy

There is a newer version: 1.13.0
Show newest version
package com.github.marschall.micrometer.jfr;

import java.util.concurrent.TimeUnit;

import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Meter;

final class JfrMeter extends AbstractJfrMeter implements Meter {

  private final Type type;
  private final Iterable measurements;
  private final Runnable hook;

  JfrMeter(Id id, Type type, Iterable measurements, TimeUnit baseTimeUnit) {
    super(id, new MeterEventFactory(id, baseTimeUnit, measurements));
    this.type = type;
    this.measurements = measurements;
    this.hook = () -> this.recordEvent();
    this.meterEventFactory.registerPeriodicEvent(this.jfrEventFactory, this.hook);
  }

  @Override
  public void close() {
    this.meterEventFactory.unregisterPeriodicEvent(this.hook);
    super.close();
  }

  private void recordEvent() {
    JfrMeterEvent event = this.newEmptyEvent();
    event.recordValues(this.type, this.measurements);
    event.commit();
  }

  @Override
  public Iterable measure() {
    return this.measurements;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy