Class BufferedStreamAdapter<F,V>
java.lang.Object
com.github.mizool.core.concurrent.BufferedStreamAdapter<F,V>
Buffers a stream of futures and provides the results as a new stream.
Futures are collected as fast as possible without the sum of concurrently running futures and available results exceeding
The new stream contains the results in the completion order of the futures. It blocks while no results are available and there are still futures to wait for.
Futures are collected as fast as possible without the sum of concurrently running futures and available results exceeding
bufferSize
.The new stream contains the results in the completion order of the futures. It blocks while no results are available and there are still futures to wait for.
Exceptional completion of futures
When one or more of the futures inside the stream complete exceptionally, the new stream will throw that exception when an attempt is made to consume the next result. The exception is thrown as is (i.e. not wrapped inExecutionException
as with Future.get()
). Basically, the new stream behaves as
if all computations were performed in a synchronous manner.Exceptions thrown by the original stream
If the original stream throws an exception instead of producing a future, the new stream will behave the same way as with exceptional completion of futures: the exception will be thrown when an attempt is made to consume the next result.Usage examples
Stream<Completable<V>> completables;
Stream<V> values = BufferedStreamAdapter.completable().adapt(completables, bufferSize, executorService);
Stream<ListenableFuture<V>> listenables;
Stream<V> values = BufferedStreamAdapter.listenable().adapt(listenables, bufferSize, executorService);
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
static final class
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E> Stream<E>
adapt
(Stream<com.google.common.util.concurrent.ListenableFuture<E>> futures, int bufferSize, ExecutorService executorService) Deprecated, for removal: This API element is subject to removal in a future version.
-
Method Details
-
listenable
-
completable
-
adapt
@Deprecated(forRemoval=true) public static <E> Stream<E> adapt(Stream<com.google.common.util.concurrent.ListenableFuture<E>> futures, int bufferSize, ExecutorService executorService) Deprecated, for removal: This API element is subject to removal in a future version.
-
listenable()
andBufferedStreamAdapter.Listenable.adapt(Stream, int, ExecutorService)
instead.