Skip to content

Commit

Permalink
thunderpay-lib: metric-api[impl(NoOpTimer)]
Browse files Browse the repository at this point in the history
  • Loading branch information
krishpranav committed Dec 20, 2024
1 parent 24c27b5 commit 99bb9b8
Showing 1 changed file with 66 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/**
* @file NoOpTimer.java
* @author Krisna Pranav
* @brief Timer
* @version 1.0
* @date 2024-11-25
*
* @copyright Copyright (c) 2024 ThunderPayment Developers, Krisna Pranav
*
*/

package org.thunderpay.metric.impl;

import java.util.concurrent.TimeUnit;
import org.thunderpay.metric.api.Histogram;
import org.thunderpay.metric.api.Meter;
import org.thunderpay.metric.api.Snapshot;
import org.thunderpay.metric.api.Timer;

public class NoOpTimer implements Timer {
private final Meter meter;
private final Histogram histogram;

public NoOpTimer() {
this.meter = new NoOpMeter();
this.histogram = new NoOpHistogram();
}

@Override
public void update(final long duration, final TimeUnit unit) {
if (duration >= 0) {
histogram.update(unit.toNanos(duration));
meter.mark(1);
}
}

@Override
public long getCount() {
return histogram.getCount();
}

@Override
public double getFifteenMinuteRate() {
return meter.getFifteenMinuteRate();
}

@Override
public double getFiveMinuteRate() {
return meter.getFiveMinuteRate();
}

@Override
public double getMeanRate() {
return meter.getMeanRate();
}

@Override
public double getOneMinuteRate() {
return meter.getOneMinuteRate();
}

@Override
public Snapshot getSnapshot() {
return histogram.getSnapshot();
}
}

0 comments on commit 99bb9b8

Please sign in to comment.