Class Sink$


  • public class Sink$
    extends java.lang.Object
    A Sink that will invoke the given function for every received element, giving it its previous output (or the given zero value) and the element as input. The returned CompletionStage will be completed with value of the final function evaluation when the input stream ends, or completed with Failure if there is a failure is signaled in the stream.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static Sink$ MODULE$
      Static reference to the singleton instance of this Scala object.
    • 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 given ActorRef.
      <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)
      Sends the elements of the stream to the given ActorRef that sends back back-pressure signal.
      <T> Sink<T,​ActorRef> actorSubscriber​(Props props)
      Deprecated.
      Use akka.stream.stage.GraphStage and fromGraph instead, 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​(AsPublisher fanout)
      A Sink that materializes into a Publisher.
      <T> Sink<T,​NotUsed> cancelled()
      A Sink that immediately cancels its upstream after materialization.
      <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>> strategy)
      Combine several sinks with fan-out strategy like Broadcast or Balance and returns Sink.
      <U,​In>
      Sink<In,​java.util.concurrent.CompletionStage<U>>
      fold​(U zero, Function2<U,​In,​U> f)  
      <U,​In>
      Sink<In,​java.util.concurrent.CompletionStage<U>>
      foldAsync​(U zero, Function2<U,​In,​java.util.concurrent.CompletionStage<U>> f)
      A Sink that will invoke the given asynchronous function for every received element, giving it its previous output (or the given zero value) and the element as input.
      <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> foreach​(Procedure<T> f)
      A Sink 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)
      A Sink that will invoke the given procedure asynchronously for each received element.
      <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> foreachParallel​(int parallel, Procedure<T> 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 CompletionStage or using CompletableFuture.supplyAsync.
      <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.
      <In> Sink<In,​NotUsed> fromSubscriber​(org.reactivestreams.Subscriber<In> subs)
      Helper to create Sink from Subscriber.
      <In> Sink<In,​java.util.concurrent.CompletionStage<In>> head()
      A Sink that materializes into a CompletionStage of the first value received.
      <In> Sink<In,​java.util.concurrent.CompletionStage<java.util.Optional<In>>> headOption()
      A Sink that materializes into a CompletionStage of the optional first value received.
      <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> ignore()
      A Sink that will consume the stream and discard the elements.
      <In> Sink<In,​java.util.concurrent.CompletionStage<In>> last()
      A Sink that materializes into a CompletionStage of the last value received.
      <In> Sink<In,​java.util.concurrent.CompletionStage<java.util.Optional<In>>> lastOption()
      A Sink that materializes into a CompletionStage of the optional last value received.
      <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 lazyInitAsync instead.
      <T,​M>
      Sink<T,​java.util.concurrent.CompletionStage<java.util.Optional<M>>>
      lazyInitAsync​(Creator<java.util.concurrent.CompletionStage<Sink<T,​M>>> sinkFactory)
      Creates a real Sink upon receiving the first element.
      <In> Sink<In,​NotUsed> onComplete​(Procedure<scala.util.Try<Done>> callback)
      A Sink that when the flow is completed, either through a failure or normal completion, apply the provided function with Success or Failure.
      <T> Sink<T,​SinkQueueWithCancel<T>> queue()
      Creates a Sink that is materialized as an SinkQueue.
      <In> Sink<In,​java.util.concurrent.CompletionStage<In>> reduce​(Function2<In,​In,​In> f)
      A Sink 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()
      A Sink that keeps on collecting incoming elements until upstream terminates.
      <In> Sink<In,​java.util.concurrent.CompletionStage<java.util.List<In>>> takeLast​(int n)
      A Sink that materializes into a a CompletionStage of List containing the last n collected elements.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • MODULE$

        public static final Sink$ MODULE$
        Static reference to the singleton instance of this Scala object.
    • Constructor Detail

      • Sink$

        public Sink$()
    • Method Detail

      • fold

        public <U,​In> Sink<In,​java.util.concurrent.CompletionStage<U>> fold​(U zero,
                                                                                        Function2<U,​In,​U> f)
      • foldAsync

        public <U,​In> Sink<In,​java.util.concurrent.CompletionStage<U>> foldAsync​(U zero,
                                                                                             Function2<U,​In,​java.util.concurrent.CompletionStage<U>> f)
        A Sink that will invoke the given asynchronous function for every received element, giving it its previous output (or the given zero value) and the element as input. The returned CompletionStage will be completed with value of the final function evaluation when the input stream ends, or completed with Failure if there is a failure is signaled in the stream.
        Parameters:
        zero - (undocumented)
        f - (undocumented)
        Returns:
        (undocumented)
      • reduce

        public <In> Sink<In,​java.util.concurrent.CompletionStage<In>> reduce​(Function2<In,​In,​In> f)
        A Sink 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 returned CompletionStage will be completed with value of the final function evaluation when the input stream ends, or completed with Failure 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.

        Parameters:
        f - (undocumented)
        Returns:
        (undocumented)
      • fromSubscriber

        public <In> Sink<In,​NotUsed> fromSubscriber​(org.reactivestreams.Subscriber<In> subs)
        Helper to create Sink from Subscriber.
        Parameters:
        subs - (undocumented)
        Returns:
        (undocumented)
      • cancelled

        public <T> Sink<T,​NotUsed> cancelled()
        A Sink that immediately cancels its upstream after materialization.
        Returns:
        (undocumented)
      • ignore

        public <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> ignore()
        A Sink that will consume the stream and discard the elements.
        Returns:
        (undocumented)
      • asPublisher

        public <T> Sink<T,​org.reactivestreams.Publisher<T>> asPublisher​(AsPublisher fanout)
        A Sink that materializes into a Publisher.

        If fanout is true, the materialized Publisher will support multiple Subscribers and the size of the inputBuffer configured for this operator becomes the maximum number of elements that the fastest Subscriber can be ahead of the slowest one before slowing the processing down due to back pressure.

        If fanout is false then the materialized Publisher will only support a single Subscriber and reject any additional Subscribers.

        Parameters:
        fanout - (undocumented)
        Returns:
        (undocumented)
      • foreach

        public <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> foreach​(Procedure<T> f)
        A Sink that will invoke the given procedure for each received element. The sink is materialized into a CompletionStage which will be completed with Success when reaching the normal end of the stream, or completed with Failure if there is a failure signaled in the stream.
        Parameters:
        f - (undocumented)
        Returns:
        (undocumented)
      • foreachAsync

        public <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> foreachAsync​(int parallelism,
                                                                                         Function<T,​java.util.concurrent.CompletionStage<java.lang.Void>> f)
        A Sink that will invoke the given procedure asynchronously for each received element. The sink is materialized into a CompletionStage which will be completed with Success when reaching the normal end of the stream, or completed with Failure if there is a failure signaled in the stream.
        Parameters:
        parallelism - (undocumented)
        f - (undocumented)
        Returns:
        (undocumented)
      • foreachParallel

        public <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> foreachParallel​(int parallel,
                                                                                            Procedure<T> 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 CompletionStage or using CompletableFuture.supplyAsync. Since 2.5.17.
        A Sink that will invoke the given procedure for each received element in parallel. The sink is materialized into a CompletionStage.

        If f throws an exception and the supervision decision is akka.stream.Supervision.Stop the CompletionStage will be completed with failure.

        If f throws an exception and the supervision decision is akka.stream.Supervision.Resume or akka.stream.Supervision.Restart the element is dropped and the stream continues.

        Parameters:
        parallel - (undocumented)
        f - (undocumented)
        ec - (undocumented)
        Returns:
        (undocumented)
      • onComplete

        public <In> Sink<In,​NotUsed> onComplete​(Procedure<scala.util.Try<Done>> callback)
        A Sink that when the flow is completed, either through a failure or normal completion, apply the provided function with Success or Failure.
        Parameters:
        callback - (undocumented)
        Returns:
        (undocumented)
      • head

        public <In> Sink<In,​java.util.concurrent.CompletionStage<In>> head()
        A Sink that materializes into a CompletionStage of the first value received. If the stream completes before signaling at least a single element, the CompletionStage will be failed with a NoSuchElementException. 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().

        Returns:
        (undocumented)
      • headOption

        public <In> Sink<In,​java.util.concurrent.CompletionStage<java.util.Optional<In>>> headOption()
        A Sink that materializes into a CompletionStage 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 empty Optional. 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().

        Returns:
        (undocumented)
      • last

        public <In> Sink<In,​java.util.concurrent.CompletionStage<In>> last()
        A Sink that materializes into a CompletionStage of the last value received. If the stream completes before signaling at least a single element, the CompletionStage will be failed with a NoSuchElementException. 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).

        Returns:
        (undocumented)
      • lastOption

        public <In> Sink<In,​java.util.concurrent.CompletionStage<java.util.Optional<In>>> lastOption()
        A Sink that materializes into a CompletionStage 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 empty Optional. 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).

        Returns:
        (undocumented)
      • takeLast

        public <In> Sink<In,​java.util.concurrent.CompletionStage<java.util.List<In>>> takeLast​(int n)
        A Sink that materializes into a a CompletionStage of List containing the last n 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 the CompletionStage will never complete. If there is a failure signaled in the stream the CompletionStage will be completed with failure.

        Parameters:
        n - (undocumented)
        Returns:
        (undocumented)
      • seq

        public <In> Sink<In,​java.util.concurrent.CompletionStage<java.util.List<In>>> seq()
        A Sink that keeps on collecting incoming elements until upstream terminates. As upstream may be unbounded, Flow[T].take or the stricter Flow[T].limit (and their variants) may be used to ensure boundedness. Materializes into a CompletionStage of Seq[T] containing all the collected elements. List is limited to Integer.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

        Returns:
        (undocumented)
      • actorRef

        public <In> Sink<In,​NotUsed> actorRef​(ActorRef ref,
                                                    java.lang.Object onCompleteMessage)
        Sends 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 given onCompleteMessage will be sent to the destination actor. When the stream is completed with failure a 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 zero mailbox-push-timeout-time or use a rate limiting operator in front of this Sink.

        Parameters:
        ref - (undocumented)
        onCompleteMessage - (undocumented)
        Returns:
        (undocumented)
      • 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)
        Sends the elements of the stream to the given ActorRef that sends back back-pressure signal. First element is always onInitMessage, then stream is waiting for acknowledgement message ackMessage from the given actor which means that it is ready to process elements. It also requires ackMessage 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 of onFailureMessage(throwable) message will be sent to the destination actor.

        Parameters:
        ref - (undocumented)
        onInitMessage - (undocumented)
        ackMessage - (undocumented)
        onCompleteMessage - (undocumented)
        onFailureMessage - (undocumented)
        Returns:
        (undocumented)
      • actorSubscriber

        public <T> Sink<T,​ActorRef> actorSubscriber​(Props props)
        Deprecated.
        Use akka.stream.stage.GraphStage and fromGraph instead, it allows for all operations an Actor would and is more type-safe as well as guaranteed to be ReactiveStreams compliant.
        Creates a Sink that is materialized to an ActorRef which points to an Actor created according to the passed in Props. Actor created by the props should be ActorSubscriber.

        Parameters:
        props - (undocumented)
        Returns:
        (undocumented)
      • 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)
      • 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>> strategy)
        Combine several sinks with fan-out strategy like Broadcast or Balance and returns Sink.
        Parameters:
        output1 - (undocumented)
        output2 - (undocumented)
        rest - (undocumented)
        strategy - (undocumented)
        Returns:
        (undocumented)
      • queue

        public <T> Sink<T,​SinkQueueWithCancel<T>> queue()
        Creates a Sink that is materialized as an SinkQueue. akka.stream.javadsl.SinkQueue.pull method is pulling element from the stream and returns CompletionStage[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 of inputBuffer from upstream and then stop back pressure. You can configure size of input buffer by using Sink.withAttributes method.

        For stream completion you need to pull all elements from SinkQueue including last None as completion marker

        Returns:
        (undocumented)
        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 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 real Sink upon receiving the first element. Internal Sink 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 the Future is completed with the exception. Otherwise the Future is completed with the materialized value of the internal sink.

        Parameters:
        sinkFactory - (undocumented)
        fallback - (undocumented)
        Returns:
        (undocumented)
      • lazyInitAsync

        public <T,​M> Sink<T,​java.util.concurrent.CompletionStage<java.util.Optional<M>>> lazyInitAsync​(Creator<java.util.concurrent.CompletionStage<Sink<T,​M>>> sinkFactory)
        Creates a real Sink upon receiving the first element. Internal Sink 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 None. If upstream fails before an element was received, sinkFactory throws an exception, or materialization of the internal sink fails then the Future is completed with the exception. Otherwise the Future is completed with the materialized value of the internal sink.

        Parameters:
        sinkFactory - (undocumented)
        Returns:
        (undocumented)