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

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

The newest version!
package com.github.marschall.micrometer.jfr;

import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.util.MeterEquivalence;
import jdk.jfr.EventFactory;

abstract class AbstractJfrMeter, E extends AbstractJfrMeterEvent> implements Meter {

  private final Id id;
  protected final F meterEventFactory;
  protected final EventFactory jfrEventFactory;
  
  AbstractJfrMeter(Id id, F meterEventFactory) {
    this.id = id;
    this.meterEventFactory = meterEventFactory;
    this.jfrEventFactory = this.meterEventFactory.newEventFactory();
  }

  E newEmptyEvent() {
    return this.meterEventFactory.newEmptyEvent(this.jfrEventFactory);
  }

  @Override
  public Id getId() {
    return this.id;
  }

  @Override
  public void close() {
    this.meterEventFactory.closeEventFactory(this.jfrEventFactory);
  }

  @Override
  public String toString() {
    return this.getClass().getSimpleName() + '(' + this.getId() + ')';
  }

  @Override
  public boolean equals(Object o) {
    if (o == this) {
      return true;
    }
    if (!(o instanceof Meter)) {
      return false;
    }
    return MeterEquivalence.equals(this, o);
  }

  @Override
  public int hashCode() {
    return MeterEquivalence.hashCode(this);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy