Class Sink$
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionactorRef(ActorRef ref, Object onCompleteMessage, scala.Function1<Throwable, Object> onFailureMessage) INTERNAL APIactorRefWithBackpressure(ActorRef ref, Object onInitMessage, Object ackMessage, Object onCompleteMessage, scala.Function1<Throwable, Object> onFailureMessage) Sends the elements of the stream to the givenActorRefthat sends back back-pressure signal.actorRefWithBackpressure(ActorRef ref, Object onInitMessage, Object onCompleteMessage, scala.Function1<Throwable, Object> onFailureMessage) Sends the elements of the stream to the givenActorRefthat sends back back-pressure signal.<T> Sink<T,org.reactivestreams.Publisher<T>> asPublisher(boolean fanout) ASinkthat materializes into aPublisher.ASinkthat immediately cancels its upstream after materialization.<T,That> Sink<T, scala.concurrent.Future<That>> collection(scala.collection.Factory<T, That> cbf) ASinkthat keeps on collecting incoming elements until upstream terminates.combine(Sink<U, ?> first, Sink<U, ?> second, scala.collection.immutable.Seq<Sink<U, ?>> rest, scala.Function1<Object, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy) Combine several sinks with fan-out strategy likeBroadcastorBalanceand returnsSink.<T,U, M> Sink<T, scala.collection.immutable.Seq<M>> combine(scala.collection.immutable.Seq<Graph<SinkShape<U>, M>> sinks, scala.Function1<Object, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy) Combine several sinks with fan-out strategy likeBroadcastorBalanceand returnsSink.<T,U, M1, M2, M>
Sink<T,M> combineMat(Sink<U, M1> first, Sink<U, M2> second, scala.Function1<Object, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy, scala.Function2<M1, M2, M> matF) Combine two sinks with fan-out strategy likeBroadcastorBalanceand returnsSinkwith 2 outlets.count()ASinkthat counts all incoming elements until upstream terminates.ASinkthat will test the given predicatepfor every received element and 1.<U,T> Sink<T, scala.concurrent.Future<U>> fold(U zero, scala.Function2<U, T, U> f) ASinkthat will invoke the given function for every received element, giving it its previous output (or the givenzerovalue) and the element as input.<U,T> Sink<T, scala.concurrent.Future<U>> foldAsync(U zero, scala.Function2<U, T, scala.concurrent.Future<U>> f) ASinkthat will invoke the given asynchronous function for every received element, giving it its previous output (or the givenzerovalue) and the element as input.<U,T> Sink<T, scala.concurrent.Future<U>> ASinkthat will invoke the given function for every received element, giving it its previous output (or the givenzerovalue) and the element as input.ASinkthat will test the given predicatepfor every received element and 1.foreach(scala.Function1<T, scala.runtime.BoxedUnit> f) ASinkthat will invoke the given procedure for each received element.foreachAsync(int parallelism, scala.Function1<T, scala.concurrent.Future<scala.runtime.BoxedUnit>> f) ASinkthat 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, scala.concurrent.Future<M>> fromMaterializer(scala.Function2<Materializer, Attributes, Sink<T, M>> factory) Defers the creation of aSinkuntil materialization.fromSubscriber(org.reactivestreams.Subscriber<T> subscriber) Helper to createSinkfromSubscriber.<T,M> Sink<T, scala.concurrent.Future<M>> futureSink(scala.concurrent.Future<Sink<T, M>> future) Turn aFuture[Sink]into a Sink that will consume the values of the source when the future completes successfully.<T> Sink<T,scala.concurrent.Future<T>> head()ASinkthat materializes into aFutureof the first value received.<T> Sink<T,scala.concurrent.Future<scala.Option<T>>> ASinkthat materializes into aFutureof the optional first value received.ignore()ASinkthat will consume the stream and discard the elements.<T> Sink<T,scala.concurrent.Future<T>> last()ASinkthat materializes into aFutureof the last value received.<T> Sink<T,scala.concurrent.Future<scala.Option<T>>> ASinkthat materializes into aFutureof the optional last value received.<T,M> Sink<T, scala.concurrent.Future<M>> lazyFutureSink(scala.Function0<scala.concurrent.Future<Sink<T, M>>> create) Defers invoking thecreatefunction to create a future sink until there is a first element passed from upstream.<T,M> Sink<T, scala.concurrent.Future<M>> Defers invoking thecreatefunction to create a sink until there is a first element passed from upstream.never()ASinkthat will always backpressure never cancel and never consume any elements from the stream.ASinkthat will test the given predicatepfor every received element and 1.onComplete(scala.Function1<scala.util.Try<Done>, scala.runtime.BoxedUnit> callback) ASinkthat when the flow is completed, either through a failure or normal completion, apply the provided function withSuccessorFailure.<T> Sink<T,SinkQueueWithCancel<T>> queue()Creates aSinkthat is materialized as anpekko.stream.scaladsl.SinkQueueWithCancel.<T> Sink<T,SinkQueueWithCancel<T>> queue(int maxConcurrentPulls) Creates aSinkthat is materialized as anpekko.stream.scaladsl.SinkQueueWithCancel.<T> Sink<T,scala.concurrent.Future<T>> reduce(scala.Function2<T, T, T> f) ASinkthat will invoke the given function for every received element, giving it its previous output (from the second element) and the element as input.<T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> seq()ASinkthat keeps on collecting incoming elements until upstream terminates.<T> SinkShape<T>INTERNAL APIsource()ASinkthat materializes thisSinkitself as aSource.<T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> takeLast(int n) ASinkthat materializes into aFutureofimmutable.Seq[T]containing the lastncollected elements.
-
Field Details
-
MODULE$
Static reference to the singleton instance of this Scala object.
-
-
Constructor Details
-
Sink$
public Sink$()
-
-
Method Details
-
shape
INTERNAL API -
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,scala.concurrent.Future<M>> fromMaterializer(scala.Function2<Materializer, Attributes, Sink<T, M>> factory) -
fromSubscriber
Helper to createSinkfromSubscriber. -
cancelled
ASinkthat immediately cancels its upstream after materialization. -
head
ASinkthat materializes into aFutureof the first value received. If the stream completes before signaling at least a single element, the Future will be failed with aNoSuchElementException. If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.See also
<T>headOption(). -
headOption
ASinkthat materializes into aFutureof the optional first value received. If the stream completes before signaling at least a single element, the value of the Future will beNone. If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.See also
<T>head(). -
last
ASinkthat materializes into aFutureof the last value received. If the stream completes before signaling at least a single element, the Future will be failed with aNoSuchElementException. If the stream signals an error, the Future will be failed with the stream's exception.See also
<T>lastOption(),<T>takeLast(int). -
lastOption
ASinkthat materializes into aFutureof the optional last value received. If the stream completes before signaling at least a single element, the value of the Future will beNone. If the stream signals an error, the Future will be failed with the stream's exception.See also
<T>last(),<T>takeLast(int). -
takeLast
ASinkthat materializes into aFutureofimmutable.Seq[T]containing the lastncollected elements.If the stream completes before signaling at least n elements, the
Futurewill complete with all elements seen so far. If the stream never completes, theFuturewill never complete. If there is a failure signaled in the stream theFuturewill be completed with failure. -
seq
ASinkthat keeps on collecting incoming elements until upstream terminates. As upstream may be unbounded,Flow[T].takeor the stricterFlow[T].limit(and their variants) may be used to ensure boundedness. Materializes into aFutureofSeq[T]containing all the collected elements.Seqis limited toInt.MaxValueelements, 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
ASinkthat counts all incoming elements until upstream terminates.Since upstream may be unbounded, consider using
Flow[T].takeor the stricterFlow[T].limit(and their variants) to ensure boundedness. The sink materializes into aFutureofLongcontaining 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
Sinkthat materializes to aFuture[Long]with the element count - Since:
- 1.3.0
See also
Flow.limit,Flow.limitWeighted,Flow.take,Flow.takeWithin,Flow.takeWhile
-
collection
public <T,That> Sink<T,scala.concurrent.Future<That>> collection(scala.collection.Factory<T, That> cbf) ASinkthat keeps on collecting incoming elements until upstream terminates. As upstream may be unbounded,Flow[T].takeor the stricterFlow[T].limit(and their variants) may be used to ensure boundedness. Materializes into aFutureofThat[T]containing all the collected elements.That[T]is limited to the limitations of the CanBuildFrom associated with it. For example,Seqis limited toInt.MaxValueelements. See [The Architecture of Scala 2.13's Collections](https://docs.scala-lang.org/overviews/core/architecture-of-scala-213-collections.html) for more info. This Sink will cancel the stream after having received that many elements.See also
Flow.limit,Flow.limitWeighted,Flow.take,Flow.takeWithin,Flow.takeWhile -
asPublisher
ASinkthat materializes into aPublisher.If
fanoutistrue, the materializedPublisherwill support multipleSubscribers and the size of theinputBufferconfigured for this operator becomes the maximum number of elements that the fastestSubscribercan be ahead of the slowest one before slowing the processing down due to back pressure.If
fanoutisfalsethen the materializedPublisherwill only support a singleSubscriberand reject any additionalSubscribers. -
source
ASinkthat materializes thisSinkitself as aSource. The returnedSourceis a "live view" onto theSinkand only supports a singleSubscriber.Use
BroadcastHub.sink(int)if you need aSourcethat allows multiple subscribers.Note: even if the
Sourceis directly connected to theSink, there is still an asynchronous boundary between them; performance may be improved in the future.- Since:
- 1.3.0
-
ignore
ASinkthat will consume the stream and discard the elements. -
never
ASinkthat will always backpressure never cancel and never consume any elements from the stream. -
foreach
public <T> Sink<T,scala.concurrent.Future<Done>> foreach(scala.Function1<T, scala.runtime.BoxedUnit> f) ASinkthat will invoke the given procedure for each received element. The sink is materialized into aFuturewhich will be completed withSuccesswhen reaching the normal end of the stream, or completed withFailureif there is a failure signaled in the stream. -
foreachAsync
public <T> Sink<T,scala.concurrent.Future<Done>> foreachAsync(int parallelism, scala.Function1<T, scala.concurrent.Future<scala.runtime.BoxedUnit>> f) ASinkthat will invoke the given procedure asynchronously for each received element. The sink is materialized into aFuturewhich will be completed withSuccesswhen reaching the normal end of the stream, or completed withFailureif there is a failure signaled in the stream. -
combine
public <T,U> Sink<T,NotUsed> combine(Sink<U, ?> first, Sink<U, ?> second, scala.collection.immutable.Seq<Sink<U, ?>> rest, scala.Function1<Object, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy) Combine several sinks with fan-out strategy likeBroadcastorBalanceand returnsSink. -
combineMat
public <T,U, Sink<T,M1, M2, M> M> combineMat(Sink<U, M1> first, Sink<U, M2> second, scala.Function1<Object, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy, scala.Function2<M1, M2, M> matF) Combine two sinks with fan-out strategy likeBroadcastorBalanceand returnsSinkwith 2 outlets.- Since:
- 1.1.0
-
combine
public <T,U, Sink<T,M> scala.collection.immutable.Seq<M>> combine(scala.collection.immutable.Seq<Graph<SinkShape<U>, M>> sinks, scala.Function1<Object, Graph<UniformFanOutShape<T, U>, NotUsed>> fanOutStrategy) Combine several sinks with fan-out strategy likeBroadcastorBalanceand returnsSink. The fanoutGraph's outlets size must match the provides sinks'.- Since:
- 1.1.0
-
fold
ASinkthat will invoke the given function for every received element, giving it its previous output (or the givenzerovalue) and the element as input. The returnedFuturewill be completed with value of the final function evaluation when the input stream ends, or completed withFailureif there is a failure signaled in the stream. -
foldWhile
public <U,T> Sink<T,scala.concurrent.Future<U>> foldWhile(U zero, scala.Function1<U, Object> p, scala.Function2<U, T, U> f) ASinkthat will invoke the given function for every received element, giving it its previous output (or the givenzerovalue) and the element as input. The returnedFuturewill be completed with value of the final function evaluation when the input stream ends, predicatepreturns false, or completed withFailureif there is a failure signaled in the stream. -
foldAsync
public <U,T> Sink<T,scala.concurrent.Future<U>> foldAsync(U zero, scala.Function2<U, T, scala.concurrent.Future<U>> f) ASinkthat will invoke the given asynchronous function for every received element, giving it its previous output (or the givenzerovalue) and the element as input. The returnedFuturewill be completed with value of the final function evaluation when the input stream ends, or completed withFailureif there is a failure signaled in the stream.- See Also:
-
forall
ASinkthat will test the given predicatepfor every received element and 1. completes and returnsFutureoftrueif the predicate is true for all elements; 2. completes and returnsFutureoftrueif the stream is empty (i.e. completes before signalling any elements); 3. completes and returnsFutureoffalseif the predicate is false for any element.The materialized value
Futurewill be completed with the valuetrueorfalsewhen the input stream ends, or completed withFailureif there is a failure signaled in the stream.Adheres to the
ActorAttributes.SupervisionStrategyattribute.'''Completes when''' upstream completes or the predicate
preturnsfalse'''Backpressures when''' the invocation of predicate
phas not yet completed'''Cancels when''' predicate
preturnsfalse- Since:
- 1.1.0
-
none
ASinkthat will test the given predicatepfor every received element and 1. completes and returnsFutureoftrueif the predicate is false for all elements; 2. completes and returnsFutureoftrueif the stream is empty (i.e. completes before signalling any elements); 3. completes and returnsFutureoffalseif the predicate is true for any element.The materialized value
Futurewill be completed with the valuetrueorfalsewhen the input stream ends, or completed withFailureif there is a failure signaled in the stream.Adheres to the
ActorAttributes.SupervisionStrategyattribute.'''Completes when''' upstream completes or the predicate
preturnstrue'''Backpressures when''' the invocation of predicate
phas not yet completed'''Cancels when''' predicate
preturnstrue- Since:
- 1.2.0
-
exists
ASinkthat will test the given predicatepfor every received element and 1. completes and returnsFutureoftrueif the predicate is true for any element; 2. completes and returnsFutureoffalseif the stream is empty (i.e. completes before signalling any elements); 3. completes and returnsFutureoffalseif the predicate is false for all elements.The materialized value
Futurewill be completed with the valuetrueorfalsewhen the input stream ends, or completed withFailureif there is a failure signaled in the stream.Adheres to the
ActorAttributes.SupervisionStrategyattribute.'''Completes when''' upstream completes or the predicate
preturnstrue'''Backpressures when''' the invocation of predicate
phas not yet completed'''Cancels when''' predicate
preturnstrue- Since:
- 1.1.0
-
reduce
ASinkthat will invoke the given function for every received element, giving it its previous output (from the second element) and the element as input. The returnedFuturewill be completed with value of the final function evaluation when the input stream ends, or completed withFailureif 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.Adheres to the
ActorAttributes.SupervisionStrategyattribute. -
onComplete
public <T> Sink<T,NotUsed> onComplete(scala.Function1<scala.util.Try<Done>, scala.runtime.BoxedUnit> callback) ASinkthat when the flow is completed, either through a failure or normal completion, apply the provided function withSuccessorFailure. -
actorRef
public <T> Sink<T,NotUsed> actorRef(ActorRef ref, Object onCompleteMessage, scala.Function1<Throwable, Object> onFailureMessage) INTERNAL APISends the elements of the stream to the given
ActorRef. If the target actor terminates the stream will be canceled. When the stream is completed successfully the givenonCompleteMessagewill be sent to the destination actor. When the stream is completed with failure theonFailureMessagewill be invoked and its result will be sent to the destination actor.It will request at most
maxInputBufferSizenumber 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-timeor use a rate limiting operator in front of thisSink. -
actorRefWithBackpressure
public <T> Sink<T,NotUsed> actorRefWithBackpressure(ActorRef ref, Object onInitMessage, Object ackMessage, Object onCompleteMessage, scala.Function1<Throwable, Object> onFailureMessage) Sends the elements of the stream to the givenActorRefthat sends back back-pressure signal. First element is alwaysonInitMessage, then stream is waiting for acknowledgement messageackMessagefrom the given actor which means that it is ready to process elements. It also requiresackMessagemessage 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
onCompleteMessagewill be sent to the destination actor. When the stream is completed with failure - result ofonFailureMessage(throwable)function will be sent to the destination actor. -
actorRefWithBackpressure
public <T> Sink<T,NotUsed> actorRefWithBackpressure(ActorRef ref, Object onInitMessage, Object onCompleteMessage, scala.Function1<Throwable, Object> onFailureMessage) Sends the elements of the stream to the givenActorRefthat 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
onCompleteMessagewill be sent to the destination actor. When the stream is completed with failure - result ofonFailureMessage(throwable)function will be sent to the destination actor. -
queue
Creates aSinkthat is materialized as anpekko.stream.scaladsl.SinkQueueWithCancel.pekko.stream.scaladsl.SinkQueueWithCancel.pullmethod is pulling element from the stream and returnsFuture[Option[T].Futurecompletes when element is available.Before calling pull method second time you need to ensure that number of pending pulls is less then
maxConcurrentPullsor wait until some of the previous Futures completes. Pull returns Failed future with ''IllegalStateException'' if there will be more thenmaxConcurrentPullsnumber of pending pulls.Sinkwill request at most number of elements equal to size ofinputBufferfrom upstream and then stop back pressure. You can configure size of input buffer by usingSink.withAttributesmethod.For stream completion you need to pull all elements from
pekko.stream.scaladsl.SinkQueueWithCancelincluding last None as completion markerSee also
pekko.stream.scaladsl.SinkQueueWithCancel -
queue
Creates aSinkthat is materialized as anpekko.stream.scaladsl.SinkQueueWithCancel.pekko.stream.scaladsl.SinkQueueWithCancel.pullmethod is pulling element from the stream and returnsFuture[Option[T}.Futurecompletes when element is available.Before calling pull method second time you need to wait until previous Future completes. Pull returns Failed future with ''IllegalStateException'' if previous future has not yet completed.
Sinkwill request at most number of elements equal to size ofinputBufferfrom upstream and then stop back pressure. You can configure size of input buffer by usingSink.withAttributesmethod.For stream completion you need to pull all elements from
pekko.stream.scaladsl.SinkQueueWithCancelincluding last None as completion markerSee also
pekko.stream.scaladsl.SinkQueueWithCancel -
futureSink
public <T,M> Sink<T,scala.concurrent.Future<M>> futureSink(scala.concurrent.Future<Sink<T, M>> future) Turn aFuture[Sink]into a Sink that will consume the values of the source when the future completes successfully. If theFutureis 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
NeverMaterializedExceptionif upstream fails or downstream cancels before the future has completed. -
lazySink
Defers invoking thecreatefunction 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
createfunction throws or returns or the stream fails to materialize, in this case the materialized future value is failed with apekko.stream.NeverMaterializedException. -
lazyFutureSink
public <T,M> Sink<T,scala.concurrent.Future<M>> lazyFutureSink(scala.Function0<scala.concurrent.Future<Sink<T, M>>> create) Defers invoking thecreatefunction 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
createfunction 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.
-