From f2579440b975e2e12f5ca74ad2164e1f77c31a45 Mon Sep 17 00:00:00 2001 From: Murtuza Chhil Date: Fri, 22 Nov 2024 11:58:13 +0530 Subject: [PATCH 1/2] Add reset method --- jpos/src/main/java/org/jpos/util/Metrics.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/jpos/src/main/java/org/jpos/util/Metrics.java b/jpos/src/main/java/org/jpos/util/Metrics.java index e6fb389cc4..684c8f6a11 100644 --- a/jpos/src/main/java/org/jpos/util/Metrics.java +++ b/jpos/src/main/java/org/jpos/util/Metrics.java @@ -120,4 +120,13 @@ public void dumpHistograms (File dir, String prefix) { public void setConversion(double conversion) { this.conversion = conversion; } + + /** + * Reset any value counts accumulated thus far. + */ + public void reset() { + metrics.values() + .forEach(Histogram::reset); + } + } From e7b0c819cd97f87da58f3f022dc18973b21c61e4 Mon Sep 17 00:00:00 2001 From: Murtuza Chhil Date: Fri, 22 Nov 2024 12:11:18 +0530 Subject: [PATCH 2/2] Update Metrics.java Added a reset for a prefix --- jpos/src/main/java/org/jpos/util/Metrics.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/jpos/src/main/java/org/jpos/util/Metrics.java b/jpos/src/main/java/org/jpos/util/Metrics.java index 684c8f6a11..50c6e245b9 100644 --- a/jpos/src/main/java/org/jpos/util/Metrics.java +++ b/jpos/src/main/java/org/jpos/util/Metrics.java @@ -128,5 +128,17 @@ public void reset() { metrics.values() .forEach(Histogram::reset); } + + /** + * Resets histograms whose keys start with the given prefix using the Histogram.reset() method. + * + * @param prefix the prefix used to filter histograms to reset + */ + public void reset(String prefix) { + metrics.entrySet() + .stream() + .filter(e -> e.getKey().startsWith(prefix)) + .forEach(e -> e.getValue().reset()); + } }