Class ThrottledIterator<T>

java.lang.Object
org.elasticsearch.common.util.concurrent.ThrottledIterator<T>
All Implemented Interfaces:
Closeable, AutoCloseable, Releasable

public class ThrottledIterator<T> extends Object implements Releasable
  • Method Summary

    Modifier and Type
    Method
    Description
    void
     
    static <T> void
    run(Iterator<T> iterator, BiConsumer<Releasable,T> itemConsumer, int maxConcurrency, Runnable onItemCompletion, Runnable onCompletion)
    Iterate through the given collection, performing an operation on each item which may fork background tasks, but with a limit on the number of such background tasks running concurrently to avoid overwhelming the rest of the system (e.g.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • run

      public static <T> void run(Iterator<T> iterator, BiConsumer<Releasable,T> itemConsumer, int maxConcurrency, Runnable onItemCompletion, Runnable onCompletion)
      Iterate through the given collection, performing an operation on each item which may fork background tasks, but with a limit on the number of such background tasks running concurrently to avoid overwhelming the rest of the system (e.g. starving other work of access to an executor).
      Parameters:
      iterator - The items to iterate. May be accessed by multiple threads, but accesses are all protected by synchronizing on itself.
      itemConsumer - The operation to perform on each item. Each operation receives a RefCounted which can be used to track the execution of any background tasks spawned for this item. This operation may run on the thread which originally called run(java.util.Iterator<T>, java.util.function.BiConsumer<org.elasticsearch.core.Releasable, T>, int, java.lang.Runnable, java.lang.Runnable), if this method has not yet returned. Otherwise it will run on a thread on which a background task previously called RefCounted.decRef() on its ref count. This operation should not throw any exceptions.
      maxConcurrency - The maximum number of ongoing operations at any time.
      onItemCompletion - Executed when each item is completed, which can be used for instance to report on progress. Must not throw exceptions.
      onCompletion - Executed when all items are completed.
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface Releasable