stefanvodita commented on code in PR #11780:
URL: https://github.com/apache/lucene/pull/11780#discussion_r982630324
##########
lucene/core/src/java/org/apache/lucene/search/ReferenceManager.java:
##########
@@ -219,6 +219,36 @@ public final boolean maybeRefresh() throws IOException {
return doTryRefresh;
}
+ /** Compute some state of the reference using a parameter. */
+ @FunctionalInterface
+ public interface StateCalculator<R, G, P> {
+ R calculate(G current, P param);
+ }
+
+ /**
+ * If you need to compute something after the refresh, you can use this
method instead of {@link
+ * #maybeRefresh()}.
+ *
+ * @throws IOException if refreshing the resource causes an {@link
IOException}
+ */
+ public final <R, P> R maybeRefreshAndReturnState(
+ StateCalculator<R, G, P> refreshedStateCalculator, P param) throws
IOException {
+ ensureOpen();
+
+ // Ensure only 1 thread does refresh at once; other threads just return
immediately:
+ final boolean doTryRefresh = refreshLock.tryLock();
+ if (doTryRefresh) {
+ try {
+ doMaybeRefresh();
+ return refreshedStateCalculator.calculate(current, param);
Review Comment:
We’re guaranteeing that no other refresh happens before computing the reader
states. Maybe that’s not important to do? If so, then the user can always
refresh and then compute their own reader states.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]