Class Sink<In,Mat>

java.lang.Object
org.apache.pekko.stream.scaladsl.Sink<In,Mat>
All Implemented Interfaces:
Graph<SinkShape<In>,Mat>

public final class Sink<In,Mat> extends Object implements Graph<SinkShape<In>,Mat>
A Sink is a set of stream processing steps that has one open input. Can be used as a Subscriber
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.apache.pekko.stream.Graph

    Graph.GraphMapMatVal<S extends Shape,M>
  • Constructor Summary

    Constructors
    Constructor
    Description
    Sink(org.apache.pekko.stream.impl.LinearTraversalBuilder traversalBuilder, SinkShape<In> shape)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Sink<T,NotUsed>
    actorRef(ActorRef ref, Object onCompleteMessage, scala.Function1<Throwable,Object> onFailureMessage)
    INTERNAL API
    static <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 given ActorRef that sends back back-pressure signal.
    static <T> Sink<T,NotUsed>
    actorRefWithBackpressure(ActorRef ref, Object onInitMessage, Object onCompleteMessage, scala.Function1<Throwable,Object> onFailureMessage)
    Sends the elements of the stream to the given ActorRef that sends back back-pressure signal.
    Add the given attributes to this Sink.
    <JIn extends In>
    Sink<JIn,Mat>
    Converts this Scala DSL element to it's Java DSL counterpart.
    static <T> Sink<T,org.reactivestreams.Publisher<T>>
    asPublisher(boolean fanout)
    A Sink that materializes into a Publisher.
    Put an asynchronous boundary around this Source
    async(String dispatcher)
    Put an asynchronous boundary around this Graph
    async(String dispatcher, int inputBufferSize)
    Put an asynchronous boundary around this Graph
    static <T> Sink<T,NotUsed>
    A Sink that immediately cancels its upstream after materialization.
    static <T, That> Sink<T,scala.concurrent.Future<That>>
    collection(scala.collection.Factory<T,That> cbf)
    A Sink that keeps on collecting incoming elements until upstream terminates.
    static <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 like Broadcast or Balance and returns Sink.
    static <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 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, scala.Function1<Object,Graph<UniformFanOutShape<T,U>,NotUsed>> fanOutStrategy, scala.Function2<M1,M2,M> matF)
    Combine two sinks with fan-out strategy like Broadcast or Balance and returns Sink with 2 outlets.
    <In2> Sink<In2,Mat>
    contramap(scala.Function1<In2,In> f)
    Transform this Sink by applying a function to each *incoming* upstream element before it is passed to the Sink
    static <T> Sink<T,scala.concurrent.Future<Object>>
    A Sink that counts all incoming elements until upstream terminates.
    static <T> Sink<T,scala.concurrent.Future<Object>>
    exists(scala.Function1<T,Object> p)
    A Sink that will test the given predicate p for every received element and 1.
    static <U, T> Sink<T,scala.concurrent.Future<U>>
    fold(U zero, scala.Function2<U,T,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, T> Sink<T,scala.concurrent.Future<U>>
    foldAsync(U zero, scala.Function2<U,T,scala.concurrent.Future<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 <U, T> Sink<T,scala.concurrent.Future<U>>
    foldWhile(U zero, scala.Function1<U,Object> p, scala.Function2<U,T,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 <T> Sink<T,scala.concurrent.Future<Object>>
    forall(scala.Function1<T,Object> p)
    A Sink that will test the given predicate p for every received element and 1.
    static <T> Sink<T,scala.concurrent.Future<Done>>
    foreach(scala.Function1<T,scala.runtime.BoxedUnit> f)
    A Sink that will invoke the given procedure for each received element.
    static <T> Sink<T,scala.concurrent.Future<Done>>
    foreachAsync(int parallelism, scala.Function1<T,scala.concurrent.Future<scala.runtime.BoxedUnit>> f)
    A Sink that will invoke the given procedure asynchronously for each received element.
    static <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.
    static <T, M> Sink<T,scala.concurrent.Future<M>>
    fromMaterializer(scala.Function2<Materializer,Attributes,Sink<T,M>> factory)
    Defers the creation of a Sink until materialization.
    static <T> Sink<T,NotUsed>
    fromSubscriber(org.reactivestreams.Subscriber<T> subscriber)
    Helper to create Sink from Subscriber.
    static <T, M> Sink<T,scala.concurrent.Future<M>>
    futureSink(scala.concurrent.Future<Sink<T,M>> future)
    Turn a Future[Sink] into a Sink that will consume the values of the source when the future completes successfully.
     
    static <T> Sink<T,scala.concurrent.Future<T>>
    A Sink that materializes into a Future of the first value received.
    static <T> Sink<T,scala.concurrent.Future<scala.Option<T>>>
    A Sink that materializes into a Future of the optional first value received.
    static Sink<Object,scala.concurrent.Future<Done>>
    A Sink that will consume the stream and discard the elements.
    static <T> Sink<T,scala.concurrent.Future<T>>
    A Sink that materializes into a Future of the last value received.
    static <T> Sink<T,scala.concurrent.Future<scala.Option<T>>>
    A Sink that materializes into a Future of the optional last value received.
    static <T, M> Sink<T,scala.concurrent.Future<M>>
    lazyFutureSink(scala.Function0<scala.concurrent.Future<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,scala.concurrent.Future<M>>
    lazySink(scala.Function0<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(scala.Function1<Mat,Mat2> f)
    Transform only the materialized value of this Sink, leaving all other properties as they were.
    named(String name)
    Add a name attribute to this Sink.
    static Sink<Object,scala.concurrent.Future<Done>>
    A Sink that will always backpressure never cancel and never consume any elements from the stream.
    static <T> Sink<T,scala.concurrent.Future<Object>>
    none(scala.Function1<T,Object> p)
    A Sink that will test the given predicate p for every received element and 1.
    static <T> Sink<T,NotUsed>
    onComplete(scala.Function1<scala.util.Try<Done>,scala.runtime.BoxedUnit> callback)
    A Sink that when the flow is completed, either through a failure or normal completion, apply the provided function with Success or Failure.
    scala.Tuple2<Mat,Sink<In,NotUsed>>
    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>>
    Creates a Sink that is materialized as an pekko.stream.scaladsl.SinkQueueWithCancel.
    static <T> Sink<T,SinkQueueWithCancel<T>>
    queue(int maxConcurrentPulls)
    Creates a Sink that is materialized as an pekko.stream.scaladsl.SinkQueueWithCancel.
    static <T> Sink<T,scala.concurrent.Future<T>>
    reduce(scala.Function2<T,T,T> 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.
    <Mat2> Mat2
    runWith(Graph<SourceShape<In>,Mat2> source, Materializer materializer)
    Connect this Sink to a Source and run it.
    static <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>>
    seq()
    A Sink that keeps on collecting incoming elements until upstream terminates.
    The shape of a graph is all that is externally visible: its inlets and outlets.
    static <T> Sink<T,Source<T,NotUsed>>
    A Sink that materializes this Sink itself as a Source.
    static <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>>
    takeLast(int n)
    A Sink that materializes into a Future of immutable.Seq[T] containing the last n collected elements.
     
    org.apache.pekko.stream.impl.LinearTraversalBuilder
    INTERNAL API.
    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 Details

    • Sink

      public Sink(org.apache.pekko.stream.impl.LinearTraversalBuilder traversalBuilder, SinkShape<In> shape)
  • Method Details

    • 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,scala.concurrent.Future<M>> fromMaterializer(scala.Function2<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.
    • fromSubscriber

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

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

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

      public static <T> Sink<T,scala.concurrent.Future<scala.Option<T>>> headOption()
      A Sink that materializes into a Future of the optional first value received. If the stream completes before signaling at least a single element, the value of the Future will be None. 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

      public static <T> Sink<T,scala.concurrent.Future<T>> last()
      A Sink that materializes into a Future of the last value received. If the stream completes before signaling at least a single element, the Future will be failed with a NoSuchElementException. If the stream signals an error, the Future will be failed with the stream's exception.

      See also <T>lastOption(), <T>takeLast(int).

    • lastOption

      public static <T> Sink<T,scala.concurrent.Future<scala.Option<T>>> lastOption()
      A Sink that materializes into a Future of the optional last value received. If the stream completes before signaling at least a single element, the value of the Future will be None. If the stream signals an error, the Future will be failed with the stream's exception.

      See also <T>last(), <T>takeLast(int).

    • takeLast

      public static <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> takeLast(int n)
      A Sink that materializes into a Future of immutable.Seq[T] containing the last n collected elements.

      If the stream completes before signaling at least n elements, the Future will complete with all elements seen so far. If the stream never completes, the Future will never complete. If there is a failure signaled in the stream the Future will be completed with failure.

    • seq

      public static <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> 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 Future of Seq[T] containing all the collected elements. Seq is limited to Int.MaxValue 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

    • count

      public static <T> Sink<T,scala.concurrent.Future<Object>> count()
      A Sink that counts all incoming elements until upstream terminates.

      Since upstream may be unbounded, consider using Flow[T].take or the stricter Flow[T].limit (and their variants) to ensure boundedness. The sink materializes into a Future of Long containing 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 Sink that materializes to a Future[Long] with the element count
      Since:
      1.3.0

      See also Flow.limit, Flow.limitWeighted, Flow.take, Flow.takeWithin, Flow.takeWhile

    • collection

      public static <T, That> Sink<T,scala.concurrent.Future<That>> collection(scala.collection.Factory<T,That> cbf)
      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 Future of That[T] containing all the collected elements. That[T] is limited to the limitations of the CanBuildFrom associated with it. For example, Seq is limited to Int.MaxValue elements. 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

      public static <T> Sink<T,org.reactivestreams.Publisher<T>> asPublisher(boolean 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.

    • source

      public static <T> Sink<T,Source<T,NotUsed>> source()
      A Sink that materializes this Sink itself as a Source. The returned Source is a "live view" onto the Sink and only supports a single Subscriber.

      Use BroadcastHub.sink(int) if you need a Source that allows multiple subscribers.

      Note: even if the Source is directly connected to the Sink, there is still an asynchronous boundary between them; performance may be improved in the future.

      Since:
      1.3.0
    • ignore

      public static Sink<Object,scala.concurrent.Future<Done>> ignore()
      A Sink that will consume the stream and discard the elements.
    • never

      public static Sink<Object,scala.concurrent.Future<Done>> never()
      A Sink that will always backpressure never cancel and never consume any elements from the stream.
    • foreach

      public static <T> Sink<T,scala.concurrent.Future<Done>> foreach(scala.Function1<T,scala.runtime.BoxedUnit> f)
      A Sink that will invoke the given procedure for each received element. The sink is materialized into a Future 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,scala.concurrent.Future<Done>> foreachAsync(int parallelism, scala.Function1<T,scala.concurrent.Future<scala.runtime.BoxedUnit>> f)
      A Sink that will invoke the given procedure asynchronously for each received element. The sink is materialized into a Future 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.
    • combine

      public static <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 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, scala.Function1<Object,Graph<UniformFanOutShape<T,U>,NotUsed>> fanOutStrategy, scala.Function2<M1,M2,M> matF)
      Combine two sinks with fan-out strategy like Broadcast or Balance and returns Sink with 2 outlets.
      Since:
      1.1.0
    • combine

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

      public static <U, T> Sink<T,scala.concurrent.Future<U>> fold(U zero, scala.Function2<U,T,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 Future 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.

      See Also:
    • foldWhile

      public static <U, T> Sink<T,scala.concurrent.Future<U>> foldWhile(U zero, scala.Function1<U,Object> p, scala.Function2<U,T,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 Future will be completed with value of the final function evaluation when the input stream ends, predicate p returns false, or completed with Failure if there is a failure signaled in the stream.

      Since:
      1.1.0
      See Also:
    • foldAsync

      public static <U, T> Sink<T,scala.concurrent.Future<U>> foldAsync(U zero, scala.Function2<U,T,scala.concurrent.Future<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 Future 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.

      See Also:
    • forall

      public static <T> Sink<T,scala.concurrent.Future<Object>> forall(scala.Function1<T,Object> p)
      A Sink that will test the given predicate p for every received element and 1. completes and returns Future of true if the predicate is true for all elements; 2. completes and returns Future of true if the stream is empty (i.e. completes before signalling any elements); 3. completes and returns Future of false if the predicate is false for any element.

      The materialized value Future will be completed with the value true or false when the input stream ends, or completed with Failure if there is a failure signaled in the stream.

      Adheres to the ActorAttributes.SupervisionStrategy attribute.

      '''Completes when''' upstream completes or the predicate p returns false

      '''Backpressures when''' the invocation of predicate p has not yet completed

      '''Cancels when''' predicate p returns false

      Since:
      1.1.0
    • none

      public static <T> Sink<T,scala.concurrent.Future<Object>> none(scala.Function1<T,Object> p)
      A Sink that will test the given predicate p for every received element and 1. completes and returns Future of true if the predicate is false for all elements; 2. completes and returns Future of true if the stream is empty (i.e. completes before signalling any elements); 3. completes and returns Future of false if the predicate is true for any element.

      The materialized value Future will be completed with the value true or false when the input stream ends, or completed with Failure if there is a failure signaled in the stream.

      Adheres to the ActorAttributes.SupervisionStrategy attribute.

      '''Completes when''' upstream completes or the predicate p returns true

      '''Backpressures when''' the invocation of predicate p has not yet completed

      '''Cancels when''' predicate p returns true

      Since:
      1.2.0
    • exists

      public static <T> Sink<T,scala.concurrent.Future<Object>> exists(scala.Function1<T,Object> p)
      A Sink that will test the given predicate p for every received element and 1. completes and returns Future of true if the predicate is true for any element; 2. completes and returns Future of false if the stream is empty (i.e. completes before signalling any elements); 3. completes and returns Future of false if the predicate is false for all elements.

      The materialized value Future will be completed with the value true or false when the input stream ends, or completed with Failure if there is a failure signaled in the stream.

      Adheres to the ActorAttributes.SupervisionStrategy attribute.

      '''Completes when''' upstream completes or the predicate p returns true

      '''Backpressures when''' the invocation of predicate p has not yet completed

      '''Cancels when''' predicate p returns true

      Since:
      1.1.0
    • reduce

      public static <T> Sink<T,scala.concurrent.Future<T>> reduce(scala.Function2<T,T,T> 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 Future 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.

      Adheres to the ActorAttributes.SupervisionStrategy attribute.

    • onComplete

      public static <T> Sink<T,NotUsed> onComplete(scala.Function1<scala.util.Try<Done>,scala.runtime.BoxedUnit> callback)
      A Sink that when the flow is completed, either through a failure or normal completion, apply the provided function with Success or Failure.
    • actorRef

      public static <T> Sink<T,NotUsed> actorRef(ActorRef ref, Object onCompleteMessage, scala.Function1<Throwable,Object> onFailureMessage)
      INTERNAL API

      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 the onFailureMessage will be invoked and its result 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 <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 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) function will be sent to the destination actor.

    • actorRefWithBackpressure

      public static <T> Sink<T,NotUsed> actorRefWithBackpressure(ActorRef ref, Object onInitMessage, Object onCompleteMessage, scala.Function1<Throwable,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) function will be sent to the destination actor.

    • queue

      public static <T> Sink<T,SinkQueueWithCancel<T>> queue(int maxConcurrentPulls)
      Creates a Sink that is materialized as an pekko.stream.scaladsl.SinkQueueWithCancel. pekko.stream.scaladsl.SinkQueueWithCancel.pull method is pulling element from the stream and returns Future[Option[T]. Future 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 pekko.stream.scaladsl.SinkQueueWithCancel including last None as completion marker

      See also pekko.stream.scaladsl.SinkQueueWithCancel

    • queue

      public static <T> Sink<T,SinkQueueWithCancel<T>> queue()
      Creates a Sink that is materialized as an pekko.stream.scaladsl.SinkQueueWithCancel. pekko.stream.scaladsl.SinkQueueWithCancel.pull method is pulling element from the stream and returns Future[Option[T}. Future completes 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.

      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 pekko.stream.scaladsl.SinkQueueWithCancel including last None as completion marker

      See also pekko.stream.scaladsl.SinkQueueWithCancel

    • futureSink

      public static <T, M> Sink<T,scala.concurrent.Future<M>> futureSink(scala.concurrent.Future<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,scala.concurrent.Future<M>> lazySink(scala.Function0<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 pekko.stream.NeverMaterializedException.

    • lazyFutureSink

      public static <T, M> Sink<T,scala.concurrent.Future<M>> lazyFutureSink(scala.Function0<scala.concurrent.Future<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 pekko.stream.NeverMaterializedException.

    • traversalBuilder

      public org.apache.pekko.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>
    • 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>
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • contramap

      public <In2> Sink<In2,Mat> contramap(scala.Function1<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 cancels

      Since:
      1.1.0
    • runWith

      public <Mat2> Mat2 runWith(Graph<SourceShape<In>,Mat2> source, Materializer materializer)
      Connect this Sink to a Source and run it. The returned value is the materialized value of the Source, e.g. the Subscriber of a Source#subscriber.

      Note that the ActorSystem can be used as the implicit materializer parameter to use the pekko.stream.SystemMaterializer for running the stream.

    • mapMaterializedValue

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

      public scala.Tuple2<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.

    • 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(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 Source
      Specified by:
      async in interface Graph<In,Mat>
    • async

      public Sink<In,Mat> async(String dispatcher)
      Put an asynchronous boundary around this Graph

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

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

      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
    • asJava

      public <JIn extends In> Sink<JIn,Mat> asJava()
      Converts this Scala DSL element to it's Java DSL counterpart.
    • getAttributes

      public Attributes getAttributes()
      Specified by:
      getAttributes in interface Graph<In,Mat>