Class Sink$
- java.lang.Object
-
- akka.stream.javadsl.Sink$
-
public class Sink$ extends java.lang.Object
Java API
-
-
Constructor Summary
Constructors Constructor Description Sink$()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <In> Sink<In,NotUsed>
actorRef(ActorRef ref, java.lang.Object onCompleteMessage)
Sends the elements of the stream to the givenActorRef
.<In> Sink<In,NotUsed>
actorRefWithAck(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, Function<java.lang.Throwable,java.lang.Object> onFailureMessage)
Deprecated.Use actorRefWithBackpressure instead<In> Sink<In,NotUsed>
actorRefWithBackpressure(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object onCompleteMessage, Function<java.lang.Throwable,java.lang.Object> onFailureMessage)
Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal.<In> Sink<In,NotUsed>
actorRefWithBackpressure(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, Function<java.lang.Throwable,java.lang.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
.<T> Sink<T,NotUsed>
cancelled()
ASink
that immediately cancels its upstream after materialization.<U,In>
Sink<In,java.util.concurrent.CompletionStage<U>>collect(java.util.stream.Collector<In,?,U> collector)
Creates a sink which materializes into aCompletionStage
which will be completed with a result of the Java
Collector
transformation and reduction operations.
<T,U>
Sink<T,NotUsed>combine(Sink<U,?> output1, Sink<U,?> output2, java.util.List<Sink<U,?>> rest, Function<java.lang.Integer,Graph<UniformFanOutShape<T,U>,NotUsed>> fanOutStrategy)
Combine several sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
.<T,U,M>
Sink<T,java.util.List<M>>combine(java.util.List<? extends Graph<SinkShape<U>,M>> sinks, Function<java.lang.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<java.lang.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,java.util.concurrent.CompletionStage<M>>completionStageSink(java.util.concurrent.CompletionStage<Sink<T,M>> future)
Turn aFuture[Sink]
into a Sink that will consume the values of the source when the future completes successfully.<U,In>
Sink<In,java.util.concurrent.CompletionStage<U>>fold(U zero, Function2<U,In,U> f)
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,java.util.concurrent.CompletionStage<U>>foldAsync(U zero, Function2<U,In,java.util.concurrent.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.<T> Sink<T,java.util.concurrent.CompletionStage<Done>>
foreach(Procedure<T> f)
ASink
that will invoke the given procedure for each received element.<T> Sink<T,java.util.concurrent.CompletionStage<Done>>
foreachAsync(int parallelism, Function<T,java.util.concurrent.CompletionStage<java.lang.Void>> f)
ASink
that will invoke the given procedure asynchronously for each received element.<T,M>
Sink<T,M>fromGraph(Graph<SinkShape<T>,M> g)
A graph with the shape of a sink logically is a sink, this method makes it so also in type.<T,M>
Sink<T,java.util.concurrent.CompletionStage<M>>fromMaterializer(java.util.function.BiFunction<Materializer,Attributes,Sink<T,M>> factory)
Defers the creation of aSink
until materialization.<In> Sink<In,NotUsed>
fromSubscriber(org.reactivestreams.Subscriber<In> subs)
Helper to createSink
fromSubscriber
.<In> Sink<In,java.util.concurrent.CompletionStage<In>>
head()
ASink
that materializes into aCompletionStage
of the first value received.<In> Sink<In,java.util.concurrent.CompletionStage<java.util.Optional<In>>>
headOption()
ASink
that materializes into aCompletionStage
of the optional first value received.<T> Sink<T,java.util.concurrent.CompletionStage<Done>>
ignore()
ASink
that will consume the stream and discard the elements.<In> Sink<In,java.util.concurrent.CompletionStage<In>>
last()
ASink
that materializes into aCompletionStage
of the last value received.<In> Sink<In,java.util.concurrent.CompletionStage<java.util.Optional<In>>>
lastOption()
ASink
that materializes into aCompletionStage
of the optional last value received.<T,M>
Sink<T,java.util.concurrent.CompletionStage<M>>lazyCompletionStageSink(Creator<java.util.concurrent.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,java.util.concurrent.CompletionStage<M>>lazyInit(Function<T,java.util.concurrent.CompletionStage<Sink<T,M>>> sinkFactory, Creator<M> fallback)
Deprecated.Use 'Sink.lazyCompletionStageSink' in combination with 'Flow.prefixAndTail(1)' instead.<T,M>
Sink<T,java.util.concurrent.CompletionStage<java.util.Optional<M>>>lazyInitAsync(Creator<java.util.concurrent.CompletionStage<Sink<T,M>>> sinkFactory)
Deprecated.Use 'Sink.lazyCompletionStageSink' instead.<T,M>
Sink<T,java.util.concurrent.CompletionStage<M>>lazySink(Creator<Sink<T,M>> create)
Defers invoking thecreate
function to create a sink until there is a first element passed from upstream.<T> Sink<T,java.util.concurrent.CompletionStage<Done>>
never()
ASink
that will always backpressure never cancel and never consume any elements from the stream.<In> Sink<In,NotUsed>
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 anSinkQueueWithCancel
.<T> Sink<T,SinkQueueWithCancel<T>>
queue(int maxConcurrentPulls)
Creates aSink
that is materialized as anSinkQueueWithCancel
.<In> Sink<In,java.util.concurrent.CompletionStage<In>>
reduce(Function2<In,In,In> f)
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,java.util.concurrent.CompletionStage<java.util.List<In>>>
seq()
ASink
that keeps on collecting incoming elements until upstream terminates.<T,M>
Sink<T,java.util.concurrent.CompletionStage<M>>setup(java.util.function.BiFunction<ActorMaterializer,Attributes,Sink<T,M>> factory)
Deprecated.Use 'fromMaterializer' instead.<In> Sink<In,java.util.concurrent.CompletionStage<java.util.List<In>>>
takeLast(int n)
ASink
that materializes into a aCompletionStage
ofList
containing the lastn
collected elements.
-
-
-
Field Detail
-
MODULE$
public static final Sink$ MODULE$
Static reference to the singleton instance of this Scala object.
-
-
Method Detail
-
fold
public <U,In> Sink<In,java.util.concurrent.CompletionStage<U>> fold(U zero, Function2<U,In,U> f)
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.
-
foldAsync
public <U,In> Sink<In,java.util.concurrent.CompletionStage<U>> foldAsync(U zero, Function2<U,In,java.util.concurrent.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. 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.
-
collect
public <U,In> Sink<In,java.util.concurrent.CompletionStage<U>> collect(java.util.stream.Collector<In,?,U> collector)
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
public <In> Sink<In,java.util.concurrent.CompletionStage<In>> reduce(Function2<In,In,In> f)
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
public <In> Sink<In,NotUsed> fromSubscriber(org.reactivestreams.Subscriber<In> subs)
Helper to createSink
fromSubscriber
.
-
cancelled
public <T> Sink<T,NotUsed> cancelled()
ASink
that immediately cancels its upstream after materialization.
-
ignore
public <T> Sink<T,java.util.concurrent.CompletionStage<Done>> ignore()
ASink
that will consume the stream and discard the elements.
-
never
public <T> Sink<T,java.util.concurrent.CompletionStage<Done>> never()
ASink
that will always backpressure never cancel and never consume any elements from the stream.
-
asPublisher
public <T> Sink<T,org.reactivestreams.Publisher<T>> asPublisher(AsPublisher fanout)
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.
-
foreach
public <T> Sink<T,java.util.concurrent.CompletionStage<Done>> foreach(Procedure<T> f)
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,java.util.concurrent.CompletionStage<Done>> foreachAsync(int parallelism, Function<T,java.util.concurrent.CompletionStage<java.lang.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
public <In> Sink<In,NotUsed> 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
.
-
head
public <In> Sink<In,java.util.concurrent.CompletionStage<In>> 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
public <In> Sink<In,java.util.concurrent.CompletionStage<java.util.Optional<In>>> 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
public <In> Sink<In,java.util.concurrent.CompletionStage<In>> 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
public <In> Sink<In,java.util.concurrent.CompletionStage<java.util.Optional<In>>> 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
public <In> Sink<In,java.util.concurrent.CompletionStage<java.util.List<In>>> takeLast(int n)
ASink
that materializes into a 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
public <In> Sink<In,java.util.concurrent.CompletionStage<java.util.List<In>>> 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
-
actorRef
public <In> Sink<In,NotUsed> actorRef(ActorRef ref, java.lang.Object onCompleteMessage)
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 aStatus.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, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, Function<java.lang.Throwable,java.lang.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, java.lang.Object onInitMessage, java.lang.Object onCompleteMessage, Function<java.lang.Throwable,java.lang.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.
-
actorRefWithAck
public <In> Sink<In,NotUsed> actorRefWithAck(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, Function<java.lang.Throwable,java.lang.Object> onFailureMessage)
Deprecated.Use actorRefWithBackpressure insteadSends 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.
-
fromGraph
public <T,M> Sink<T,M> fromGraph(Graph<SinkShape<T>,M> g)
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,java.util.concurrent.CompletionStage<M>> fromMaterializer(java.util.function.BiFunction<Materializer,Attributes,Sink<T,M>> factory)
-
setup
public <T,M> Sink<T,java.util.concurrent.CompletionStage<M>> setup(java.util.function.BiFunction<ActorMaterializer,Attributes,Sink<T,M>> factory)
Deprecated.Use 'fromMaterializer' instead. Since 2.6.0.
-
combine
public <T,U> Sink<T,NotUsed> combine(Sink<U,?> output1, Sink<U,?> output2, java.util.List<Sink<U,?>> rest, Function<java.lang.Integer,Graph<UniformFanOutShape<T,U>,NotUsed>> fanOutStrategy)
Combine several sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
.
-
combineMat
public <T,U,M1,M2,M> Sink<T,M> combineMat(Sink<U,M1> first, Sink<U,M2> second, Function<java.lang.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.
-
combine
public <T,U,M> Sink<T,java.util.List<M>> combine(java.util.List<? extends Graph<SinkShape<U>,M>> sinks, Function<java.lang.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'.
-
queue
public <T> Sink<T,SinkQueueWithCancel<T>> queue(int maxConcurrentPulls)
Creates aSink
that is materialized as anSinkQueueWithCancel
.akka.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
SinkQueueWithCancel
including last None as completion marker- See Also:
SinkQueueWithCancel
-
queue
public <T> Sink<T,SinkQueueWithCancel<T>> queue()
Creates aSink
that is materialized as anSinkQueueWithCancel
.akka.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
SinkQueueWithCancel
including last None as completion marker- See Also:
SinkQueueWithCancel
-
lazyInit
public <T,M> Sink<T,java.util.concurrent.CompletionStage<M>> lazyInit(Function<T,java.util.concurrent.CompletionStage<Sink<T,M>>> sinkFactory, Creator<M> fallback)
Deprecated.Use 'Sink.lazyCompletionStageSink' in combination with 'Flow.prefixAndTail(1)' instead. Since 2.6.0.Creates a realSink
upon receiving the first element. InternalSink
will not be created if there are no elements, because of completion or error.If upstream completes before an element was received then the
Future
is completed with the value created by fallback. If upstream fails before an element was received,sinkFactory
throws an exception, or materialization of the internal sink fails then theFuture
is completed with the exception. Otherwise theFuture
is completed with the materialized value of the internal sink.
-
lazyInitAsync
public <T,M> Sink<T,java.util.concurrent.CompletionStage<java.util.Optional<M>>> lazyInitAsync(Creator<java.util.concurrent.CompletionStage<Sink<T,M>>> sinkFactory)
Deprecated.Use 'Sink.lazyCompletionStageSink' instead. Since 2.6.0.Creates a realSink
upon receiving the first element. InternalSink
will not be created if there are no elements, because of completion or error.If upstream completes before an element was received then the
Future
is completed withNone
. If upstream fails before an element was received,sinkFactory
throws an exception, or materialization of the internal sink fails then theFuture
is completed with the exception. Otherwise theFuture
is completed with the materialized value of the internal sink.
-
completionStageSink
public <T,M> Sink<T,java.util.concurrent.CompletionStage<M>> completionStageSink(java.util.concurrent.CompletionStage<Sink<T,M>> future)
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
public <T,M> Sink<T,java.util.concurrent.CompletionStage<M>> lazySink(Creator<Sink<T,M>> create)
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 aNeverMaterializedException
.
-
lazyCompletionStageSink
public <T,M> Sink<T,java.util.concurrent.CompletionStage<M>> lazyCompletionStageSink(Creator<java.util.concurrent.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 aNeverMaterializedException
.
-
-