Class Sink$
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSends the elements of the stream to the givenActorRef
.actorRefWithBackpressure
(ActorRef ref, Object onInitMessage, Object ackMessage, Object onCompleteMessage, Function<Throwable, Object> onFailureMessage) Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal.actorRefWithBackpressure
(ActorRef ref, Object onInitMessage, Object onCompleteMessage, Function<Throwable, Object> onFailureMessage) Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal.<T> Sink<T,
org.reactivestreams.Publisher<T>> asPublisher
(AsPublisher fanout) ASink
that materializes into aPublisher
.ASink
that immediately cancels its upstream after materialization.<U,
In> Sink<In, CompletionStage<U>> Creates a sink which materializes into aCompletionStage
which will be completed with a result of the Java
Collector
transformation and reduction operations.
combine
(List<? extends Graph<SinkShape<U>, M>> sinks, Function<Integer, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy) Combine several sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
.combine
(Sink<U, ?> output1, Sink<U, ?> output2, List<Sink<U, ?>> rest, Function<Integer, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy) Combine several sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
.<T,
U, M1, M2, M>
Sink<T,M> combineMat
(Sink<U, M1> first, Sink<U, M2> second, Function<Integer, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy, Function2<M1, M2, M> matF) Combine two sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
with 2 outlets.<T,
M> Sink<T, CompletionStage<M>> completionStageSink
(CompletionStage<Sink<T, M>> future) Turn aFuture[Sink]
into a Sink that will consume the values of the source when the future completes successfully.<In> Sink<In,
CompletionStage<Long>> count()
ASink
that counts all incoming elements until upstream terminates.<In> Sink<In,
CompletionStage<Boolean>> ASink
that will test the given predicatep
for every received element and 1.<U,
In> Sink<In, CompletionStage<U>> ASink
that will invoke the given function for every received element, giving it its previous output (or the givenzero
value) and the element as input.<U,
In> Sink<In, CompletionStage<U>> foldAsync
(U zero, Function2<U, In, CompletionStage<U>> f) ASink
that will invoke the given asynchronous function for every received element, giving it its previous output (or the givenzero
value) and the element as input.<U,
In> Sink<In, CompletionStage<U>> ASink
that will invoke the given function for every received element, giving it its previous output (or the givenzero
value) and the element as input.<In> Sink<In,
CompletionStage<Boolean>> ASink
that will test the given predicatep
for every received element and 1.<T> Sink<T,
CompletionStage<Done>> ASink
that will invoke the given procedure for each received element.<T> Sink<T,
CompletionStage<Done>> foreachAsync
(int parallelism, Function<T, CompletionStage<Void>> f) ASink
that will invoke the given procedure asynchronously for each received element.<T,
M> Sink<T, M> A graph with the shape of a sink logically is a sink, this method makes it so also in type.<T,
M> Sink<T, CompletionStage<M>> fromMaterializer
(Function2<Materializer, Attributes, Sink<T, M>> factory) Defers the creation of aSink
until materialization.fromSubscriber
(org.reactivestreams.Subscriber<In> subs) Helper to createSink
fromSubscriber
.<In> Sink<In,
CompletionStage<In>> head()
ASink
that materializes into aCompletionStage
of the first value received.<In> Sink<In,
CompletionStage<Optional<In>>> ASink
that materializes into aCompletionStage
of the optional first value received.<T> Sink<T,
CompletionStage<Done>> ignore()
ASink
that will consume the stream and discard the elements.<In> Sink<In,
CompletionStage<In>> last()
ASink
that materializes into aCompletionStage
of the last value received.<In> Sink<In,
CompletionStage<Optional<In>>> ASink
that materializes into aCompletionStage
of the optional last value received.<T,
M> Sink<T, CompletionStage<M>> lazyCompletionStageSink
(Creator<CompletionStage<Sink<T, M>>> create) Defers invoking thecreate
function to create a future sink until there is a first element passed from upstream.<T,
M> Sink<T, CompletionStage<M>> Defers invoking thecreate
function to create a sink until there is a first element passed from upstream.<T> Sink<T,
CompletionStage<Done>> never()
ASink
that will always backpressure never cancel and never consume any elements from the stream.<In> Sink<In,
CompletionStage<Boolean>> ASink
that will test the given predicatep
for every received element and 1.onComplete
(Procedure<scala.util.Try<Done>> callback) ASink
that when the flow is completed, either through a failure or normal completion, apply the provided function withSuccess
orFailure
.<T> Sink<T,
SinkQueueWithCancel<T>> queue()
Creates aSink
that is materialized as anpekko.stream.javadsl.SinkQueueWithCancel
.<T> Sink<T,
SinkQueueWithCancel<T>> queue
(int maxConcurrentPulls) Creates aSink
that is materialized as anpekko.stream.javadsl.SinkQueueWithCancel
.<In> Sink<In,
CompletionStage<In>> ASink
that will invoke the given function for every received element, giving it its previous output (from the second element) and the element as input.<In> Sink<In,
CompletionStage<List<In>>> seq()
ASink
that keeps on collecting incoming elements until upstream terminates.source()
ASink
that materializes thisSink
itself as aSource
.<In> Sink<In,
CompletionStage<List<In>>> takeLast
(int n) ASink
that materializes into aCompletionStage
ofList
containing the lastn
collected elements.
-
Field Details
-
MODULE$
Static reference to the singleton instance of this Scala object.
-
-
Constructor Details
-
Sink$
public Sink$()
-
-
Method Details
-
fold
ASink
that will invoke the given function for every received element, giving it its previous output (or the givenzero
value) and the element as input. The returnedCompletionStage
will be completed with value of the final function evaluation when the input stream ends, or completed withFailure
if there is a failure is signaled in the stream. -
foldWhile
ASink
that will invoke the given function for every received element, giving it its previous output (or the givenzero
value) and the element as input. The returnedCompletionStage
will be completed with value of the final function evaluation when the input stream ends, predicatep
returns false, or completed withFailure
if there is a failure is signaled in the stream.- Since:
- 1.1.0
-
foldAsync
ASink
that will invoke the given asynchronous function for every received element, giving it its previous output (or the givenzero
value) and the element as input. The returnedCompletionStage
will be completed with value of the final function evaluation when the input stream ends, or completed withFailure
if there is a failure is signaled in the stream. -
forall
ASink
that will test the given predicatep
for every received element and 1. completes and returnsCompletionStage
oftrue
if the predicate is true for all elements; 2. completes and returnsCompletionStage
oftrue
if the stream is empty (i.e. completes before signalling any elements); 3. completes and returnsCompletionStage
offalse
if the predicate is false for any element.The materialized value
CompletionStage
will be completed with the valuetrue
orfalse
when the input stream ends, or completed withFailure
if there is a failure signaled in the stream.Adheres to the
ActorAttributes.SupervisionStrategy
attribute.'''Completes when''' upstream completes or the predicate
p
returnsfalse
'''Backpressures when''' the invocation of predicate
p
has not yet completed'''Cancels when''' predicate
p
returnsfalse
- Since:
- 1.1.0
-
none
ASink
that will test the given predicatep
for every received element and 1. completes and returnsCompletionStage
oftrue
if the predicate is false for all elements; 2. completes and returnsCompletionStage
oftrue
if the stream is empty (i.e. completes before signalling any elements); 3. completes and returnsCompletionStage
offalse
if the predicate is true for any element.The materialized value
CompletionStage
will be completed with the valuetrue
orfalse
when the input stream ends, or completed withFailure
if there is a failure signaled in the stream.Adheres to the
ActorAttributes.SupervisionStrategy
attribute.'''Completes when''' upstream completes or the predicate
p
returnstrue
'''Backpressures when''' the invocation of predicate
p
has not yet completed'''Cancels when''' predicate
p
returnstrue
- Since:
- 1.2.0
-
exists
ASink
that will test the given predicatep
for every received element and 1. completes and returnsCompletionStage
oftrue
if the predicate is true for any element; 2. completes and returnsCompletionStage
offalse
if the stream is empty (i.e. completes before signalling any elements); 3. completes and returnsCompletionStage
offalse
if the predicate is false for all elements.The materialized value
CompletionStage
will be completed with the valuetrue
orfalse
when the input stream ends, or completed withFailure
if there is a failure signaled in the stream.Adheres to the
ActorAttributes.SupervisionStrategy
attribute.'''Completes when''' upstream completes or the predicate
p
returnstrue
'''Backpressures when''' the invocation of predicate
p
has not yet completed'''Cancels when''' predicate
p
returnstrue
- Since:
- 1.1.0
-
collect
Creates a sink which materializes into aCompletionStage
which will be completed with a result of the Java
Collector
transformation and reduction operations. This allows usage of Java streams transformations for reactive streams. The
Collector
will trigger demand downstream. Elements emitted through the stream will be accumulated into a mutable result container, optionally transformed into a final representation after all input elements have been processed. The
Collector
can also do reduction at the end. Reduction processing is performed sequentially.
-
reduce
ASink
that will invoke the given function for every received element, giving it its previous output (from the second element) and the element as input. The returnedCompletionStage
will be completed with value of the final function evaluation when the input stream ends, or completed withFailure
if there is a failure signaled in the stream.If the stream is empty (i.e. completes before signalling any elements), the reduce operator will fail its downstream with a
NoSuchElementException
, which is semantically in-line with that Scala's standard library collections do in such situations. -
fromSubscriber
Helper to createSink
fromSubscriber
. -
cancelled
ASink
that immediately cancels its upstream after materialization. -
ignore
ASink
that will consume the stream and discard the elements. -
never
ASink
that will always backpressure never cancel and never consume any elements from the stream. -
asPublisher
ASink
that materializes into aPublisher
.If
fanout
istrue
, the materializedPublisher
will support multipleSubscriber
s and the size of theinputBuffer
configured for this operator becomes the maximum number of elements that the fastestSubscriber
can be ahead of the slowest one before slowing the processing down due to back pressure.If
fanout
isfalse
then the materializedPublisher
will only support a singleSubscriber
and reject any additionalSubscriber
s. -
source
ASink
that materializes thisSink
itself as aSource
. The returnedSource
is a "live view" onto theSink
and only supports a singleSubscriber
.Use
BroadcastHub#sink
if you need aSource
that allows multiple subscribers.Note: even if the
Source
is directly connected to theSink
, there is still an asynchronous boundary between them; performance may be improved in the future.- Since:
- 2.0.0
-
foreach
ASink
that will invoke the given procedure for each received element. The sink is materialized into aCompletionStage
which will be completed withSuccess
when reaching the normal end of the stream, or completed withFailure
if there is a failure signaled in the stream. -
foreachAsync
public <T> Sink<T,CompletionStage<Done>> foreachAsync(int parallelism, Function<T, CompletionStage<Void>> f) ASink
that will invoke the given procedure asynchronously for each received element. The sink is materialized into aCompletionStage
which will be completed withSuccess
when reaching the normal end of the stream, or completed withFailure
if there is a failure signaled in the stream. -
onComplete
ASink
that when the flow is completed, either through a failure or normal completion, apply the provided function withSuccess
orFailure
. -
head
ASink
that materializes into aCompletionStage
of the first value received. If the stream completes before signaling at least a single element, the CompletionStage will be failed with aNoSuchElementException
. If the stream signals an error before signaling at least a single element, the CompletionStage will be failed with the streams exception.See also
<In>headOption()
. -
headOption
ASink
that materializes into aCompletionStage
of the optional first value received. If the stream completes before signaling at least a single element, the value of the CompletionStage will be an emptyOptional
. If the stream signals an error errors before signaling at least a single element, the CompletionStage will be failed with the streams exception.See also
<In>head()
. -
last
ASink
that materializes into aCompletionStage
of the last value received. If the stream completes before signaling at least a single element, the CompletionStage will be failed with aNoSuchElementException
. If the stream signals an error errors before signaling at least a single element, the CompletionStage will be failed with the streams exception.See also
<In>lastOption()
,<In>takeLast(int)
. -
lastOption
ASink
that materializes into aCompletionStage
of the optional last value received. If the stream completes before signaling at least a single element, the value of the CompletionStage will be an emptyOptional
. If the stream signals an error errors before signaling at least a single element, the CompletionStage will be failed with the streams exception.See also
<In>head()
,<In>takeLast(int)
. -
takeLast
ASink
that materializes into aCompletionStage
ofList
containing the lastn
collected elements.If the stream completes before signaling at least n elements, the
CompletionStage
will complete with all elements seen so far. If the stream never completes theCompletionStage
will never complete. If there is a failure signaled in the stream theCompletionStage
will be completed with failure. -
seq
ASink
that keeps on collecting incoming elements until upstream terminates. As upstream may be unbounded,Flow[T].take
or the stricterFlow[T].limit
(and their variants) may be used to ensure boundedness. Materializes into aCompletionStage
ofSeq[T]
containing all the collected elements.List
is limited toInteger.MAX_VALUE
elements, this Sink will cancel the stream after having received that many elements.See also
Flow.limit
,Flow.limitWeighted
,Flow.take
,Flow.takeWithin
,Flow.takeWhile
-
count
ASink
that counts all incoming elements until upstream terminates.Since upstream may be unbounded, consider using
Flow[T].take
or the stricterFlow[T].limit
(and their variants) to ensure boundedness. The sink materializes into aCompletionStage
ofLong
containing the total count of elements that passed through.'''Completes when''' upstream completes
'''Backpressures when''' never (counting is a lightweight operation)
'''Cancels when''' never
- Returns:
- a
Sink
that materializes to aCompletionStage[Long]
with the element count - Since:
- 2.0.0
See also
Flow.limit
,Flow.limitWeighted
,Flow.take
,Flow.takeWithin
,Flow.takeWhile
-
actorRef
Sends the elements of the stream to the givenActorRef
. If the target actor terminates the stream will be canceled. When the stream is completed successfully the givenonCompleteMessage
will be sent to the destination actor. When the stream is completed with failure apekko.actor.Status.Failure
message will be sent to the destination actor.It will request at most
maxInputBufferSize
number of elements from upstream, but there is no back-pressure signal from the destination actor, i.e. if the actor is not consuming the messages fast enough the mailbox of the actor will grow. For potentially slow consumer actors it is recommended to use a bounded mailbox with zeromailbox-push-timeout-time
or use a rate limiting operator in front of thisSink
. -
actorRefWithBackpressure
public <In> Sink<In,NotUsed> actorRefWithBackpressure(ActorRef ref, Object onInitMessage, Object ackMessage, Object onCompleteMessage, Function<Throwable, Object> onFailureMessage) Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal. First element is alwaysonInitMessage
, then stream is waiting for acknowledgement messageackMessage
from the given actor which means that it is ready to process elements. It also requiresackMessage
message after each stream element to make backpressure work.If the target actor terminates the stream will be canceled. When the stream is completed successfully the given
onCompleteMessage
will be sent to the destination actor. When the stream is completed with failure - result ofonFailureMessage(throwable)
message will be sent to the destination actor. -
actorRefWithBackpressure
public <In> Sink<In,NotUsed> actorRefWithBackpressure(ActorRef ref, Object onInitMessage, Object onCompleteMessage, Function<Throwable, Object> onFailureMessage) Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal. First element is alwaysonInitMessage
, then stream is waiting for acknowledgement message from the given actor which means that it is ready to process elements. It also requires an ack message after each stream element to make backpressure work. This variant will consider any message as ack message.If the target actor terminates the stream will be canceled. When the stream is completed successfully the given
onCompleteMessage
will be sent to the destination actor. When the stream is completed with failure - result ofonFailureMessage(throwable)
message will be sent to the destination actor. -
fromGraph
A graph with the shape of a sink logically is a sink, this method makes it so also in type. -
fromMaterializer
public <T,M> Sink<T,CompletionStage<M>> fromMaterializer(Function2<Materializer, Attributes, Sink<T, M>> factory) -
combine
public <T,U> Sink<T,NotUsed> combine(Sink<U, ?> output1, Sink<U, ?> output2, List<Sink<U, ?>> rest, Function<Integer, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy) Combine several sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
. -
combineMat
public <T,U, Sink<T,M1, M2, M> M> combineMat(Sink<U, M1> first, Sink<U, M2> second, Function<Integer, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy, Function2<M1, M2, M> matF) Combine two sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
with 2 outlets.- Since:
- 1.1.0
-
combine
public <T,U, Sink<T,M> List<M>> combine(List<? extends Graph<SinkShape<U>, M>> sinks, Function<Integer, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy) Combine several sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
. The fanoutGraph's outlets size must match the provides sinks'.- Since:
- 1.1.0
-
queue
Creates aSink
that is materialized as anpekko.stream.javadsl.SinkQueueWithCancel
.pekko.stream.javadsl.SinkQueueWithCancel.pull
method is pulling element from the stream and returnsCompletionStage[Option[T}
.
CompletionStage
completes when element is available.Before calling pull method second time you need to ensure that number of pending pulls is less then
maxConcurrentPulls
or wait until some of the previous Futures completes. Pull returns Failed future with ''IllegalStateException'' if there will be more then
maxConcurrentPulls
number of pending pulls.
Sink
will request at most number of elements equal to size ofinputBuffer
from upstream and then stop back pressure. You can configure size of input buffer by usingSink.withAttributes
method.For stream completion you need to pull all elements from
pekko.stream.javadsl.SinkQueueWithCancel
including last None as completion marker- See Also:
-
pekko.stream.javadsl.SinkQueueWithCancel
-
queue
Creates aSink
that is materialized as anpekko.stream.javadsl.SinkQueueWithCancel
.pekko.stream.javadsl.SinkQueueWithCancel.pull
method is pulling element from the stream and returnsCompletionStage[Option[T}
.
CompletionStage
completes when element is available.Before calling pull method second time you need to wait until previous CompletionStage completes. Pull returns Failed future with ''IllegalStateException'' if previous future has not yet completed.
Sink
will request at most number of elements equal to size ofinputBuffer
from upstream and then stop back pressure. You can configure size of input buffer by usingSink.withAttributes
method.For stream completion you need to pull all elements from
pekko.stream.javadsl.SinkQueueWithCancel
including last None as completion marker- See Also:
-
pekko.stream.javadsl.SinkQueueWithCancel
-
completionStageSink
Turn aFuture[Sink]
into a Sink that will consume the values of the source when the future completes successfully. If theFuture
is completed with a failure the stream is failed.The materialized future value is completed with the materialized value of the future sink or failed with a
NeverMaterializedException
if upstream fails or downstream cancels before the future has completed. -
lazySink
Defers invoking thecreate
function to create a sink until there is a first element passed from upstream.The materialized future value is completed with the materialized value of the created sink when that has successfully been materialized.
If the
create
function throws or returns or the stream fails to materialize, in this case the materialized future value is failed with apekko.stream.NeverMaterializedException
. -
lazyCompletionStageSink
public <T,M> Sink<T,CompletionStage<M>> lazyCompletionStageSink(Creator<CompletionStage<Sink<T, M>>> create) Defers invoking thecreate
function to create a future sink until there is a first element passed from upstream.The materialized future value is completed with the materialized value of the created sink when that has successfully been materialized.
If the
create
function throws or returns a future that is failed, or the stream fails to materialize, in this case the materialized future value is failed with apekko.stream.NeverMaterializedException
.
-