This is an automated email from the ASF dual-hosted git repository.
reschke pushed a commit to branch OAK-11618
in repository https://gitbox.apache.org/repos/asf/jackrabbit-oak.git
The following commit(s) were added to refs/heads/OAK-11618 by this push:
new 94afd146b2 OAK-11618: Remove usage of Guava Stopwatch - work in
progress
94afd146b2 is described below
commit 94afd146b2f7f212b2e205bda6192250445f087a
Author: Julian Reschke <[email protected]>
AuthorDate: Mon Apr 7 14:36:42 2025 +0100
OAK-11618: Remove usage of Guava Stopwatch - work in progress
---
.../org/apache/jackrabbit/oak/stats/Stopwatch.java | 18 +++++++++++++++++-
.../oak/plugins/index/TrackingCorruptIndexHandler.java | 2 +-
.../oak/plugins/index/search/BadIndexTracker.java | 4 ++--
3 files changed, 20 insertions(+), 4 deletions(-)
diff --git
a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/stats/Stopwatch.java
b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/stats/Stopwatch.java
index b8a5cfaa4f..c39b6ade33 100644
--- a/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/stats/Stopwatch.java
+++ b/oak-core-spi/src/main/java/org/apache/jackrabbit/oak/stats/Stopwatch.java
@@ -25,7 +25,10 @@ import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;
/**
- * A stop watch based on a {@link Supplier} of nanoseconds.
+ * A stop watch based either on a {@link Supplier} of nanoseconds, or a {@link
java.time.Clock}.
+ * <p>
+ * The accuracy of measurements depends on the precision of the time source,
which likely depends on platform and
+ * configuration.
* <p>
* Inspired by Guava's.
*/
@@ -57,6 +60,15 @@ public class Stopwatch {
return new Stopwatch(ticker).start();
}
+ /**
+ * @return a running stop watch, using the supplied clock.
+ * <p>
+ * Note that only {@link Clock#millis()} will be used, thus the watch will
have ms precision at most.
+ */
+ public static Stopwatch createStarted(java.time.Clock clock) {
+ return new Stopwatch(clockAsLongSupplier(clock)).start();
+ }
+
/**
* @return a non-running stop watch, using {@link System#nanoTime()}.
*/
@@ -137,4 +149,8 @@ public class Stopwatch {
private static long tick() {
return System.nanoTime();
}
+
+ private static Supplier<Long> clockAsLongSupplier(java.time.Clock clock) {
+ return () -> TimeUnit.MILLISECONDS.toNanos(clock.millis());
+ }
}
diff --git
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
index 777b0e61c2..fb5f5e1a83 100644
---
a/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
+++
b/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/TrackingCorruptIndexHandler.java
@@ -167,7 +167,7 @@ public class TrackingCorruptIndexHandler implements
CorruptIndexHandler {
private final String asyncName;
private final String path;
private final long lastIndexerCycleCount = indexerCycleCount;
- private final Stopwatch watch = Stopwatch.createStarted(() ->
TimeUnit.MILLISECONDS.toNanos(clock.millis()));
+ private final Stopwatch watch = Stopwatch.createStarted(clock);
private String exception = "";
private int failureCount;
diff --git
a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/BadIndexTracker.java
b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/BadIndexTracker.java
index 4004f09d88..66f7d52dcd 100644
---
a/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/BadIndexTracker.java
+++
b/oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/BadIndexTracker.java
@@ -156,8 +156,8 @@ public class BadIndexTracker {
final int lastIndexerCycleCount = indexerCycleCount;
private final long createdTime = clock.millis();
private final boolean persistedIndex;
- private final Stopwatch created = Stopwatch.createStarted(() ->
TimeUnit.MILLISECONDS.toNanos(clock.millis()));
- private final Stopwatch watch = Stopwatch.createStarted(() ->
TimeUnit.MILLISECONDS.toNanos(clock.millis()));
+ private final Stopwatch created = Stopwatch.createStarted(clock);
+ private final Stopwatch watch = Stopwatch.createStarted(clock);
private String exception;
private int accessCount;
private int failedAccessCount;