-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
thunderpay-lib: metric-api[impl(NoOpTimer)]
- Loading branch information
1 parent
24c27b5
commit 99bb9b8
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
66 changes: 66 additions & 0 deletions
66
thunderpay-lib/metric-api/src/main/java/org/thunderpay/metric/impl/NoOpTimer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |