public final class Accumulator<E,A>
extends java.lang.Object
map
, recover
and so on are
provided for the the eventually redeemed future value.
In order to be in line with the Java ecosystem, the future implementation that this uses for the materialised value
of the Sink is java.util.concurrent.CompletionStage, and running this accumulator will yield a CompletionStage. The
constructor allows an accumulator to be created from such a sink. Many methods in the Akka streams API however
materialise a scala.concurrent.Future, hence the fromSink
method is provided to create an accumulator
from a typical Akka streams Sink
.Constructor and Description |
---|
Accumulator(akka.stream.javadsl.Sink<E,java.util.concurrent.CompletionStage<A>> sink)
Create an accumulator for the given sink.
|
Modifier and Type | Method and Description |
---|---|
play.api.libs.streams.Accumulator<E,A> |
asScala()
Convert this accumulator to a Scala accumulator.
|
static <E,A> Accumulator<E,A> |
done(A a)
Create a done accumulator with the given value.
|
static <E,A> Accumulator<E,A> |
done(java.util.concurrent.CompletionStage<A> a)
Create a done accumulator with the given future.
|
static <E,A> Accumulator<E,A> |
fromSink(akka.stream.javadsl.Sink<E,scala.concurrent.Future<A>> sink)
Create an accumulator from an Akka streams sink.
|
<B> Accumulator<E,B> |
map(java.util.function.Function<? super A,? extends B> f,
java.util.concurrent.Executor executor)
Map the accumulated value.
|
<B> Accumulator<E,B> |
mapFuture(java.util.function.Function<? super A,? extends java.util.concurrent.CompletionStage<B>> f,
java.util.concurrent.Executor executor)
Map the accumulated value with a function that returns a future.
|
Accumulator<E,A> |
recover(java.util.function.Function<? super java.lang.Throwable,? extends A> f,
java.util.concurrent.Executor executor)
Recover from any errors encountered by the accumulator.
|
Accumulator<E,A> |
recoverWith(java.util.function.Function<? super java.lang.Throwable,? extends java.util.concurrent.CompletionStage<A>> f,
java.util.concurrent.Executor executor)
Recover from any errors encountered by the accumulator.
|
java.util.concurrent.CompletionStage<A> |
run(akka.stream.Materializer mat)
Run the accumulator with an empty source.
|
java.util.concurrent.CompletionStage<A> |
run(akka.stream.javadsl.Source<E,?> source,
akka.stream.Materializer mat)
Run the accumulator with the given source.
|
static <E> Accumulator<E,akka.stream.javadsl.Source<E,?>> |
source()
Create an accumulator that forwards the stream fed into it to the source it produces.
|
<D> Accumulator<D,A> |
through(akka.stream.javadsl.Flow<D,E,?> flow)
Pass the stream through the given flow before forwarding it to the accumulator.
|
akka.stream.javadsl.Sink<E,java.util.concurrent.CompletionStage<A>> |
toSink()
Convert this accumulator to a sink.
|
public <B> Accumulator<E,B> map(java.util.function.Function<? super A,? extends B> f, java.util.concurrent.Executor executor)
f
- The function to perform the map with.executor
- The executor to run the function in.public <B> Accumulator<E,B> mapFuture(java.util.function.Function<? super A,? extends java.util.concurrent.CompletionStage<B>> f, java.util.concurrent.Executor executor)
f
- The function to perform the map with.executor
- The executor to run the function in.public Accumulator<E,A> recover(java.util.function.Function<? super java.lang.Throwable,? extends A> f, java.util.concurrent.Executor executor)
f
- The function to use to recover from errors.executor
- The executor to run the function in.public Accumulator<E,A> recoverWith(java.util.function.Function<? super java.lang.Throwable,? extends java.util.concurrent.CompletionStage<A>> f, java.util.concurrent.Executor executor)
f
- The function to use to recover from errors.executor
- The executor to run the function in.public <D> Accumulator<D,A> through(akka.stream.javadsl.Flow<D,E,?> flow)
flow
- The flow to send the stream through first.public java.util.concurrent.CompletionStage<A> run(akka.stream.Materializer mat)
mat
- The flow materializer.public java.util.concurrent.CompletionStage<A> run(akka.stream.javadsl.Source<E,?> source, akka.stream.Materializer mat)
source
- The source to feed into the accumulator.mat
- The flow materializer.public akka.stream.javadsl.Sink<E,java.util.concurrent.CompletionStage<A>> toSink()
public play.api.libs.streams.Accumulator<E,A> asScala()
public static <E,A> Accumulator<E,A> fromSink(akka.stream.javadsl.Sink<E,scala.concurrent.Future<A>> sink)
sink
- The sink.public static <E> Accumulator<E,akka.stream.javadsl.Source<E,?>> source()
public static <E,A> Accumulator<E,A> done(A a)
a
- The done value for the accumulator.public static <E,A> Accumulator<E,A> done(java.util.concurrent.CompletionStage<A> a)
a
- A future of the done value.