mikemccand commented on code in PR #11780: URL: https://github.com/apache/lucene/pull/11780#discussion_r982553986
########## 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: Hmm why is it necessary to compute this state under lock? Can't the caller just compute the state themselves when they get the refreshed reader? -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org