public class Sink$
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Sink$ |
MODULE$
Static reference to the singleton instance of this Scala object.
|
Constructor and Description |
---|
Sink$() |
Modifier and Type | Method and Description |
---|---|
<T> Sink<T,NotUsed> |
actorRef(ActorRef ref,
java.lang.Object onCompleteMessage)
Sends the elements of the stream to the given
ActorRef . |
<T> Sink<T,NotUsed> |
actorRefWithAck(ActorRef ref,
java.lang.Object onInitMessage,
java.lang.Object ackMessage,
java.lang.Object onCompleteMessage,
scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
Sends the elements of the stream to the given
ActorRef that sends back back-pressure signal. |
<T> Sink<T,ActorRef> |
actorSubscriber(Props props)
|
<T> Sink<T,org.reactivestreams.Publisher<T>> |
asPublisher(boolean fanout)
A
Sink that materializes into a Publisher . |
<T> Sink<T,NotUsed> |
cancelled()
A
Sink that immediately cancels its upstream after materialization. |
<T,U> Sink<T,NotUsed> |
combine(Sink<U,?> first,
Sink<U,?> second,
scala.collection.Seq<Sink<U,?>> rest,
scala.Function1<java.lang.Object,Graph<UniformFanOutShape<T,U>,NotUsed>> strategy)
Combine several sinks with fan-out strategy like
Broadcast or Balance and returns Sink . |
<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. |
<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. |
<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. |
<T> Sink<T,scala.concurrent.Future<Done>> |
foreachParallel(int parallelism,
scala.Function1<T,scala.runtime.BoxedUnit> f,
scala.concurrent.ExecutionContext ec)
A
Sink that will invoke the given function to each of the elements
as they pass in. |
<T,M> Sink<T,M> |
fromGraph(Graph<SinkShape<T>,M> g)
A graph with the shape of a sink logically is a sink, this method makes
it so also in type.
|
<T> Sink<T,NotUsed> |
fromSubscriber(org.reactivestreams.Subscriber<T> subscriber)
Helper to create
Sink from Subscriber . |
<T> Sink<T,scala.concurrent.Future<T>> |
head()
A
Sink that materializes into a Future of the first value received. |
<T> Sink<T,scala.concurrent.Future<scala.Option<T>>> |
headOption()
A
Sink that materializes into a Future of the optional first value received. |
Sink<java.lang.Object,scala.concurrent.Future<Done>> |
ignore()
A
Sink that will consume the stream and discard the elements. |
<T> Sink<T,scala.concurrent.Future<T>> |
last()
A
Sink that materializes into a Future of the last value received. |
<T> Sink<T,scala.concurrent.Future<scala.Option<T>>> |
lastOption()
A
Sink that materializes into a Future of the optional last value received. |
<T,M> Sink<T,scala.concurrent.Future<M>> |
lazyInit(scala.Function1<T,scala.concurrent.Future<Sink<T,M>>> sinkFactory,
scala.Function0<M> fallback)
Creates a real
Sink upon receiving the first element. |
<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 . |
<T> Sink<T,SinkQueueWithCancel<T>> |
queue()
Creates a
Sink that is materialized as an SinkQueue . |
<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. |
<T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> |
seq()
A
Sink that keeps on collecting incoming elements until upstream terminates. |
<T> SinkShape<T> |
shape(java.lang.String name)
INTERNAL API
|
public static final Sink$ MODULE$
public <T> SinkShape<T> shape(java.lang.String name)
public <T,M> Sink<T,M> fromGraph(Graph<SinkShape<T>,M> g)
g
- (undocumented)public <T> Sink<T,NotUsed> fromSubscriber(org.reactivestreams.Subscriber<T> subscriber)
Sink
from Subscriber
.subscriber
- (undocumented)public <T> Sink<T,NotUsed> cancelled()
Sink
that immediately cancels its upstream after materialization.public <T> Sink<T,scala.concurrent.Future<T>> head()
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 headOption
.
public <T> Sink<T,scala.concurrent.Future<scala.Option<T>>> headOption()
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 head
.
public <T> Sink<T,scala.concurrent.Future<T>> last()
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 errors before signaling at least a single element, the Future will be failed with the streams exception.
See also lastOption
.
public <T> Sink<T,scala.concurrent.Future<scala.Option<T>>> lastOption()
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 errors before signaling at least a single element, the Future will be failed with the streams exception.
See also last
.
public <T> Sink<T,scala.concurrent.Future<scala.collection.immutable.Seq<T>>> seq()
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
public <T> Sink<T,org.reactivestreams.Publisher<T>> asPublisher(boolean fanout)
Sink
that materializes into a Publisher
.
If fanout
is true
, the materialized Publisher
will support multiple Subscriber
s and
the size of the inputBuffer
configured for this stage 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 Subscriber
s.
fanout
- (undocumented)public Sink<java.lang.Object,scala.concurrent.Future<Done>> ignore()
Sink
that will consume the stream and discard the elements.public <T> Sink<T,scala.concurrent.Future<Done>> foreach(scala.Function1<T,scala.runtime.BoxedUnit> f)
Sink
that will invoke the given procedure for each received element. The sink is materialized
into a Future
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..f
- (undocumented)public <T,U> Sink<T,NotUsed> combine(Sink<U,?> first, Sink<U,?> second, scala.collection.Seq<Sink<U,?>> rest, scala.Function1<java.lang.Object,Graph<UniformFanOutShape<T,U>,NotUsed>> strategy)
Broadcast
or Balance
and returns Sink
.first
- (undocumented)second
- (undocumented)rest
- (undocumented)strategy
- (undocumented)public <T> Sink<T,scala.concurrent.Future<Done>> foreachParallel(int parallelism, scala.Function1<T,scala.runtime.BoxedUnit> f, scala.concurrent.ExecutionContext ec)
Sink
that will invoke the given function to each of the elements
as they pass in. The sink is materialized into a Future
If f
throws an exception and the supervision decision is
akka.stream.Supervision.Stop
the Future
will be completed with failure.
If f
throws an exception and the supervision decision is
akka.stream.Supervision.Resume
or akka.stream.Supervision.Restart
the
element is dropped and the stream continues.
See also Flow.mapAsyncUnordered
parallelism
- (undocumented)f
- (undocumented)ec
- (undocumented)public <U,T> Sink<T,scala.concurrent.Future<U>> fold(U zero, scala.Function2<U,T,U> f)
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.
zero
- (undocumented)f
- (undocumented)foldAsync(U, scala.Function2<U, T, scala.concurrent.Future<U>>)
public <U,T> Sink<T,scala.concurrent.Future<U>> foldAsync(U zero, scala.Function2<U,T,scala.concurrent.Future<U>> f)
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.
zero
- (undocumented)f
- (undocumented)fold(U, scala.Function2<U, T, U>)
public <T> Sink<T,scala.concurrent.Future<T>> reduce(scala.Function2<T,T,T> f)
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 stage will fail its downstream with a NoSuchElementException
,
which is semantically in-line with that Scala's standard library collections
do in such situations.
f
- (undocumented)public <T> Sink<T,NotUsed> onComplete(scala.Function1<scala.util.Try<Done>,scala.runtime.BoxedUnit> callback)
Sink
that when the flow is completed, either through a failure or normal
completion, apply the provided function with Success
or Failure
.callback
- (undocumented)public <T> Sink<T,NotUsed> actorRef(ActorRef ref, java.lang.Object onCompleteMessage)
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 stage in front of this Sink
.
ref
- (undocumented)onCompleteMessage
- (undocumented)public <T> Sink<T,NotUsed> actorRefWithAck(ActorRef ref, java.lang.Object onInitMessage, java.lang.Object ackMessage, java.lang.Object onCompleteMessage, scala.Function1<java.lang.Throwable,java.lang.Object> onFailureMessage)
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.
ref
- (undocumented)onInitMessage
- (undocumented)ackMessage
- (undocumented)onCompleteMessage
- (undocumented)onFailureMessage
- (undocumented)public <T> Sink<T,ActorRef> actorSubscriber(Props props)
Sink
that is materialized to an ActorRef
which points to an Actor
created according to the passed in Props
. Actor created by the props
must
be ActorSubscriber
.props
- (undocumented)public <T> Sink<T,SinkQueueWithCancel<T>> queue()
Sink
that is materialized as an SinkQueue
.
akka.stream.scaladsl.SinkQueue.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 SinkQueue
including last None
as completion marker
See also SinkQueueWithCancel
public <T,M> Sink<T,scala.concurrent.Future<M>> lazyInit(scala.Function1<T,scala.concurrent.Future<Sink<T,M>>> sinkFactory, scala.Function0<M> fallback)
Sink
upon receiving the first element. Internal Sink
will not be created if there are no elements,
because of completion or error.
If sinkFactory
throws an exception and the supervision decision is
akka.stream.Supervision.Stop
the Future
will be completed with failure. For all other supervision options it will
try to create sink with next element
fallback
will be executed when there was no elements and completed is received from upstream.
sinkFactory
- (undocumented)fallback
- (undocumented)