Class Sink$
- java.lang.Object
-
- akka.stream.scaladsl.Sink$
-
public class Sink$ extends java.lang.ObjectINTERNAL API
-
-
Constructor Summary
Constructors Constructor Description Sink$()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <T> Sink<T,NotUsed>actorRef(ActorRef ref, java.lang.Object onCompleteMessage)Sends the elements of the stream to the givenActorRef.<T> Sink<T,NotUsed>actorRef(ActorRef ref, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)INTERNAL API<T> Sink<T,NotUsed>actorRefWithAck(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)Sends the elements of the stream to the givenActorRefthat sends back back-pressure signal.<T> Sink<T,NotUsed>actorRefWithAck(ActorRef ref, scala.Function1<ActorRef,scala.Function1<T,java.lang.Object>> messageAdapter, scala.Function1<ActorRef,java.lang.Object> onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)INTERNAL API<T> scala.Function1<java.lang.Throwable,java.lang.Object>actorRefWithAck$default$5()<T> Sink<T,ActorRef>actorSubscriber(Props props)Deprecated.Useakka.stream.stage.GraphStageandfromGraphinstead, it allows for all operations an Actor would and is more type-safe as well as guaranteed to be ReactiveStreams compliant.<T> Sink<T,org.reactivestreams.Publisher<T>>asPublisher(boolean fanout)ASinkthat materializes into aPublisher.<T> Sink<T,NotUsed>cancelled()ASinkthat immediately cancels its upstream after materialization.<T,That>
Sink<T,scala.concurrent.Future<That>>collection(scala.collection.generic.CanBuildFrom<scala.runtime.Nothing$,T,That> cbf)ASinkthat keeps on collecting incoming elements until upstream terminates.<T,U>
Sink<T,NotUsed>combine(Sink<U,?> first, Sink<U,?> second, scala.collection.Seq<Sink<U,?>> rest, scala.Function1<java.lang.Object,Graph<UniformFanOutShape<T,U>,NotUsed>> strategy)Combine several sinks with fan-out strategy likeBroadcastorBalanceand returnsSink.<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.<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.<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.<T> Sink<T,scala.concurrent.Future<Done>>foreachParallel(int parallelism, scala.Function1<T,scala.runtime.BoxedUnit> f, scala.concurrent.ExecutionContext ec)Deprecated.Use `foreachAsync` instead, it allows you to choose how to run the procedure, by calling some other API returning a Future or spawning a new Future.<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> Sink<T,NotUsed>fromSubscriber(org.reactivestreams.Subscriber<T> subscriber)Helper to createSinkfromSubscriber.<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>>>headOption()ASinkthat materializes into aFutureof the optional first value received.Sink<java.lang.Object,scala.concurrent.Future<Done>>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>>>lastOption()ASinkthat materializes into aFutureof the optional last value received.<T,M>
Sink<T,scala.concurrent.Future<M>>lazyInit(scala.Function1<T,scala.concurrent.Future<Sink<T,M>>> sinkFactory, scala.Function0<M> fallback)Deprecated.Use lazyInitAsync instead.<T,M>
Sink<T,scala.concurrent.Future<scala.Option<M>>>lazyInitAsync(scala.Function0<scala.concurrent.Future<Sink<T,M>>> sinkFactory)Creates a realSinkupon receiving the first element.<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.<T> Sink<T,SinkQueueWithCancel<T>>queue()Creates aSinkthat is materialized as anSinkQueue.<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,M>
Sink<T,scala.concurrent.Future<M>>setup(scala.Function2<ActorMaterializer,Attributes,Sink<T,M>> factory)Defers the creation of aSinkuntil materialization.<T> SinkShape<T>shape(java.lang.String name)<T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>>takeLast(int n)ASinkthat materializes into a aFutureofimmutable.Seq[T]containing the lastncollected elements.
-
-
-
Field Detail
-
MODULE$
public static final Sink$ MODULE$
Static reference to the singleton instance of this Scala object.
-
-
Method Detail
-
shape
public <T> SinkShape<T> shape(java.lang.String name)
-
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.- Parameters:
g- (undocumented)- Returns:
- (undocumented)
-
setup
public <T,M> Sink<T,scala.concurrent.Future<M>> setup(scala.Function2<ActorMaterializer,Attributes,Sink<T,M>> factory)
Defers the creation of aSinkuntil materialization. Thefactoryfunction exposesActorMaterializerwhich is going to be used during materialization andAttributesof theSinkreturned by this method.- Parameters:
factory- (undocumented)- Returns:
- (undocumented)
-
fromSubscriber
public <T> Sink<T,NotUsed> fromSubscriber(org.reactivestreams.Subscriber<T> subscriber)
Helper to createSinkfromSubscriber.- Parameters:
subscriber- (undocumented)- Returns:
- (undocumented)
-
cancelled
public <T> Sink<T,NotUsed> cancelled()
ASinkthat immediately cancels its upstream after materialization.- Returns:
- (undocumented)
-
head
public <T> Sink<T,scala.concurrent.Future<T>> 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().- Returns:
- (undocumented)
-
headOption
public <T> Sink<T,scala.concurrent.Future<scala.Option<T>>> 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().- Returns:
- (undocumented)
-
last
public <T> Sink<T,scala.concurrent.Future<T>> 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).- Returns:
- (undocumented)
-
lastOption
public <T> Sink<T,scala.concurrent.Future<scala.Option<T>>> 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).- Returns:
- (undocumented)
-
takeLast
public <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> takeLast(int n)
ASinkthat materializes into a 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.- Parameters:
n- (undocumented)- Returns:
- (undocumented)
-
seq
public <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> 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- Returns:
- (undocumented)
-
collection
public <T,That> Sink<T,scala.concurrent.Future<That>> collection(scala.collection.generic.CanBuildFrom<scala.runtime.Nothing$,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- Parameters:
cbf- (undocumented)- Returns:
- (undocumented)
-
asPublisher
public <T> Sink<T,org.reactivestreams.Publisher<T>> asPublisher(boolean fanout)
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.- Parameters:
fanout- (undocumented)- Returns:
- (undocumented)
-
ignore
public Sink<java.lang.Object,scala.concurrent.Future<Done>> ignore()
ASinkthat will consume the stream and discard the elements.- Returns:
- (undocumented)
-
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.- Parameters:
f- (undocumented)- Returns:
- (undocumented)
-
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.- Parameters:
parallelism- (undocumented)f- (undocumented)- Returns:
- (undocumented)
-
combine
public <T,U> Sink<T,NotUsed> combine(Sink<U,?> first, Sink<U,?> second, scala.collection.Seq<Sink<U,?>> rest, scala.Function1<java.lang.Object,Graph<UniformFanOutShape<T,U>,NotUsed>> strategy)
Combine several sinks with fan-out strategy likeBroadcastorBalanceand returnsSink.- Parameters:
first- (undocumented)second- (undocumented)rest- (undocumented)strategy- (undocumented)- Returns:
- (undocumented)
-
foreachParallel
public <T> Sink<T,scala.concurrent.Future<Done>> foreachParallel(int parallelism, scala.Function1<T,scala.runtime.BoxedUnit> f, scala.concurrent.ExecutionContext ec)
Deprecated.Use `foreachAsync` instead, it allows you to choose how to run the procedure, by calling some other API returning a Future or spawning a new Future. Since 2.5.17.ASinkthat will invoke the given function to each of the elements as they pass in. The sink is materialized into aFutureIf
fthrows an exception and the supervision decision isakka.stream.Supervision.StoptheFuturewill be completed with failure.If
fthrows an exception and the supervision decision isakka.stream.Supervision.Resumeorakka.stream.Supervision.Restartthe element is dropped and the stream continues.See also
Flow.mapAsyncUnordered- Parameters:
parallelism- (undocumented)f- (undocumented)ec- (undocumented)- Returns:
- (undocumented)
-
fold
public <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. 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.- Parameters:
zero- (undocumented)f- (undocumented)- Returns:
- (undocumented)
- See Also:
foldAsync(U, scala.Function2<U, T, scala.concurrent.Future<U>>)
-
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.- Parameters:
zero- (undocumented)f- (undocumented)- Returns:
- (undocumented)
- See Also:
fold(U, scala.Function2<U, T, U>)
-
reduce
public <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. 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.- Parameters:
f- (undocumented)- Returns:
- (undocumented)
-
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.- Parameters:
callback- (undocumented)- Returns:
- (undocumented)
-
actorRef
public <T> Sink<T,NotUsed> actorRef(ActorRef ref, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.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.- Parameters:
ref- (undocumented)onCompleteMessage- (undocumented)onFailureMessage- (undocumented)- Returns:
- (undocumented)
-
actorRef
public <T> Sink<T,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 givenonCompleteMessagewill be sent to the destination actor. When the stream is completed with failure aStatus.Failuremessage 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.- Parameters:
ref- (undocumented)onCompleteMessage- (undocumented)- Returns:
- (undocumented)
-
actorRefWithAck
public <T> Sink<T,NotUsed> actorRefWithAck(ActorRef ref, scala.Function1<ActorRef,scala.Function1<T,java.lang.Object>> messageAdapter, scala.Function1<ActorRef,java.lang.Object> onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
INTERNAL APISends the elements of the stream to the given
ActorRefthat sends back back-pressure signal. First element is created by callingonInitMessagewith anActorRefof the actor that expects acknowledgements. 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.Every message that is sent to the actor is first transformed using
messageAdapter. This can be used to capture the ActorRef of the actor that expects acknowledgments as well as transforming messages from the stream to the ones that actor underrefhandles.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.- Parameters:
ref- (undocumented)messageAdapter- (undocumented)onInitMessage- (undocumented)ackMessage- (undocumented)onCompleteMessage- (undocumented)onFailureMessage- (undocumented)- Returns:
- (undocumented)
-
actorRefWithAck
public <T> Sink<T,NotUsed> actorRefWithAck(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.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.- Parameters:
ref- (undocumented)onInitMessage- (undocumented)ackMessage- (undocumented)onCompleteMessage- (undocumented)onFailureMessage- (undocumented)- Returns:
- (undocumented)
-
actorRefWithAck$default$5
public <T> scala.Function1<java.lang.Throwable,java.lang.Object> actorRefWithAck$default$5()
-
actorSubscriber
public <T> Sink<T,ActorRef> actorSubscriber(Props props)
Deprecated.Useakka.stream.stage.GraphStageandfromGraphinstead, it allows for all operations an Actor would and is more type-safe as well as guaranteed to be ReactiveStreams compliant.Creates aSinkthat is materialized to anActorRefwhich points to an Actor created according to the passed inProps. Actor created by thepropsmust beActorSubscriber.- Parameters:
props- (undocumented)- Returns:
- (undocumented)
-
queue
public <T> Sink<T,SinkQueueWithCancel<T>> queue()
Creates aSinkthat is materialized as anSinkQueue.akka.stream.scaladsl.SinkQueue.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
SinkQueueincluding last None as completion markerSee also
SinkQueueWithCancel- Returns:
- (undocumented)
-
lazyInit
public <T,M> Sink<T,scala.concurrent.Future<M>> lazyInit(scala.Function1<T,scala.concurrent.Future<Sink<T,M>>> sinkFactory, scala.Function0<M> fallback)
Deprecated.Use lazyInitAsync instead. (lazyInitAsync no more needs a fallback function and the materialized value more clearly indicates if the internal sink was materialized or not.). Since 2.5.11.Creates a realSinkupon receiving the first element. InternalSinkwill not be created if there are no elements, because of completion or error.If upstream completes before an element was received then the
Futureis completed with the value created by fallback. If upstream fails before an element was received,sinkFactorythrows an exception, or materialization of the internal sink fails then theFutureis completed with the exception. Otherwise theFutureis completed with the materialized value of the internal sink.- Parameters:
sinkFactory- (undocumented)fallback- (undocumented)- Returns:
- (undocumented)
-
lazyInitAsync
public <T,M> Sink<T,scala.concurrent.Future<scala.Option<M>>> lazyInitAsync(scala.Function0<scala.concurrent.Future<Sink<T,M>>> sinkFactory)
Creates a realSinkupon receiving the first element. InternalSinkwill not be created if there are no elements, because of completion or error.If upstream completes before an element was received then the
Futureis completed withNone. If upstream fails before an element was received,sinkFactorythrows an exception, or materialization of the internal sink fails then theFutureis completed with the exception. Otherwise theFutureis completed with the materialized value of the internal sink.- Parameters:
sinkFactory- (undocumented)- Returns:
- (undocumented)
-
-