object Source
- Alphabetic
- By Inheritance
- Source
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
Value Members
- final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def ##: Int
- Definition Classes
- AnyRef → Any
- final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- def actorRef[T](completionMatcher: Function[Any, Optional[CompletionStrategy]], failureMatcher: Function[Any, Optional[Throwable]], bufferSize: Int, overflowStrategy: OverflowStrategy): Source[T, ActorRef]
Creates a
Source
that is materialized as an pekko.actor.ActorRef.Creates a
Source
that is materialized as an pekko.actor.ActorRef. Messages sent to this actor will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received.Depending on the defined pekko.stream.OverflowStrategy it might drop elements if there is no space available in the buffer.
The strategy pekko.stream.OverflowStrategy.backpressure is not supported, and an IllegalArgument("Backpressure overflowStrategy not supported") will be thrown if it is passed as argument.
The buffer can be disabled by using
bufferSize
of 0 and then received messages are dropped if there is no demand from downstream. WhenbufferSize
is 0 theoverflowStrategy
does not matter.The stream can be completed successfully by sending the actor reference a message that is matched by
completionMatcher
in which case already buffered elements will be signaled before signaling completion.The stream can be completed with failure by sending a message that is matched by
failureMatcher
. The extracted Throwable will be used to fail the stream. In case the Actor is still draining its internal buffer (after having received a message matched bycompletionMatcher
) before signaling completion and it receives a message matched byfailureMatcher
, the failure will be signaled downstream immediately (instead of the completion signal).Note that terminating the actor without first completing it, either with a success or a failure, will prevent the actor triggering downstream completion and the stream will continue to run even though the source actor is dead. Therefore you should **not** attempt to manually terminate the actor such as with a pekko.actor.PoisonPill.
The actor will be stopped when the stream is completed, failed or canceled from downstream, i.e. you can watch it to get notified when that happens.
See also pekko.stream.scaladsl.Source.queue.
- completionMatcher
catches the completion message to end the stream
- failureMatcher
catches the failure message to fail the stream
- bufferSize
The size of the buffer in element count
- overflowStrategy
Strategy that is used when incoming elements cannot fit inside the buffer
- def actorRefWithBackpressure[T](ackMessage: Any, completionMatcher: Function[Any, Optional[CompletionStrategy]], failureMatcher: Function[Any, Optional[Throwable]]): Source[T, ActorRef]
Creates a
Source
that is materialized as an pekko.actor.ActorRef.Creates a
Source
that is materialized as an pekko.actor.ActorRef. Messages sent to this actor will be emitted to the stream if there is demand from downstream, and a new message will only be accepted after the previous messages has been consumed and acknowledged back. The stream will complete with failure if a message is sent before the acknowledgement has been replied back.The stream can be completed with failure by sending a message that is matched by
failureMatcher
. The extracted Throwable will be used to fail the stream. In case the Actor is still draining its internal buffer (after having received a message matched bycompletionMatcher
) before signaling completion and it receives a message matched byfailureMatcher
, the failure will be signaled downstream immediately (instead of the completion signal).The actor will be stopped when the stream is completed, failed or canceled from downstream, i.e. you can watch it to get notified when that happens.
- final def asInstanceOf[T0]: T0
- Definition Classes
- Any
- def asSubscriber[T](): Source[T, Subscriber[T]]
Creates a
Source
that is materialized as a org.reactivestreams.Subscriber - def clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
- def combine[T, U](first: Source[T, _], second: Source[T, _], rest: List[Source[T, _]], strategy: Function[Integer, _ <: Graph[UniformFanInShape[T, U], NotUsed]]): Source[U, NotUsed]
Combines several sources with fan-in strategy like Merge or Concat into a single Source.
- def combineMat[T, U, M1, M2, M](first: Source[T, M1], second: Source[T, M2], strategy: Function[Integer, _ <: Graph[UniformFanInShape[T, U], NotUsed]], combine: Function2[M1, M2, M]): Source[U, M]
Combines two sources with fan-in strategy like
Merge
orConcat
and returnsSource
with a materialized value. - def completionStage[T](completionStage: CompletionStage[T]): Source[T, NotUsed]
Emits a single value when the given
CompletionStage
is successfully completed and then completes the stream.Emits a single value when the given
CompletionStage
is successfully completed and then completes the stream. If theCompletionStage
is completed with a failure the stream is failed. - def completionStageSource[T, M](completionStageSource: CompletionStage[Source[T, M]]): Source[T, CompletionStage[M]]
Turn a
CompletionStage[Source]
into a source that will emit the values of the source when the future completes successfully.Turn a
CompletionStage[Source]
into a source that will emit the values of the source when the future completes successfully. If theCompletionStage
is completed with a failure the stream is failed. - def cycle[O](f: Creator[Iterator[O]]): Source[O, NotUsed]
Helper to create 'cycled' Source from iterator provider.
Helper to create 'cycled' Source from iterator provider. Example usage:
Source.cycle(() -> Arrays.asList(1, 2, 3).iterator());
Start a new 'cycled'
Source
from the given elements. The producer stream of elements will continue infinitely by repeating the sequence of elements provided by function parameter. - def empty[T](clazz: Class[T]): Source[T, NotUsed]
Create a
Source
with no elements.Create a
Source
with no elements. The result is the same as callingSource.<O>empty()
- def empty[O](): Source[O, NotUsed]
Create a
Source
with no elements, i.e.Create a
Source
with no elements, i.e. an empty stream that is completed immediately for every connectedSink
. - final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def failed[T](cause: Throwable): Source[T, NotUsed]
Create a
Source
that immediately ends the stream with thecause
failure to every connectedSink
. - def from[O](iterable: Iterable[O]): Source[O, NotUsed]
Helper to create Source from
Iterable
.Helper to create Source from
Iterable
. Example usage:List<Integer> data = new ArrayList<Integer>(); data.add(1); data.add(2); data.add(3); Source.from(data);
Starts a new
Source
from the givenIterable
. This is like starting from an Iterator, but every Subscriber directly attached to the Publisher of this stream will see an individual flow of elements (always starting from the beginning) regardless of when they subscribed.Make sure that the
Iterable
is immutable or at least not modified after being used as aSource
. Otherwise the stream may fail withConcurrentModificationException
or other more subtle errors may occur. - def fromGraph[T, M](g: Graph[SourceShape[T], M]): Source[T, M]
A graph with the shape of a source logically is a source, this method makes it so also in type.
- def fromIterator[O](f: Creator[Iterator[O]]): Source[O, NotUsed]
Helper to create Source from
Iterator
.Helper to create Source from
Iterator
. Example usage:List<Integer> data = new ArrayList<Integer>(); data.add(1); data.add(2); data.add(3); Source.from(() -> data.iterator());
Start a new
Source
from the given Iterator. The produced stream of elements will continue until the iterator runs empty or fails during evaluation of thenext()
method. Elements are pulled out of the iterator in accordance with the demand coming from the downstream transformation steps. - def fromJavaStream[O, S <: BaseStream[O, S]](stream: Creator[BaseStream[O, S]]): Source[O, NotUsed]
Creates a source that wraps a Java 8
.Stream
Creates a source that wraps a Java 8
.Stream
uses a stream iterator to get all its elements and send them downstream on demand.Source
You can use Source.async to create asynchronous boundaries between synchronous java stream and the rest of flow.
- def fromMaterializer[T, M](factory: BiFunction[Materializer, Attributes, Source[T, M]]): Source[T, CompletionStage[M]]
Defers the creation of a Source until materialization.
Defers the creation of a Source until materialization. The
factory
function exposes Materializer which is going to be used during materialization and Attributes of the Source returned by this method. - def fromPublisher[O](publisher: Publisher[O]): Source[O, NotUsed]
Helper to create Source from
Publisher
.Helper to create Source from
Publisher
.Construct a transformation starting with given publisher. The transformation steps are executed by a series of org.reactivestreams.Processor instances that mediate the flow of elements downstream and the propagation of back-pressure upstream.
- def future[T](futureElement: Future[T]): Source[T, NotUsed]
Emits a single value when the given Scala
Future
is successfully completed and then completes the stream.Emits a single value when the given Scala
Future
is successfully completed and then completes the stream. The stream fails if theFuture
is completed with a failure.Here for Java interoperability, the normal use from Java should be Source.completionStage
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def lazyCompletionStage[T](create: Creator[CompletionStage[T]]): Source[T, NotUsed]
Defers invoking the
create
function to create a future element until there is downstream demand.Defers invoking the
create
function to create a future element until there is downstream demand.The returned future element will be emitted downstream when it completes, or fail the stream if the future is failed or the
create
function itself fails.Note that asynchronous boundaries (and other operators) in the stream may do pre-fetching which counter acts the laziness and will trigger the factory immediately.
The materialized future
Done
value is completed when thecreate
function has successfully been invoked and the future completes, if the function throws or the future fails the future materialized value is failed with that exception. If downstream cancels or fails before the function is invoked the materialized value is failed with a pekko.stream.NeverMaterializedException - def lazyCompletionStageSource[T, M](create: Creator[CompletionStage[Source[T, M]]]): Source[T, CompletionStage[M]]
Defers invoking the
create
function to create a future source until there is downstream demand.Defers invoking the
create
function to create a future source until there is downstream demand.The returned future source will emit downstream and behave just like it was the outer source when the
CompletionStage
completes successfully. Downstream completes when the created source completes and fails when the created source fails. If theCompletionStage
or thecreate
function fails the stream is failed.Note that asynchronous boundaries (and other operators) in the stream may do pre-fetching which counter acts the laziness and triggers the factory immediately.
The materialized
CompletionStage
value is completed with the materialized value of the created source when it has been materialized. If the function throws or the source materialization fails the future materialized value is failed with the thrown exception.If downstream cancels or fails before the function is invoked the materialized value is failed with a pekko.stream.NeverMaterializedException
- def lazySingle[T](create: Creator[T]): Source[T, NotUsed]
Defers invoking the
create
function to create a single element until there is downstream demand.Defers invoking the
create
function to create a single element until there is downstream demand.If the
create
function fails when invoked the stream is failed.Note that asynchronous boundaries (and other operators) in the stream may do pre-fetching which counter acts the laziness and will trigger the factory immediately.
The materialized future
Done
value is completed when thecreate
function has successfully been invoked, if the function throws the future materialized value is failed with that exception. If downstream cancels or fails before the function is invoked the materialized value is failed with a pekko.stream.NeverMaterializedException - def lazySource[T, M](create: Creator[Source[T, M]]): Source[T, CompletionStage[M]]
Defers invoking the
create
function to create a future source until there is downstream demand.Defers invoking the
create
function to create a future source until there is downstream demand.The returned source will emit downstream and behave just like it was the outer source. Downstream completes when the created source completes and fails when the created source fails.
Note that asynchronous boundaries (and other operators) in the stream may do pre-fetching which counter acts the laziness and will trigger the factory immediately.
The materialized future value is completed with the materialized value of the created source when it has been materialized. If the function throws or the source materialization fails the future materialized value is failed with the thrown exception.
If downstream cancels or fails before the function is invoked the materialized value is failed with a pekko.stream.NeverMaterializedException
- def maybe[T]: Source[T, CompletableFuture[Optional[T]]]
Create a
Source
which materializes a java.util.concurrent.CompletableFuture which controls what element will be emitted by the Source.Create a
Source
which materializes a java.util.concurrent.CompletableFuture which controls what element will be emitted by the Source. If the materialized promise is completed with a filled Optional, that value will be produced downstream, followed by completion. If the materialized promise is completed with an empty Optional, no value will be produced downstream and completion will be signalled immediately. If the materialized promise is completed with a failure, then the source will fail with that error. If the downstream of this source cancels or fails before the promise has been completed, then the promise will be completed with an empty Optional. - def mergePrioritizedN[T](sourcesAndPriorities: List[Pair[Source[T, _], Integer]], eagerComplete: Boolean): Source[T, NotUsed]
Merge multiple Sources.
Merge multiple Sources. Prefer the sources depending on the 'priority' parameters. The provided sources and priorities must have the same size and order.
emits when one of the inputs has an element available, preferring inputs based on the 'priority' parameters if both have elements available
backpressures when downstream backpressures
completes when both upstreams complete (This behavior is changeable to completing when any upstream completes by setting
eagerComplete=true
.)Cancels when downstream cancels
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def never[T]: Source[T, NotUsed]
Never emits any elements, never completes and never fails.
Never emits any elements, never completes and never fails. This stream could be useful in tests.
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @HotSpotIntrinsicCandidate()
- def queue[T](bufferSize: Int, overflowStrategy: OverflowStrategy, maxConcurrentOffers: Int): Source[T, SourceQueueWithComplete[T]]
Creates a
Source
that is materialized as an pekko.stream.javadsl.SourceQueueWithComplete.Creates a
Source
that is materialized as an pekko.stream.javadsl.SourceQueueWithComplete. You can push elements to the queue and they will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received. Elements in the buffer will be discarded if downstream is terminated.Depending on the defined pekko.stream.OverflowStrategy it might drop elements if there is no space available in the buffer.
Acknowledgement mechanism is available. pekko.stream.javadsl.SourceQueueWithComplete.offer returns
CompletionStage<QueueOfferResult>
which completes withQueueOfferResult.enqueued()
if element was added to buffer or sent downstream. It completes withQueueOfferResult.dropped()
if element was dropped. Can also complete withQueueOfferResult.Failure
- when stream failed orQueueOfferResult.QueueClosed
when downstream is completed.The strategy pekko.stream.OverflowStrategy.backpressure will not complete
maxConcurrentOffers
number ofoffer():CompletionStage
call when buffer is full.Instead of using the strategy pekko.stream.OverflowStrategy.dropNew it's recommended to use
Source.queue(bufferSize)
instead which returns a QueueOfferResult synchronously.You can watch accessibility of stream with pekko.stream.javadsl.SourceQueueWithComplete.watchCompletion. It returns a future that completes with success when this operator is completed or fails when stream is failed.
The buffer can be disabled by using
bufferSize
of 0 and then received message will wait for downstream demand unless there is another message waiting for downstream demand, in that case offer result will be completed according to the overflow strategy.The materialized SourceQueue may be used by up to maxConcurrentOffers concurrent producers.
- bufferSize
size of buffer in element count
- overflowStrategy
Strategy that is used when incoming elements cannot fit inside the buffer
- maxConcurrentOffers
maximum number of pending offers when buffer is full, should be greater than 0, not applicable when
OverflowStrategy.dropNew
is used
- def queue[T](bufferSize: Int, overflowStrategy: OverflowStrategy): Source[T, SourceQueueWithComplete[T]]
Creates a
Source
that is materialized as an pekko.stream.javadsl.SourceQueueWithComplete.Creates a
Source
that is materialized as an pekko.stream.javadsl.SourceQueueWithComplete. You can push elements to the queue and they will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received. Elements in the buffer will be discarded if downstream is terminated.Depending on the defined pekko.stream.OverflowStrategy it might drop elements if there is no space available in the buffer.
Acknowledgement mechanism is available. pekko.stream.javadsl.SourceQueueWithComplete.offer returns
CompletionStage<QueueOfferResult>
which completes withQueueOfferResult.enqueued()
if element was added to buffer or sent downstream. It completes withQueueOfferResult.dropped()
if element was dropped. Can also complete withQueueOfferResult.Failure
- when stream failed orQueueOfferResult.QueueClosed
when downstream is completed.The strategy pekko.stream.OverflowStrategy.backpressure will not complete last
offer():CompletionStage
call when buffer is full.Instead of using the strategy pekko.stream.OverflowStrategy.dropNew it's recommended to use
Source.queue(bufferSize)
instead which returns a QueueOfferResult synchronously.You can watch accessibility of stream with pekko.stream.javadsl.SourceQueueWithComplete.watchCompletion. It returns a future that completes with success when this operator is completed or fails when stream is failed.
The buffer can be disabled by using
bufferSize
of 0 and then received message will wait for downstream demand unless there is another message waiting for downstream demand, in that case offer result will be completed according to the overflow strategy.The materialized SourceQueue may only be used from a single producer.
- bufferSize
size of buffer in element count
- overflowStrategy
Strategy that is used when incoming elements cannot fit inside the buffer
- def queue[T](bufferSize: Int): Source[T, BoundedSourceQueue[T]]
Creates a
Source
that is materialized as an pekko.stream.BoundedSourceQueue.Creates a
Source
that is materialized as an pekko.stream.BoundedSourceQueue. You can push elements to the queue and they will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received. The buffer size is passed in as a parameter. Elements in the buffer will be discarded if downstream is terminated.Pushed elements may be dropped if there is no space available in the buffer. Elements will also be dropped if the queue is failed through the materialized
BoundedQueueSource
or theSource
is cancelled by the downstream. An element that was reported to beenqueued
is not guaranteed to be processed by the rest of the stream. If the queue is failed by callingBoundedQueueSource.fail
or the downstream cancels the stream, elements in the buffer are discarded.Acknowledgement of pushed elements is immediate. pekko.stream.BoundedSourceQueue.offer returns pekko.stream.QueueOfferResult which is implemented as:
QueueOfferResult.enqueued()
element was added to buffer, but may still be discarded later when the queue is failed or cancelledQueueOfferResult.dropped()
element was droppedQueueOfferResult.QueueClosed
the queue was completed with pekko.stream.BoundedSourceQueue.completeQueueOfferResult.Failure
the queue was failed with pekko.stream.BoundedSourceQueue.fail or if the stream failed- bufferSize
size of the buffer in number of elements
- def range(start: Int, end: Int, step: Int): Source[Integer, NotUsed]
Creates Source that represents integer values in range [start;end], with the given step.
Creates Source that represents integer values in range [start;end], with the given step. It allows to create
Source
out of range as simply as on ScalaSource(1 to N)
Uses Int, Int) internally
- See also
Int, Int)
- def range(start: Int, end: Int): Source[Integer, NotUsed]
Creates Source that represents integer values in range [start;end], step equals to 1.
Creates Source that represents integer values in range [start;end], step equals to 1. It allows to create
Source
out of range as simply as on ScalaSource(1 to N)
Uses Int) internally
- See also
Int)
- def repeat[T](element: T): Source[T, NotUsed]
Create a
Source
that will continually emit the given element. - def single[T](element: T): Source[T, NotUsed]
Create a
Source
with one element.Create a
Source
with one element. Every connectedSink
of this stream will see an individual stream consisting of one element. - final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def tick[O](initialDelay: Duration, interval: Duration, tick: O): Source[O, Cancellable]
Elements are emitted periodically with the specified interval.
Elements are emitted periodically with the specified interval. The tick element will be delivered to downstream consumers that has requested any elements. If a consumer has not requested any elements at the point in time when the tick element is produced it will not receive that tick element later. It will receive new tick elements as soon as it has requested more elements.
- Annotations
- @nowarn()
- def toString(): String
- Definition Classes
- AnyRef → Any
- def unfold[S, E](s: S, f: Function[S, Optional[Pair[S, E]]]): Source[E, NotUsed]
Create a
Source
that will unfold a value of typeS
into a pair of the next stateS
and output elements of typeE
. - def unfoldAsync[S, E](s: S, f: Function[S, CompletionStage[Optional[Pair[S, E]]]]): Source[E, NotUsed]
Same as unfold, but uses an async function to generate the next state-element tuple.
- def unfoldResource[T, S](create: Creator[S], read: Function[S, Optional[T]], close: Procedure[S]): Source[T, NotUsed]
Start a new
Source
from some resource which can be opened, read and closed.Start a new
Source
from some resource which can be opened, read and closed. Interaction with resource happens in a blocking way.Example:
Source.unfoldResource( () -> new BufferedReader(new FileReader("...")), reader -> reader.readLine(), reader -> reader.close())
You can use the supervision strategy to handle exceptions for
read
function. All exceptions thrown bycreate
orclose
will fail the stream.Restart
supervision strategy will close and create blocking IO again. Default strategy isStop
which means that stream will be terminated on error inread
function by default.You can configure the default dispatcher for this Source by changing the
pekko.stream.materializer.blocking-io-dispatcher
or set it for a given Source by using ActorAttributes.Adheres to the ActorAttributes.SupervisionStrategy attribute.
- create
- function that is called on stream start and creates/opens resource.
- read
- function that reads data from opened resource. It is called each time backpressure signal is received. Stream calls close and completes when
read
returns None.- close
- function that closes resource
- def unfoldResourceAsync[T, S](create: Creator[CompletionStage[S]], read: Function[S, CompletionStage[Optional[T]]], close: Function[S, CompletionStage[Done]]): Source[T, NotUsed]
Start a new
Source
from some resource which can be opened, read and closed.Start a new
Source
from some resource which can be opened, read and closed. It's similar tounfoldResource
but takes functions that returnCompletionStage
instead of plain values.You can use the supervision strategy to handle exceptions for
read
function or failures of producedFutures
. All exceptions thrown bycreate
orclose
as well as fails of returned futures will fail the stream.Restart
supervision strategy will close and create resource. Default strategy isStop
which means that stream will be terminated on error inread
function (or future) by default.You can configure the default dispatcher for this Source by changing the
pekko.stream.materializer.blocking-io-dispatcher
or set it for a given Source by using ActorAttributes.Adheres to the ActorAttributes.SupervisionStrategy attribute.
- create
- function that is called on stream start and creates/opens resource.
- read
- function that reads data from opened resource. It is called each time backpressure signal is received. Stream calls close and completes when
CompletionStage
from read function returns None.- close
- function that closes resource
- def upcast[SuperOut, Out <: SuperOut, Mat](source: Source[Out, Mat]): Source[SuperOut, Mat]
Upcast a stream of elements to a stream of supertypes of that element.
Upcast a stream of elements to a stream of supertypes of that element. Useful in combination with fan-in operators where you do not want to pay the cost of casting each element in a
map
.Example:
Source<Apple, NotUsed> apples = Source.single(new Apple()); Source<Orange, NotUsed> oranges = Source.single(new Orange()); Source<Fruit, NotUsed> appleFruits = Source.upcast(apples); Source<Fruit, NotUsed> orangeFruits = Source.upcast(oranges); Source<Fruit, NotUsed> fruits = appleFruits.merge(orangeFruits);
- SuperOut
a supertype to the type of elements in stream
- returns
A source with the supertype as elements
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- def zipN[T](sources: List[Source[T, _]]): Source[List[T], NotUsed]
Combine the elements of multiple streams into a stream of lists.
- def zipWithN[T, O](zipper: Function[List[T], O], sources: List[Source[T, _]]): Source[O, NotUsed]
Deprecated Value Members
- def actorRef[T](bufferSize: Int, overflowStrategy: OverflowStrategy): Source[T, ActorRef]
Creates a
Source
that is materialized as an pekko.actor.ActorRef.Creates a
Source
that is materialized as an pekko.actor.ActorRef. Messages sent to this actor will be emitted to the stream if there is demand from downstream, otherwise they will be buffered until request for demand is received.Depending on the defined pekko.stream.OverflowStrategy it might drop elements if there is no space available in the buffer.
The strategy pekko.stream.OverflowStrategy.backpressure is not supported, and an IllegalArgument("Backpressure overflowStrategy not supported") will be thrown if it is passed as argument.
The buffer can be disabled by using
bufferSize
of 0 and then received messages are dropped if there is no demand from downstream. WhenbufferSize
is 0 theoverflowStrategy
does not matter.The stream can be completed successfully by sending the actor reference a pekko.actor.Status.Success (whose content will be ignored) in which case already buffered elements will be signaled before signaling completion.
The stream can be completed successfully by sending the actor reference a pekko.actor.Status.Success. If the content is pekko.stream.CompletionStrategy.immediately the completion will be signaled immediately, otherwise if the content is pekko.stream.CompletionStrategy.draining (or anything else) already buffered elements will be signaled before signaling completion. Sending pekko.actor.PoisonPill will signal completion immediately but this behavior is deprecated and scheduled to be removed.
The stream can be completed with failure by sending a pekko.actor.Status.Failure to the actor reference. In case the Actor is still draining its internal buffer (after having received a pekko.actor.Status.Success) before signaling completion and it receives a pekko.actor.Status.Failure, the failure will be signaled downstream immediately (instead of the completion signal).
Note that terminating the actor without first completing it, either with a success or a failure, will prevent the actor triggering downstream completion and the stream will continue to run even though the source actor is dead. Therefore you should **not** attempt to manually terminate the actor such as with a pekko.actor.PoisonPill.
The actor will be stopped when the stream is completed, failed or canceled from downstream, i.e. you can watch it to get notified when that happens.
See also pekko.stream.javadsl.Source.queue.
- bufferSize
The size of the buffer in element count
- overflowStrategy
Strategy that is used when incoming elements cannot fit inside the buffer
- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use variant accepting completion and failure matchers
- def actorRefWithAck[T](ackMessage: Any): Source[T, ActorRef]
Creates a
Source
that is materialized as an pekko.actor.ActorRef.Creates a
Source
that is materialized as an pekko.actor.ActorRef. Messages sent to this actor will be emitted to the stream if there is demand from downstream, and a new message will only be accepted after the previous messages has been consumed and acknowledged back. The stream will complete with failure if a message is sent before the acknowledgement has been replied back.The stream can be completed successfully by sending the actor reference a pekko.actor.Status.Success. If the content is pekko.stream.CompletionStrategy.immediately the completion will be signaled immediately, otherwise if the content is pekko.stream.CompletionStrategy.draining (or anything else) already buffered element will be signaled before signaling completion.
The stream can be completed with failure by sending a pekko.actor.Status.Failure to the actor reference. In case the Actor is still draining its internal buffer (after having received a pekko.actor.Status.Success) before signaling completion and it receives a pekko.actor.Status.Failure, the failure will be signaled downstream immediately (instead of the completion signal).
The actor will be stopped when the stream is completed, failed or canceled from downstream, i.e. you can watch it to get notified when that happens.
- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use actorRefWithBackpressure accepting completion and failure matchers
- def actorRefWithAck[T](ackMessage: Any, completionMatcher: Function[Any, Optional[CompletionStrategy]], failureMatcher: Function[Any, Optional[Throwable]]): Source[T, ActorRef]
Creates a
Source
that is materialized as an pekko.actor.ActorRef.Creates a
Source
that is materialized as an pekko.actor.ActorRef. Messages sent to this actor will be emitted to the stream if there is demand from downstream, and a new message will only be accepted after the previous messages has been consumed and acknowledged back. The stream will complete with failure if a message is sent before the acknowledgement has been replied back.The stream can be completed with failure by sending a message that is matched by
failureMatcher
. The extracted Throwable will be used to fail the stream. In case the Actor is still draining its internal buffer (after having received a message matched bycompletionMatcher
) before signaling completion and it receives a message matched byfailureMatcher
, the failure will be signaled downstream immediately (instead of the completion signal).The actor will be stopped when the stream is completed, failed or canceled from downstream, i.e. you can watch it to get notified when that happens.
- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use actorRefWithBackpressure instead
- def finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable]) @Deprecated @Deprecated
- Deprecated
- def fromCompletionStage[O](future: CompletionStage[O]): Source[O, NotUsed]
Starts a new
Source
from the givenCompletionStage
.Starts a new
Source
from the givenCompletionStage
. The stream will consist of one element when theCompletionStage
is completed with a successful value, which may happen before or after materializing theFlow
. The stream terminates with a failure if theCompletionStage
is completed with a failure.- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use 'Source.completionStage' instead
- def fromFuture[O](future: Future[O]): Source[O, NotUsed]
Start a new
Source
from the givenFuture
.Start a new
Source
from the givenFuture
. The stream will consist of one element when theFuture
is completed with a successful value, which may happen before or after materializing theFlow
. The stream terminates with a failure if theFuture
is completed with a failure.- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use 'Source.future' instead
- def fromFutureSource[T, M](future: Future[_ <: Graph[SourceShape[T], M]]): Source[T, Future[M]]
Streams the elements of the given future source once it successfully completes.
Streams the elements of the given future source once it successfully completes. If the Future fails the stream is failed with the exception from the future. If downstream cancels before the stream completes the materialized Future will be failed with a StreamDetachedException.
- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use 'Source.futureSource' (potentially together with
Source.fromGraph
) instead
- def fromSourceCompletionStage[T, M](completion: CompletionStage[_ <: Graph[SourceShape[T], M]]): Source[T, CompletionStage[M]]
Streams the elements of an asynchronous source once its given CompletionStage completes.
Streams the elements of an asynchronous source once its given CompletionStage completes. If the CompletionStage fails the stream is failed with the exception from the future. If downstream cancels before the stream completes the materialized CompletionStage will be failed with a StreamDetachedException
- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use 'Source.completionStageSource' (potentially together with
Source.fromGraph
) instead
- def lazily[T, M](create: Creator[Source[T, M]]): Source[T, CompletionStage[M]]
Creates a
Source
that is not materialized until there is downstream demand, when the source gets materialized the materialized future is completed with its value, if downstream cancels or fails without any demand thecreate
factory is never called and the materializedCompletionStage
is failed.Creates a
Source
that is not materialized until there is downstream demand, when the source gets materialized the materialized future is completed with its value, if downstream cancels or fails without any demand thecreate
factory is never called and the materializedCompletionStage
is failed.- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use 'Source.lazySource' instead
- def lazilyAsync[T](create: Creator[CompletionStage[T]]): Source[T, Future[NotUsed]]
Creates a
Source
from supplied future factory that is not called until downstream demand.Creates a
Source
from supplied future factory that is not called until downstream demand. When source gets materialized the materialized future is completed with the value from the factory. If downstream cancels or fails without any demand the create factory is never called and the materializedFuture
is failed.- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use 'Source.lazyCompletionStage' instead
- See also
- def setup[T, M](factory: BiFunction[ActorMaterializer, Attributes, Source[T, M]]): Source[T, CompletionStage[M]]
Defers the creation of a Source until materialization.
Defers the creation of a Source until materialization. The
factory
function exposes ActorMaterializer which is going to be used during materialization and Attributes of the Source returned by this method.- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.6.0) Use 'fromMaterializer' instead
- def tick[O](initialDelay: FiniteDuration, interval: FiniteDuration, tick: O): Source[O, Cancellable]
Elements are emitted periodically with the specified interval.
Elements are emitted periodically with the specified interval. The tick element will be delivered to downstream consumers that has requested any elements. If a consumer has not requested any elements at the point in time when the tick element is produced it will not receive that tick element later. It will receive new tick elements as soon as it has requested more elements.
- Annotations
- @deprecated
- Deprecated
(Since version Akka 2.5.12) Use the overloaded one which accepts java.time.Duration instead.