Class Sink<In,​Mat>

  • All Implemented Interfaces:
    Graph<SinkShape<In>,​Mat>

    public final class Sink<In,​Mat>
    extends java.lang.Object
    implements Graph<SinkShape<In>,​Mat>
    Java API

    A Sink is a set of stream processing steps that has one open input. Can be used as a Subscriber

    • Constructor Summary

      Constructors 
      Constructor Description
      Sink​(Sink<In,​Mat> delegate)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      static <In> Sink<In,​NotUsed> actorRef​(ActorRef ref, java.lang.Object onCompleteMessage)
      Sends the elements of the stream to the given ActorRef.
      static <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
      static <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 given ActorRef that sends back back-pressure signal.
      static <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 given ActorRef that sends back back-pressure signal.
      Sink<In,​Mat> addAttributes​(Attributes attr)
      Add the given attributes to this Sink.
      static <T> Sink<T,​org.reactivestreams.Publisher<T>> asPublisher​(AsPublisher fanout)
      A Sink that materializes into a Publisher.
      Sink<In,​Mat> asScala()
      Converts this Sink to its Scala DSL counterpart.
      Sink<In,​Mat> async()
      Put an asynchronous boundary around this Sink
      Sink<In,​Mat> async​(java.lang.String dispatcher)
      Put an asynchronous boundary around this Sink
      Sink<In,​Mat> async​(java.lang.String dispatcher, int inputBufferSize)
      Put an asynchronous boundary around this Sink
      static <T> Sink<T,​NotUsed> cancelled()
      A Sink that immediately cancels its upstream after materialization.
      static <U,​In>
      Sink<In,​java.util.concurrent.CompletionStage<U>>
      collect​(java.util.stream.Collector<In,​?,​U> collector)
      Creates a sink which materializes into a CompletionStage which will be completed with a result of the Java Collector transformation and reduction operations.
      static <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 like Broadcast or Balance and returns Sink.
      static <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 like Broadcast or Balance and returns Sink.
      static <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 like Broadcast or Balance and returns Sink with 2 outlets.
      static <T,​M>
      Sink<T,​java.util.concurrent.CompletionStage<M>>
      completionStageSink​(java.util.concurrent.CompletionStage<Sink<T,​M>> future)
      Turn a Future[Sink] into a Sink that will consume the values of the source when the future completes successfully.
      <In2> Sink<In2,​Mat> contramap​(Function<In2,​In> f)
      Transform this Sink by applying a function to each *incoming* upstream element before it is passed to the Sink
      static <U,​In>
      Sink<In,​java.util.concurrent.CompletionStage<U>>
      fold​(U zero, Function2<U,​In,​U> f)
      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.
      static <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.
      static <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> foreach​(Procedure<T> f)
      A Sink that will invoke the given procedure for each received element.
      static <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.
      static <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.
      static <T,​M>
      Sink<T,​java.util.concurrent.CompletionStage<M>>
      fromMaterializer​(java.util.function.BiFunction<Materializer,​Attributes,​Sink<T,​M>> factory)
      Defers the creation of a Sink until materialization.
      static <In> Sink<In,​NotUsed> fromSubscriber​(org.reactivestreams.Subscriber<In> subs)
      Helper to create Sink from Subscriber.
      Attributes getAttributes()  
      static <In> Sink<In,​java.util.concurrent.CompletionStage<In>> head()
      A Sink that materializes into a CompletionStage of the first value received.
      static <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.
      static <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> ignore()
      A Sink that will consume the stream and discard the elements.
      static <In> Sink<In,​java.util.concurrent.CompletionStage<In>> last()
      A Sink that materializes into a CompletionStage of the last value received.
      static <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.
      static <T,​M>
      Sink<T,​java.util.concurrent.CompletionStage<M>>
      lazyCompletionStageSink​(Creator<java.util.concurrent.CompletionStage<Sink<T,​M>>> create)
      Defers invoking the create function to create a future sink until there is a first element passed from upstream.
      static <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.
      static <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.
      static <T,​M>
      Sink<T,​java.util.concurrent.CompletionStage<M>>
      lazySink​(Creator<Sink<T,​M>> create)
      Defers invoking the create function to create a sink until there is a first element passed from upstream.
      <Mat2> Sink<In,​Mat2> mapMaterializedValue​(Function<Mat,​Mat2> f)
      Transform only the materialized value of this Sink, leaving all other properties as they were.
      Sink<In,​Mat> named​(java.lang.String name)
      Add a name attribute to this Sink.
      static <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> never()
      A Sink that will always backpressure never cancel and never consume any elements from the stream.
      static <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.
      Pair<Mat,​Sink<In,​NotUsed>> preMaterialize​(ClassicActorSystemProvider systemProvider)
      Materializes this Sink, immediately returning (1) its materialized value, and (2) a new Sink that can be consume elements 'into' the pre-materialized one.
      Pair<Mat,​Sink<In,​NotUsed>> preMaterialize​(Materializer materializer)
      Materializes this Sink, immediately returning (1) its materialized value, and (2) a new Sink that can be consume elements 'into' the pre-materialized one.
      static <T> Sink<T,​SinkQueueWithCancel<T>> queue()
      Creates a Sink that is materialized as an SinkQueueWithCancel.
      static <T> Sink<T,​SinkQueueWithCancel<T>> queue​(int maxConcurrentPulls)
      Creates a Sink that is materialized as an SinkQueueWithCancel.
      static <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.
      <M> M runWith​(Graph<SourceShape<In>,​M> source, ClassicActorSystemProvider systemProvider)
      Connect this Sink to a Source and run it.
      <M> M runWith​(Graph<SourceShape<In>,​M> source, Materializer materializer)
      Connect this Sink to a Source and run it.
      static <In> Sink<In,​java.util.concurrent.CompletionStage<java.util.List<In>>> seq()
      A Sink that keeps on collecting incoming elements until upstream terminates.
      static <T,​M>
      Sink<T,​java.util.concurrent.CompletionStage<M>>
      setup​(java.util.function.BiFunction<ActorMaterializer,​Attributes,​Sink<T,​M>> factory)
      Deprecated.
      Use 'fromMaterializer' instead.
      SinkShape<In> shape()
      The shape of a graph is all that is externally visible: its inlets and outlets.
      static <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.
      java.lang.String toString()  
      akka.stream.impl.LinearTraversalBuilder traversalBuilder()
      INTERNAL API.
      Sink<In,​Mat> withAttributes​(Attributes attr)
      Replace the attributes of this Sink with the given ones.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • Sink

        public Sink​(Sink<In,​Mat> delegate)
    • Method Detail

      • fold

        public static <U,​In> Sink<In,​java.util.concurrent.CompletionStage<U>> fold​(U zero,
                                                                                               Function2<U,​In,​U> f)
        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.
      • foldAsync

        public static <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.
      • collect

        public static <U,​In> Sink<In,​java.util.concurrent.CompletionStage<U>> collect​(java.util.stream.Collector<In,​?,​U> collector)
        Creates a sink which materializes into a CompletionStage 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 static <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.

      • fromSubscriber

        public static <In> Sink<In,​NotUsed> fromSubscriber​(org.reactivestreams.Subscriber<In> subs)
        Helper to create Sink from Subscriber.
      • cancelled

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

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

        public static <T> Sink<T,​java.util.concurrent.CompletionStage<Done>> never()
        A Sink that will always backpressure never cancel and never consume any elements from the stream.
      • asPublisher

        public static <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.

      • foreach

        public static <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.
      • foreachAsync

        public static <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.
      • onComplete

        public static <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.
      • head

        public static <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().

      • headOption

        public static <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().

      • last

        public static <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).

      • lastOption

        public static <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).

      • takeLast

        public static <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.

      • seq

        public static <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

      • actorRef

        public static <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.

      • actorRefWithBackpressure

        public static <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 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.

      • actorRefWithBackpressure

        public static <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 given ActorRef that sends back back-pressure signal. First element is always onInitMessage, 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 of onFailureMessage(throwable) message will be sent to the destination actor.

      • actorRefWithAck

        public static <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
        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.

      • fromGraph

        public static <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 static <T,​M> Sink<T,​java.util.concurrent.CompletionStage<M>> fromMaterializer​(java.util.function.BiFunction<Materializer,​Attributes,​Sink<T,​M>> factory)
        Defers the creation of a Sink until materialization. The factory function exposes Materializer which is going to be used during materialization and Attributes of the Sink returned by this method.
      • setup

        public static <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.
        Defers the creation of a Sink until materialization. The factory function exposes ActorMaterializer which is going to be used during materialization and Attributes of the Sink returned by this method.
      • combine

        public static <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 like Broadcast or Balance and returns Sink.
      • combineMat

        public static <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 like Broadcast or Balance and returns Sink with 2 outlets.
      • combine

        public static <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 like Broadcast or Balance and returns Sink. The fanoutGraph's outlets size must match the provides sinks'.
      • queue

        public static <T> Sink<T,​SinkQueueWithCancel<T>> queue​(int maxConcurrentPulls)
        Creates a Sink that is materialized as an SinkQueueWithCancel. akka.stream.javadsl.SinkQueueWithCancel.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 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 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 SinkQueueWithCancel including last None as completion marker

        See Also:
        SinkQueueWithCancel
      • queue

        public static <T> Sink<T,​SinkQueueWithCancel<T>> queue()
        Creates a Sink that is materialized as an SinkQueueWithCancel. akka.stream.javadsl.SinkQueueWithCancel.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 SinkQueueWithCancel including last None as completion marker

        See Also:
        SinkQueueWithCancel
      • lazyInit

        public static <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 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.

      • lazyInitAsync

        public static <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 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.

      • completionStageSink

        public static <T,​M> Sink<T,​java.util.concurrent.CompletionStage<M>> completionStageSink​(java.util.concurrent.CompletionStage<Sink<T,​M>> future)
        Turn a Future[Sink] into a Sink that will consume the values of the source when the future completes successfully. If the Future 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 static <T,​M> Sink<T,​java.util.concurrent.CompletionStage<M>> lazySink​(Creator<Sink<T,​M>> create)
        Defers invoking the create 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 a NeverMaterializedException.

      • lazyCompletionStageSink

        public static <T,​M> Sink<T,​java.util.concurrent.CompletionStage<M>> lazyCompletionStageSink​(Creator<java.util.concurrent.CompletionStage<Sink<T,​M>>> create)
        Defers invoking the create 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 a NeverMaterializedException.

      • shape

        public SinkShape<In> shape()
        Description copied from interface: Graph
        The shape of a graph is all that is externally visible: its inlets and outlets.
        Specified by:
        shape in interface Graph<In,​Mat>
      • traversalBuilder

        public akka.stream.impl.LinearTraversalBuilder traversalBuilder()
        Description copied from interface: Graph
        INTERNAL API.

        Every materializable element must be backed by a stream layout module

        Specified by:
        traversalBuilder in interface Graph<In,​Mat>
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • asScala

        public Sink<In,​Mat> asScala()
        Converts this Sink to its Scala DSL counterpart.
      • runWith

        public <M> M runWith​(Graph<SourceShape<In>,​M> source,
                             ClassicActorSystemProvider systemProvider)
        Connect this Sink to a Source and run it.

        Note that the ActorSystem can be used as the systemProvider parameter.

      • contramap

        public <In2> Sink<In2,​Mat> contramap​(Function<In2,​In> f)
        Transform this Sink by applying a function to each *incoming* upstream element before it is passed to the Sink

        '''Backpressures when''' original Sink backpressures

        '''Cancels when''' original Sink backpressures

      • mapMaterializedValue

        public <Mat2> Sink<In,​Mat2> mapMaterializedValue​(Function<Mat,​Mat2> f)
        Transform only the materialized value of this Sink, leaving all other properties as they were.
      • preMaterialize

        public Pair<Mat,​Sink<In,​NotUsed>> preMaterialize​(ClassicActorSystemProvider systemProvider)
        Materializes this Sink, immediately returning (1) its materialized value, and (2) a new Sink that can be consume elements 'into' the pre-materialized one.

        Useful for when you need a materialized value of a Sink when handing it out to someone to materialize it for you.

        Note that the ActorSystem can be used as the systemProvider parameter.

        Note that preMaterialize is implemented through a reactive streams Subscriber which means that a buffer is introduced and that errors are not propagated upstream but are turned into cancellations without error details.

      • preMaterialize

        public Pair<Mat,​Sink<In,​NotUsed>> preMaterialize​(Materializer materializer)
        Materializes this Sink, immediately returning (1) its materialized value, and (2) a new Sink that can be consume elements 'into' the pre-materialized one.

        Useful for when you need a materialized value of a Sink when handing it out to someone to materialize it for you.

        Prefer the method taking an ActorSystem unless you have special requirements.

      • withAttributes

        public Sink<In,​Mat> withAttributes​(Attributes attr)
        Replace the attributes of this Sink with the given ones. If this Sink is a composite of multiple graphs, new attributes on the composite will be less specific than attributes set directly on the individual graphs of the composite.
        Specified by:
        withAttributes in interface Graph<In,​Mat>
      • addAttributes

        public Sink<In,​Mat> addAttributes​(Attributes attr)
        Add the given attributes to this Sink. If the specific attribute was already present on this graph this means the added attribute will be more specific than the existing one. If this Sink is a composite of multiple graphs, new attributes on the composite will be less specific than attributes set directly on the individual graphs of the composite.
        Specified by:
        addAttributes in interface Graph<In,​Mat>
      • named

        public Sink<In,​Mat> named​(java.lang.String name)
        Add a name attribute to this Sink.
        Specified by:
        named in interface Graph<In,​Mat>
      • async

        public Sink<In,​Mat> async()
        Put an asynchronous boundary around this Sink
        Specified by:
        async in interface Graph<In,​Mat>
      • async

        public Sink<In,​Mat> async​(java.lang.String dispatcher)
        Put an asynchronous boundary around this Sink

        Specified by:
        async in interface Graph<In,​Mat>
        Parameters:
        dispatcher - Run the graph on this dispatcher
      • async

        public Sink<In,​Mat> async​(java.lang.String dispatcher,
                                        int inputBufferSize)
        Put an asynchronous boundary around this Sink

        Specified by:
        async in interface Graph<In,​Mat>
        Parameters:
        dispatcher - Run the graph on this dispatcher
        inputBufferSize - Set the input buffer to this size for the graph