Interface BlockingIterable<T>
-
- Type Parameters:
T- the type of elements returned by theBlockingIterator.
- All Superinterfaces:
CloseableIterable<T>,java.lang.Iterable<T>
- All Known Subinterfaces:
BlockingIterable.Processor<T>
- All Known Implementing Classes:
TestIterableToBlockingIterable
public interface BlockingIterable<T> extends CloseableIterable<T>
AnIterablewhich supports generation ofBlockingIterators.This interface is meant to be the synchronous API equivalent of
PublisherSource. Each call toiterator()is equivalent to callingPublisherSource.subscribe(Subscriber)and typically has the same characteristics in terms of being able to call the method multiple times and data availability in memory.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interfaceBlockingIterable.Processor<T>ABlockingIterablethat supports to dynamically emitting items usingBlockingIterable.Processor.next(Object).
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default voidforEach(java.util.function.Consumer<? super T> action, long timeout, java.util.concurrent.TimeUnit unit)Mimics the behavior ofIterable.forEach(Consumer)but applies atimeoutduration for the overall completion of this method.default voidforEach(java.util.function.Consumer<? super T> action, java.util.function.LongSupplier timeoutSupplier, java.util.concurrent.TimeUnit unit)Mimics the behavior ofIterable.forEach(Consumer)but uses thetimeoutSupplierto determine the timeout value for interactions with theBlockingIterator.BlockingIterator<T>iterator()default BlockingSpliterator<T>spliterator()The same behavior asIterable.spliterator(), but returns aBlockingSpliteratorview.
-
-
-
Method Detail
-
iterator
BlockingIterator<T> iterator()
- Specified by:
iteratorin interfaceCloseableIterable<T>- Specified by:
iteratorin interfacejava.lang.Iterable<T>
-
forEach
default void forEach(java.util.function.Consumer<? super T> action, java.util.function.LongSupplier timeoutSupplier, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException
Mimics the behavior ofIterable.forEach(Consumer)but uses thetimeoutSupplierto determine the timeout value for interactions with theBlockingIterator.By default the
timeoutSupplierwill be used for each interaction withBlockingIterator.hasNext(long, TimeUnit)andBlockingIterator.next(long, TimeUnit). However implementations ofBlockingIterablemay decide to only apply the timeout when they are not be sure if an interaction with theBlockingIteratorwill block or not.- Parameters:
action- The action to be performed for each element.timeoutSupplier- ALongSupplierthat provides the timeout duration for the next call toBlockingIterator.hasNext(long, TimeUnit)andBlockingIterator.next(long, TimeUnit). These methods should be consulted for the meaning of non-positive timeout durations.unit- The units for the duration of time.- Throws:
java.util.concurrent.TimeoutException- If an individual call toBlockingIterator.hasNext(long, TimeUnit)takes longer than thetimeoutduration.
-
forEach
default void forEach(java.util.function.Consumer<? super T> action, long timeout, java.util.concurrent.TimeUnit unit) throws java.util.concurrent.TimeoutException
Mimics the behavior ofIterable.forEach(Consumer)but applies atimeoutduration for the overall completion of this method. Thetimeoutis adjusted for each interaction with theBlockingIteratorwhich may block.Note that the
timeoutduration is an approximation and this duration maybe exceeded if data is available without blocking.By default the
timeoutwill be used for each interaction withBlockingIterator.hasNext(long, TimeUnit)andBlockingIterator.next(long, TimeUnit). However implementations ofBlockingIterablemay decide to only apply the timeout when they are not be sure if an interaction with theBlockingIteratorwill block or not.- Parameters:
action- The action to be performed for each element.timeout- An approximate total duration for the overall completion of this method. This value is used to approximate because the actual duration maybe longer if data is available without blocking.unit- The units for the duration of time.- Throws:
java.util.concurrent.TimeoutException- If the total iteration time as determined byBlockingIterator.hasNext(long, TimeUnit)takes longer than thetimeoutduration.
-
spliterator
default BlockingSpliterator<T> spliterator()
The same behavior asIterable.spliterator(), but returns aBlockingSpliteratorview.Calling
BlockingSpliterator.close()may result in closing of the underlyingBlockingIterator.- Specified by:
spliteratorin interfacejava.lang.Iterable<T>- Returns:
- a
BlockingSpliteratorover the elements described by thisBlockingIterable.
-
-