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>
AnIterable
which supports generation ofBlockingIterator
s.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 interface
BlockingIterable.Processor<T>
ABlockingIterable
that 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 void
forEach(java.util.function.Consumer<? super T> action, long timeout, java.util.concurrent.TimeUnit unit)
Mimics the behavior ofIterable.forEach(Consumer)
but applies atimeout
duration for the overall completion of this method.default void
forEach(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 thetimeoutSupplier
to determine the timeout value for interactions with theBlockingIterator
.BlockingIterator<T>
iterator()
default BlockingSpliterator<T>
spliterator()
The same behavior asIterable.spliterator()
, but returns aBlockingSpliterator
view.
-
-
-
Method Detail
-
iterator
BlockingIterator<T> iterator()
- Specified by:
iterator
in interfaceCloseableIterable<T>
- Specified by:
iterator
in 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 thetimeoutSupplier
to determine the timeout value for interactions with theBlockingIterator
.By default the
timeoutSupplier
will be used for each interaction withBlockingIterator.hasNext(long, TimeUnit)
andBlockingIterator.next(long, TimeUnit)
. However implementations ofBlockingIterable
may decide to only apply the timeout when they are not be sure if an interaction with theBlockingIterator
will block or not.- Parameters:
action
- The action to be performed for each element.timeoutSupplier
- ALongSupplier
that 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 thetimeout
duration.
-
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 atimeout
duration for the overall completion of this method. Thetimeout
is adjusted for each interaction with theBlockingIterator
which may block.Note that the
timeout
duration is an approximation and this duration maybe exceeded if data is available without blocking.By default the
timeout
will be used for each interaction withBlockingIterator.hasNext(long, TimeUnit)
andBlockingIterator.next(long, TimeUnit)
. However implementations ofBlockingIterable
may decide to only apply the timeout when they are not be sure if an interaction with theBlockingIterator
will 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 thetimeout
duration.
-
spliterator
default BlockingSpliterator<T> spliterator()
The same behavior asIterable.spliterator()
, but returns aBlockingSpliterator
view.Calling
BlockingSpliterator.close()
may result in closing of the underlyingBlockingIterator
.- Specified by:
spliterator
in interfacejava.lang.Iterable<T>
- Returns:
- a
BlockingSpliterator
over the elements described by thisBlockingIterable
.
-
-