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 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 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 always strictly sequential: for any two method calls M1 and M2 on this iterator, either the return of M1 _happens-before_ the invocation of M2 or vice versa.
      itemConsumer - The operation to perform on each item. Each operation receives a Releasable resource which can be used to track the execution of any background tasks spawned for this item and which must be closed when all processing of the item has finished. If the iterator has not been fully consumed then closing an operation's resource triggers the start of an operation on the next 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), if this method has not yet returned. Otherwise, it will run on a thread on which a background task previously closed its tracking resource.

      This operation must not throw any exceptions.

      maxConcurrency - The maximum number of ongoing operations at any time.
      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