diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 3fa2759e67a7..288536f297df 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -131,7 +131,6 @@ Other API Changes --------------------- -(No changes) New Features --------------------- @@ -139,7 +138,8 @@ New Features Improvements --------------------- -(No changes) +* GITHUB#12574: Make TaskExecutor public so that it can be retrieved from the searcher and used + outside of the o.a.l.search package (Luca Cavanna) Optimizations --------------------- diff --git a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java index 9aa865f351a8..6e66d5c2af19 100644 --- a/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java +++ b/lucene/core/src/java/org/apache/lucene/search/IndexSearcher.java @@ -951,7 +951,12 @@ public Executor getExecutor() { return executor; } - TaskExecutor getTaskExecutor() { + /** + * Returns the {@link TaskExecutor} that this searcher relies on to execute concurrent operations + * + * @return the task executor + */ + public TaskExecutor getTaskExecutor() { return taskExecutor; } diff --git a/lucene/core/src/java/org/apache/lucene/search/TaskExecutor.java b/lucene/core/src/java/org/apache/lucene/search/TaskExecutor.java index d416d70c2f54..6e64df31400f 100644 --- a/lucene/core/src/java/org/apache/lucene/search/TaskExecutor.java +++ b/lucene/core/src/java/org/apache/lucene/search/TaskExecutor.java @@ -40,8 +40,10 @@ * calls, and not for potential {@link #invokeAll(Collection)} calls made from one of the tasks. * This is to prevent deadlock with certain types of pool based executors (e.g. {@link * java.util.concurrent.ThreadPoolExecutor}). + * + * @lucene.experimental */ -class TaskExecutor { +public final class TaskExecutor { // a static thread local is ok as long as we use a counter, which accounts for multiple // searchers holding a different TaskExecutor all backed by the same executor private static final ThreadLocal numberOfRunningTasksInCurrentThread = @@ -61,7 +63,7 @@ class TaskExecutor { * @return a list containing the results from the tasks execution * @param the return type of the task execution */ - final List invokeAll(Collection> tasks) throws IOException { + public List invokeAll(Collection> tasks) throws IOException { if (numberOfRunningTasksInCurrentThread.get() > 0) { for (Task task : tasks) { task.run(); @@ -85,11 +87,24 @@ final List invokeAll(Collection> tasks) throws IOException { return results; } - final Task createTask(Callable callable) { + /** + * Creates a task given the provided {@link Callable} + * + * @param callable the callable to be executed as part of the task + * @return the created task + * @param the return type of the task + */ + public Task createTask(Callable callable) { return new Task<>(callable); } - static class Task extends FutureTask { + /** + * Extension of {@link FutureTask} that tracks the number of tasks that are running in each + * thread. + * + * @param the return type of the task + */ + public static final class Task extends FutureTask { private Task(Callable callable) { super(callable); }