com.github.marschall.micrometer.jfr.FieldUpdaterLongStatistics Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micrometer-jfr Show documentation
Show all versions of micrometer-jfr Show documentation
A Micrometer meter registry that generates JFR events
The newest version!
package com.github.marschall.micrometer.jfr;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
/**
* A minimal statistics implementation for {@code long} values using
* {@code AtomicLongFieldUpdater} types consuming less memory
* but offering worse concurrency.
*/
final class FieldUpdaterLongStatistics implements LongStatistics {
static final AtomicLongFieldUpdater COUNT_UPDATER =
AtomicLongFieldUpdater.newUpdater(FieldUpdaterLongStatistics.class, "count");
static final AtomicLongFieldUpdater MAX_UPDATER =
AtomicLongFieldUpdater.newUpdater(FieldUpdaterLongStatistics.class, "max");
static final AtomicLongFieldUpdater TOTALAMOUNT_UPDATER =
AtomicLongFieldUpdater.newUpdater(FieldUpdaterLongStatistics.class, "totalAmount");
private volatile long count;
private volatile long max;
private volatile long totalAmount;
FieldUpdaterLongStatistics() {
this.count = 0L;
this.max = Long.MIN_VALUE;
this.totalAmount = 0L;
}
@Override
public long count() {
return this.count;
}
@Override
public long totalAmount() {
return this.totalAmount;
}
@Override
public long max() {
return this.max;
}
@Override
public void record(long value) {
COUNT_UPDATER.incrementAndGet(this);
MAX_UPDATER.getAndAccumulate(this, value, Long::max);
TOTALAMOUNT_UPDATER.addAndGet(this, value);
}
}