object Sink
- Source
- Sink.scala
- Alphabetic
- By Inheritance
- Sink
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Value Members
-
def
actorRef[T](ref: ActorRef, onCompleteMessage: Any): Sink[T, NotUsed]
Sends the elements of the stream to the given
ActorRef
.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 givenonCompleteMessage
will be sent to the destination actor. When the stream is completed with failure a akka.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 stage in front of thisSink
. -
def
actorRefWithAck[T](ref: ActorRef, onInitMessage: Any, ackMessage: Any, onCompleteMessage: Any, onFailureMessage: (Throwable) ⇒ Any = Status.Failure): Sink[T, NotUsed]
Sends the elements of the stream to the given
ActorRef
that sends back back-pressure signal.Sends the elements of the stream to the given
ActorRef
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. -
def
actorSubscriber[T](props: Props): Sink[T, ActorRef]
Creates a
Sink
that is materialized to an akka.actor.ActorRef which points to an Actor created according to the passed in akka.actor.Props.Creates a
Sink
that is materialized to an akka.actor.ActorRef which points to an Actor created according to the passed in akka.actor.Props. Actor created by theprops
must be akka.stream.actor.ActorSubscriber. -
def
asPublisher[T](fanout: Boolean): Sink[T, Publisher[T]]
A
Sink
that materializes into a org.reactivestreams.Publisher.A
Sink
that materializes into a org.reactivestreams.Publisher.If
fanout
istrue
, the materializedPublisher
will support multipleSubscriber
s and the size of theinputBuffer
configured for this stage becomes the maximum number of elements that the fastest org.reactivestreams.Subscriber 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. -
def
cancelled[T]: Sink[T, NotUsed]
A
Sink
that immediately cancels its upstream after materialization. -
def
combine[T, U](first: Sink[U, _], second: Sink[U, _], rest: Sink[U, _]*)(strategy: (Int) ⇒ Graph[UniformFanOutShape[T, U], NotUsed]): Sink[T, NotUsed]
Combine several sinks with fan-out strategy like
Broadcast
orBalance
and returnsSink
. -
def
fold[U, T](zero: U)(f: (U, T) ⇒ U): Sink[T, Future[U]]
A
Sink
that will invoke the given function for every received element, giving it its previous output (or the givenzero
value) and the element as input.A
Sink
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 returned scala.concurrent.Future 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
-
def
foldAsync[U, T](zero: U)(f: (U, T) ⇒ Future[U]): Sink[T, Future[U]]
A
Sink
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.A
Sink
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 returned scala.concurrent.Future 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
-
def
foreach[T](f: (T) ⇒ Unit): Sink[T, Future[Done]]
A
Sink
that will invoke the given procedure for each received element.A
Sink
that will invoke the given procedure for each received element. The sink is materialized into a scala.concurrent.Future will be completed withSuccess
when reaching the normal end of the stream, or completed withFailure
if there is a failure signaled in the stream.. -
def
foreachParallel[T](parallelism: Int)(f: (T) ⇒ Unit)(implicit ec: ExecutionContext): Sink[T, Future[Done]]
A
Sink
that will invoke the given function to each of the elements as they pass in.A
Sink
that will invoke the given function to each of the elements as they pass in. The sink is materialized into a scala.concurrent.FutureIf
f
throws an exception and the supervision decision is akka.stream.Supervision.Stop theFuture
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
-
def
fromGraph[T, M](g: Graph[SinkShape[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.
-
def
fromSubscriber[T](subscriber: Subscriber[T]): Sink[T, NotUsed]
Helper to create Sink from
Subscriber
. -
def
head[T]: Sink[T, Future[T]]
A
Sink
that materializes into aFuture
of the first value received.A
Sink
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 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.
-
def
headOption[T]: Sink[T, Future[Option[T]]]
A
Sink
that materializes into aFuture
of the optional first value received.A
Sink
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 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.
-
def
ignore: Sink[Any, Future[Done]]
A
Sink
that will consume the stream and discard the elements. -
def
last[T]: Sink[T, Future[T]]
A
Sink
that materializes into aFuture
of the last value received.A
Sink
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 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.
-
def
lastOption[T]: Sink[T, Future[Option[T]]]
A
Sink
that materializes into aFuture
of the optional last value received.A
Sink
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 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.
-
def
lazyInit[T, M](sinkFactory: (T) ⇒ Future[Sink[T, M]], fallback: () ⇒ M): Sink[T, Future[M]]
Creates a real
Sink
upon receiving the first element.Creates a real
Sink
upon receiving the first element. InternalSink
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 theFuture
will be completed with failure. For all other supervision options it will try to create sink with next elementfallback
will be executed when there was no elements and completed is received from upstream. -
def
onComplete[T](callback: (Try[Done]) ⇒ Unit): Sink[T, NotUsed]
A
Sink
that when the flow is completed, either through a failure or normal completion, apply the provided function with scala.util.Success or scala.util.Failure. -
def
queue[T](): Sink[T, SinkQueueWithCancel[T]]
Creates a
Sink
that is materialized as an akka.stream.scaladsl.SinkQueue.Creates a
Sink
that is materialized as an akka.stream.scaladsl.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 ofinputBuffer
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 akka.stream.scaladsl.SinkQueue including last None as completion marker
-
def
reduce[T](f: (T, T) ⇒ T): Sink[T, Future[T]]
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.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 scala.concurrent.Future 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 stage will fail its downstream with a NoSuchElementException, which is semantically in-line with that Scala's standard library collections do in such situations.
-
def
seq[T]: Sink[T, Future[Seq[T]]]
A
Sink
that keeps on collecting incoming elements until upstream terminates.A
Sink
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
-
def
shape[T](name: String): SinkShape[T]
INTERNAL API