Class Sink<In,Mat>
- java.lang.Object
-
- org.apache.pekko.stream.scaladsl.Sink<In,Mat>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.pekko.stream.Graph
Graph.GraphMapMatVal<S extends Shape,M>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> Sink<T,NotUsed>
actorRef(ActorRef ref, java.lang.Object onCompleteMessage)
Deprecated.Use variant accepting both on complete and on failure message.static <T> Sink<T,NotUsed>
actorRef(ActorRef ref, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
INTERNAL APIstatic <T> Sink<T,NotUsed>
actorRefWithAck(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
Deprecated.Use actorRefWithBackpressure accepting completion and failure matchers instead.static <T> scala.Function1<java.lang.Throwable,java.lang.Object>
actorRefWithAck$default$5()
static <T> Sink<T,NotUsed>
actorRefWithBackpressure(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal.static <T> Sink<T,NotUsed>
actorRefWithBackpressure(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal.Sink<In,Mat>
addAttributes(Attributes attr)
Add the given attributes to thisSink
.<JIn extends In>
Sink<JIn,Mat>asJava()
Converts this Scala DSL element to it's Java DSL counterpart.static <T> Sink<T,org.reactivestreams.Publisher<T>>
asPublisher(boolean fanout)
ASink
that materializes into aPublisher
.Sink<In,Mat>
async()
Put an asynchronous boundary around thisSource
Sink<In,Mat>
async(java.lang.String dispatcher)
Put an asynchronous boundary around thisGraph
Sink<In,Mat>
async(java.lang.String dispatcher, int inputBufferSize)
Put an asynchronous boundary around thisGraph
static <T> Sink<T,NotUsed>
cancelled()
ASink
that immediately cancels its upstream after materialization.static <T,That>
Sink<T,scala.concurrent.Future<That>>collection(scala.collection.Factory<T,That> cbf)
ASink
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<java.lang.Object,Graph<UniformFanOutShape<T,U>,NotUsed>> strategy)
Combine several sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
.<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 theSink
static <U,T>
Sink<T,scala.concurrent.Future<U>>fold(U zero, scala.Function2<U,T,U> f)
ASink
that will invoke the given function for every received element, giving it its previous output (or the givenzero
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)
ASink
that will invoke the given asynchronous function for every received element, giving it its previous output (or the givenzero
value) and the element as input.static <T> Sink<T,scala.concurrent.Future<Done>>
foreach(scala.Function1<T,scala.runtime.BoxedUnit> f)
ASink
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)
ASink
that will invoke the given procedure asynchronously for each received element.static <T> Sink<T,scala.concurrent.Future<Done>>
foreachParallel(int parallelism, scala.Function1<T,scala.runtime.BoxedUnit> f, scala.concurrent.ExecutionContext ec)
Deprecated.Use `foreachAsync` instead, it allows you to choose how to run the procedure, by calling some other API returning a Future or spawning a new Future.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,scala.concurrent.Future<M>>fromMaterializer(scala.Function2<Materializer,Attributes,Sink<T,M>> factory)
Defers the creation of aSink
until materialization.static <T> Sink<T,NotUsed>
fromSubscriber(org.reactivestreams.Subscriber<T> subscriber)
Helper to createSink
fromSubscriber
.static <T,M>
Sink<T,scala.concurrent.Future<M>>futureSink(scala.concurrent.Future<Sink<T,M>> future)
Turn aFuture[Sink]
into a Sink that will consume the values of the source when the future completes successfully.Attributes
getAttributes()
static <T> Sink<T,scala.concurrent.Future<T>>
head()
ASink
that materializes into aFuture
of the first value received.static <T> Sink<T,scala.concurrent.Future<scala.Option<T>>>
headOption()
ASink
that materializes into aFuture
of the optional first value received.static Sink<java.lang.Object,scala.concurrent.Future<Done>>
ignore()
ASink
that will consume the stream and discard the elements.static <T> Sink<T,scala.concurrent.Future<T>>
last()
ASink
that materializes into aFuture
of the last value received.static <T> Sink<T,scala.concurrent.Future<scala.Option<T>>>
lastOption()
ASink
that materializes into aFuture
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 thecreate
function to create a future sink until there is a first element passed from upstream.static <T,M>
Sink<T,scala.concurrent.Future<M>>lazyInit(scala.Function1<T,scala.concurrent.Future<Sink<T,M>>> sinkFactory, scala.Function0<M> fallback)
Deprecated.Use 'Sink.lazyFutureSink' in combination with 'Flow.prefixAndTail(1)' instead.static <T,M>
Sink<T,scala.concurrent.Future<scala.Option<M>>>lazyInitAsync(scala.Function0<scala.concurrent.Future<Sink<T,M>>> sinkFactory)
Deprecated.Use 'Sink.lazyFutureSink' instead.static <T,M>
Sink<T,scala.concurrent.Future<M>>lazySink(scala.Function0<Sink<T,M>> create)
Defers invoking thecreate
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.Sink<In,Mat>
named(java.lang.String name)
Add aname
attribute to this Sink.
static Sink<java.lang.Object,scala.concurrent.Future<Done>>
never()
ASink
that will always backpressure never cancel and never consume any elements from the stream.static <T> Sink<T,NotUsed>
onComplete(scala.Function1<scala.util.Try<Done>,scala.runtime.BoxedUnit> callback)
ASink
that when the flow is completed, either through a failure or normal completion, apply the provided function withSuccess
orFailure
.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.static <T> Sink<T,SinkQueueWithCancel<T>>
queue()
Creates aSink
that is materialized as anpekko.stream.scaladsl.SinkQueueWithCancel
.static <T> Sink<T,SinkQueueWithCancel<T>>
queue(int maxConcurrentPulls)
Creates aSink
that is materialized as anpekko.stream.scaladsl.SinkQueueWithCancel
.static <T> Sink<T,scala.concurrent.Future<T>>
reduce(scala.Function2<T,T,T> f)
ASink
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 thisSink
to aSource
and run it.static <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>>
seq()
ASink
that keeps on collecting incoming elements until upstream terminates.static <T,M>
Sink<T,scala.concurrent.Future<M>>setup(scala.Function2<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 <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>>
takeLast(int n)
ASink
that materializes into a aFuture
ofimmutable.Seq[T]
containing the lastn
collected elements.java.lang.String
toString()
org.apache.pekko.stream.impl.LinearTraversalBuilder
traversalBuilder()
INTERNAL API.Sink<In,Mat>
withAttributes(Attributes attr)
Replace the attributes of thisSink
with the given ones.
-
-
-
Method Detail
-
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)
-
setup
public static <T,M> Sink<T,scala.concurrent.Future<M>> setup(scala.Function2<ActorMaterializer,Attributes,Sink<T,M>> factory)
Deprecated.Use 'fromMaterializer' instead. Since Akka 2.6.0.
-
fromSubscriber
public static <T> Sink<T,NotUsed> fromSubscriber(org.reactivestreams.Subscriber<T> subscriber)
Helper to createSink
fromSubscriber
.
-
cancelled
public static <T> Sink<T,NotUsed> cancelled()
ASink
that immediately cancels its upstream after materialization.
-
head
public static <T> Sink<T,scala.concurrent.Future<T>> head()
ASink
that materializes into aFuture
of the first value received. If the stream completes before signaling at least a single element, the Future will be failed with aNoSuchElementException
. If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.See also
<T>headOption()
.
-
headOption
public static <T> Sink<T,scala.concurrent.Future<scala.Option<T>>> headOption()
ASink
that materializes into aFuture
of the optional first value received. If the stream completes before signaling at least a single element, the value of the Future will beNone
. If the stream signals an error errors before signaling at least a single element, the Future will be failed with the streams exception.See also
<T>head()
.
-
last
public static <T> Sink<T,scala.concurrent.Future<T>> last()
ASink
that materializes into aFuture
of the last value received. If the stream completes before signaling at least a single element, the Future will be failed with aNoSuchElementException
. If the stream signals an error, the Future will be failed with the stream's exception.See also
<T>lastOption()
,<T>takeLast(int)
.
-
lastOption
public static <T> Sink<T,scala.concurrent.Future<scala.Option<T>>> lastOption()
ASink
that materializes into aFuture
of the optional last value received. If the stream completes before signaling at least a single element, the value of the Future will beNone
. If the stream signals an error, the Future will be failed with the stream's exception.See also
<T>last()
,<T>takeLast(int)
.
-
takeLast
public static <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> takeLast(int n)
ASink
that materializes into a aFuture
ofimmutable.Seq[T]
containing the lastn
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, theFuture
will never complete. If there is a failure signaled in the stream theFuture
will be completed with failure.
-
seq
public static <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> seq()
ASink
that keeps on collecting incoming elements until upstream terminates. As upstream may be unbounded,Flow[T].take
or the stricterFlow[T].limit
(and their variants) may be used to ensure boundedness. Materializes into aFuture
ofSeq[T]
containing all the collected elements.Seq
is limited toInt.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
-
collection
public static <T,That> Sink<T,scala.concurrent.Future<That>> collection(scala.collection.Factory<T,That> cbf)
ASink
that keeps on collecting incoming elements until upstream terminates. As upstream may be unbounded,Flow[T].take
or the stricterFlow[T].limit
(and their variants) may be used to ensure boundedness. Materializes into aFuture
ofThat[T]
containing all the collected elements.That[T]
is limited to the limitations of the CanBuildFrom associated with it. For example,Seq
is limited toInt.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)
ASink
that materializes into aPublisher
.If
fanout
istrue
, the materializedPublisher
will support multipleSubscriber
s and the size of theinputBuffer
configured for this operator becomes the maximum number of elements that the fastestSubscriber
can be ahead of the slowest one before slowing the processing down due to back pressure.If
fanout
isfalse
then the materializedPublisher
will only support a singleSubscriber
and reject any additionalSubscriber
s.
-
ignore
public static Sink<java.lang.Object,scala.concurrent.Future<Done>> ignore()
ASink
that will consume the stream and discard the elements.
-
never
public static Sink<java.lang.Object,scala.concurrent.Future<Done>> never()
ASink
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)
ASink
that will invoke the given procedure for each received element. The sink is materialized into aFuture
which will be completed withSuccess
when reaching the normal end of the stream, or completed withFailure
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)
ASink
that will invoke the given procedure asynchronously for each received element. The sink is materialized into aFuture
which will be completed withSuccess
when reaching the normal end of the stream, or completed withFailure
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<java.lang.Object,Graph<UniformFanOutShape<T,U>,NotUsed>> strategy)
Combine several sinks with fan-out strategy likeBroadcast
orBalance
and returnsSink
.
-
foreachParallel
public static <T> Sink<T,scala.concurrent.Future<Done>> foreachParallel(int parallelism, scala.Function1<T,scala.runtime.BoxedUnit> f, scala.concurrent.ExecutionContext ec)
Deprecated.Use `foreachAsync` instead, it allows you to choose how to run the procedure, by calling some other API returning a Future or spawning a new Future. Since Akka 2.5.17.ASink
that will invoke the given function to each of the elements as they pass in. The sink is materialized into aFuture
If
f
throws an exception and the supervision decision ispekko.stream.Supervision.Stop
theFuture
will be completed with failure.If
f
throws an exception and the supervision decision ispekko.stream.Supervision.Resume
orpekko.stream.Supervision.Restart
the element is dropped and the stream continues.See also
Flow.mapAsyncUnordered
-
fold
public static <U,T> Sink<T,scala.concurrent.Future<U>> fold(U zero, scala.Function2<U,T,U> f)
ASink
that will invoke the given function for every received element, giving it its previous output (or the givenzero
value) and the element as input. The returnedFuture
will be completed with value of the final function evaluation when the input stream ends, or completed withFailure
if there is a failure signaled in the stream.
-
foldAsync
public static <U,T> Sink<T,scala.concurrent.Future<U>> foldAsync(U zero, scala.Function2<U,T,scala.concurrent.Future<U>> f)
ASink
that will invoke the given asynchronous function for every received element, giving it its previous output (or the givenzero
value) and the element as input. The returnedFuture
will be completed with value of the final function evaluation when the input stream ends, or completed withFailure
if there is a failure signaled in the stream.- See Also:
fold(U, scala.Function2<U, T, U>)
-
reduce
public static <T> Sink<T,scala.concurrent.Future<T>> reduce(scala.Function2<T,T,T> f)
ASink
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 returnedFuture
will be completed with value of the final function evaluation when the input stream ends, or completed withFailure
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)
ASink
that when the flow is completed, either through a failure or normal completion, apply the provided function withSuccess
orFailure
.
-
actorRef
public static <T> Sink<T,NotUsed> actorRef(ActorRef ref, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
INTERNAL APISends the elements of the stream to the given
ActorRef
. If the target actor terminates the stream will be canceled. When the stream is completed successfully the givenonCompleteMessage
will be sent to the destination actor. When the stream is completed with failure theonFailureMessage
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 zeromailbox-push-timeout-time
or use a rate limiting operator in front of thisSink
.
-
actorRef
public static <T> Sink<T,NotUsed> actorRef(ActorRef ref, java.lang.Object onCompleteMessage)
Deprecated.Use variant accepting both on complete and on failure message. Since Akka 2.6.0.Sends the elements of the stream to the givenActorRef
. If the target actor terminates the stream will be canceled. When the stream is completed successfully the givenonCompleteMessage
will be sent to the destination actor. When the stream is completed with failure apekko.actor.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 zeromailbox-push-timeout-time
or use a rate limiting operator in front of thisSink
.
-
actorRefWithBackpressure
public static <T> Sink<T,NotUsed> actorRefWithBackpressure(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal. First element is alwaysonInitMessage
, then stream is waiting for acknowledgement messageackMessage
from the given actor which means that it is ready to process elements. It also requiresackMessage
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 ofonFailureMessage(throwable)
function will be sent to the destination actor.
-
actorRefWithBackpressure
public static <T> Sink<T,NotUsed> actorRefWithBackpressure(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal. First element is alwaysonInitMessage
, then stream is waiting for acknowledgement message from the given actor which means that it is ready to process elements. It also requires an ack message after each stream element to make backpressure work. This variant will consider any message as ack message.If the target actor terminates the stream will be canceled. When the stream is completed successfully the given
onCompleteMessage
will be sent to the destination actor. When the stream is completed with failure - result ofonFailureMessage(throwable)
function will be sent to the destination actor.
-
actorRefWithAck
public static <T> Sink<T,NotUsed> actorRefWithAck(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
Deprecated.Use actorRefWithBackpressure accepting completion and failure matchers instead. Since Akka 2.6.0.Sends the elements of the stream to the givenActorRef
that sends back back-pressure signal. First element is alwaysonInitMessage
, then stream is waiting for acknowledgement messageackMessage
from the given actor which means that it is ready to process elements. It also requiresackMessage
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 ofonFailureMessage(throwable)
function will be sent to the destination actor.
-
actorRefWithAck$default$5
public static <T> scala.Function1<java.lang.Throwable,java.lang.Object> actorRefWithAck$default$5()
-
queue
public static <T> Sink<T,SinkQueueWithCancel<T>> queue(int maxConcurrentPulls)
Creates aSink
that is materialized as anpekko.stream.scaladsl.SinkQueueWithCancel
.pekko.stream.scaladsl.SinkQueueWithCancel.pull
method is pulling element from the stream and returnsFuture[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 ofinputBuffer
from upstream and then stop back pressure. You can configure size of input buffer by usingSink.withAttributes
method.For stream completion you need to pull all elements from
pekko.stream.scaladsl.SinkQueueWithCancel
including last None as completion markerSee also
pekko.stream.scaladsl.SinkQueueWithCancel
-
queue
public static <T> Sink<T,SinkQueueWithCancel<T>> queue()
Creates aSink
that is materialized as anpekko.stream.scaladsl.SinkQueueWithCancel
.pekko.stream.scaladsl.SinkQueueWithCancel.pull
method is pulling element from the stream and returnsFuture[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 ofinputBuffer
from upstream and then stop back pressure. You can configure size of input buffer by usingSink.withAttributes
method.For stream completion you need to pull all elements from
pekko.stream.scaladsl.SinkQueueWithCancel
including last None as completion markerSee also
pekko.stream.scaladsl.SinkQueueWithCancel
-
lazyInit
public static <T,M> Sink<T,scala.concurrent.Future<M>> lazyInit(scala.Function1<T,scala.concurrent.Future<Sink<T,M>>> sinkFactory, scala.Function0<M> fallback)
Deprecated.Use 'Sink.lazyFutureSink' in combination with 'Flow.prefixAndTail(1)' instead. Since Akka 2.6.0.Creates a realSink
upon receiving the first element. InternalSink
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 theFuture
is completed with the exception. Otherwise theFuture
is completed with the materialized value of the internal sink.
-
lazyInitAsync
public static <T,M> Sink<T,scala.concurrent.Future<scala.Option<M>>> lazyInitAsync(scala.Function0<scala.concurrent.Future<Sink<T,M>>> sinkFactory)
Deprecated.Use 'Sink.lazyFutureSink' instead. Since Akka 2.6.0.Creates a realSink
upon receiving the first element. InternalSink
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 withNone
. If upstream fails before an element was received,sinkFactory
throws an exception, or materialization of the internal sink fails then theFuture
is completed with the exception. Otherwise theFuture
is completed with the materialized value of the internal sink.
-
futureSink
public static <T,M> Sink<T,scala.concurrent.Future<M>> futureSink(scala.concurrent.Future<Sink<T,M>> future)
Turn aFuture[Sink]
into a Sink that will consume the values of the source when the future completes successfully. If theFuture
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 thecreate
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 apekko.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 thecreate
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 apekko.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 interfaceGraph<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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
runWith
public <Mat2> Mat2 runWith(Graph<SourceShape<In>,Mat2> source, Materializer materializer)
Connect thisSink
to aSource
and run it. The returned value is the materialized value of theSource
, e.g. theSubscriber
of aSource#subscriber
.Note that the
ActorSystem
can be used as the implicitmaterializer
parameter to use thepekko.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 thisSink
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 interfaceGraph<In,Mat>
-
addAttributes
public Sink<In,Mat> addAttributes(Attributes attr)
Add the given attributes to thisSink
. 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 interfaceGraph<In,Mat>
-
async
public Sink<In,Mat> async(java.lang.String dispatcher)
Put an asynchronous boundary around thisGraph
-
async
public Sink<In,Mat> async(java.lang.String dispatcher, int inputBufferSize)
Put an asynchronous boundary around thisGraph
-
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 interfaceGraph<In,Mat>
-
-