public class Source$
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static Source$ |
MODULE$
Static reference to the singleton instance of this Scala object.
|
Constructor and Description |
---|
Source$() |
Modifier and Type | Method and Description |
---|---|
<T> Source<T,ActorRef> |
actorPublisher(Props props)
|
<T> Source<T,ActorRef> |
actorRef(int bufferSize,
OverflowStrategy overflowStrategy)
Creates a
Source that is materialized as an ActorRef . |
<T> Source<T,org.reactivestreams.Subscriber<T>> |
asSubscriber()
Creates a
Source that is materialized as a Subscriber |
<T,U> Source<U,NotUsed> |
combine(Source<T,?> first,
Source<T,?> second,
java.util.List<Source<T,?>> rest,
Function<java.lang.Integer,? extends Graph<UniformFanInShape<T,U>,NotUsed>> strategy)
Combines several sources with fan-in strategy like
Merge or Concat and returns Source . |
<O> Source<O,NotUsed> |
cycle(Creator<java.util.Iterator<O>> f)
Helper to create 'cycled'
Source from iterator provider. |
<O> Source<O,NotUsed> |
empty()
Create a
Source with no elements, i.e. |
<T> Source<T,NotUsed> |
failed(java.lang.Throwable cause)
Create a
Source that immediately ends the stream with the cause failure to every connected Sink . |
<O> Source<O,NotUsed> |
from(java.lang.Iterable<O> iterable)
Helper to create
Source from Iterable . |
<O> Source<O,NotUsed> |
fromCompletionStage(java.util.concurrent.CompletionStage<O> future)
Start a new
Source from the given CompletionStage . |
<O> Source<O,NotUsed> |
fromFuture(scala.concurrent.Future<O> future)
Start a new
Source from the given Future . |
<T,M> Source<T,M> |
fromGraph(Graph<SourceShape<T>,M> g)
A graph with the shape of a source logically is a source, this method makes
it so also in type.
|
<O> Source<O,NotUsed> |
fromIterator(Creator<java.util.Iterator<O>> f)
Helper to create
Source from Iterator . |
<O> Source<O,NotUsed> |
fromPublisher(org.reactivestreams.Publisher<O> publisher)
Helper to create
Source from Publisher . |
<T,M> Source<T,java.util.concurrent.CompletionStage<M>> |
lazily(Creator<Source<T,M>> create)
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 the
create factory is never called and the materialized CompletionStage is failed. |
<T> Source<T,java.util.concurrent.CompletableFuture<java.util.Optional<T>>> |
maybe()
Create a
Source which materializes a CompletableFuture which controls what element
will be emitted by the Source. |
<T> Source<T,SourceQueueWithComplete<T>> |
queue(int bufferSize,
OverflowStrategy overflowStrategy)
Creates a
Source that is materialized as an SourceQueue . |
Source<java.lang.Integer,NotUsed> |
range(int start,
int end)
Creates
Source that represents integer values in range ''[start;end]'', step equals to 1. |
Source<java.lang.Integer,NotUsed> |
range(int start,
int end,
int step)
Creates
Source that represents integer values in range ''[start;end]'', with the given step. |
<T> Source<T,NotUsed> |
repeat(T element)
Create a
Source that will continually emit the given element. |
<T> Source<T,NotUsed> |
single(T element)
Create a
Source with one element. |
<O> Source<O,Cancellable> |
tick(scala.concurrent.duration.FiniteDuration initialDelay,
scala.concurrent.duration.FiniteDuration interval,
O tick)
Elements are emitted periodically with the specified interval.
|
<S,E> Source<E,NotUsed> |
unfold(S s,
Function<S,java.util.Optional<Pair<S,E>>> f)
Create a
Source that will unfold a value of type S into
a pair of the next state S and output elements of type E . |
<S,E> Source<E,NotUsed> |
unfoldAsync(S s,
Function<S,java.util.concurrent.CompletionStage<java.util.Optional<Pair<S,E>>>> f)
Same as
unfold , but uses an async function to generate the next state-element tuple. |
<T,S> Source<T,NotUsed> |
unfoldResource(Creator<S> create,
Function<S,java.util.Optional<T>> read,
Procedure<S> close)
Start a new
Source from some resource which can be opened, read and closed. |
<T,S> Source<T,NotUsed> |
unfoldResourceAsync(Creator<java.util.concurrent.CompletionStage<S>> create,
Function<S,java.util.concurrent.CompletionStage<java.util.Optional<T>>> read,
Function<S,java.util.concurrent.CompletionStage<Done>> close)
Start a new
Source from some resource which can be opened, read and closed. |
<T> Source<java.util.List<T>,NotUsed> |
zipN(java.util.List<Source<T,?>> sources)
Combine the elements of multiple streams into a stream of lists.
|
<T,O> Source<O,NotUsed> |
zipWithN(Function<java.util.List<T>,O> zipper,
java.util.List<Source<T,?>> sources) |
public static final Source$ MODULE$
public <O> Source<O,NotUsed> empty()
Source
with no elements, i.e. an empty stream that is completed immediately
for every connected Sink
.public <T> Source<T,java.util.concurrent.CompletableFuture<java.util.Optional<T>>> maybe()
Source
which materializes a 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 returned source will terminate with that error.
If the downstream of this source cancels before the promise has been completed, then the promise will be completed
with an empty Optional.public <O> Source<O,NotUsed> fromPublisher(org.reactivestreams.Publisher<O> publisher)
Source
from Publisher
.
Construct a transformation starting with given publisher. The transformation steps
are executed by a series of Processor
instances
that mediate the flow of elements downstream and the propagation of
back-pressure upstream.
publisher
- (undocumented)public <O> Source<O,NotUsed> fromIterator(Creator<java.util.Iterator<O>> f)
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
the next()
method. Elements are pulled out of the iterator
in accordance with the demand coming from the downstream transformation
steps.
f
- (undocumented)public <O> Source<O,NotUsed> cycle(Creator<java.util.Iterator<O>> f)
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.
f
- (undocumented)public <O> Source<O,NotUsed> from(java.lang.Iterable<O> iterable)
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 given Iterable
. 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 a Source
. Otherwise the stream may fail with
ConcurrentModificationException
or other more subtle errors may occur.
iterable
- (undocumented)public Source<java.lang.Integer,NotUsed> range(int start, int end)
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 Scala Source(1 to N)
Uses scala.collection.immutable.Range.inclusive(Int, Int)
internally
start
- (undocumented)end
- (undocumented)scala.collection.immutable.Range.inclusive(Int, Int)
public Source<java.lang.Integer,NotUsed> range(int start, int end, int step)
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 Scala Source(1 to N)
Uses scala.collection.immutable.Range.inclusive(Int, Int, Int)
internally
start
- (undocumented)end
- (undocumented)step
- (undocumented)scala.collection.immutable.Range.inclusive(Int, Int, Int)
public <O> Source<O,NotUsed> fromFuture(scala.concurrent.Future<O> future)
Source
from the given Future
. The stream will consist of
one element when the Future
is completed with a successful value, which
may happen before or after materializing the Flow
.
The stream terminates with a failure if the Future
is completed with a failure.future
- (undocumented)public <O> Source<O,NotUsed> fromCompletionStage(java.util.concurrent.CompletionStage<O> future)
Source
from the given CompletionStage
. The stream will consist of
one element when the CompletionStage
is completed with a successful value, which
may happen before or after materializing the Flow
.
The stream terminates with a failure if the CompletionStage
is completed with a failure.future
- (undocumented)public <O> Source<O,Cancellable> tick(scala.concurrent.duration.FiniteDuration initialDelay, scala.concurrent.duration.FiniteDuration interval, O tick)
initialDelay
- (undocumented)interval
- (undocumented)tick
- (undocumented)public <T> Source<T,NotUsed> single(T element)
Source
with one element.
Every connected Sink
of this stream will see an individual stream consisting of one element.element
- (undocumented)public <T> Source<T,NotUsed> repeat(T element)
Source
that will continually emit the given element.element
- (undocumented)public <S,E> Source<E,NotUsed> unfold(S s, Function<S,java.util.Optional<Pair<S,E>>> f)
Source
that will unfold a value of type S
into
a pair of the next state S
and output elements of type E
.s
- (undocumented)f
- (undocumented)public <S,E> Source<E,NotUsed> unfoldAsync(S s, Function<S,java.util.concurrent.CompletionStage<java.util.Optional<Pair<S,E>>>> f)
unfold
, but uses an async function to generate the next state-element tuple.s
- (undocumented)f
- (undocumented)public <T> Source<T,NotUsed> failed(java.lang.Throwable cause)
Source
that immediately ends the stream with the cause
failure to every connected Sink
.cause
- (undocumented)public <T,M> Source<T,java.util.concurrent.CompletionStage<M>> lazily(Creator<Source<T,M>> create)
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 the
create
factory is never called and the materialized CompletionStage
is failed.create
- (undocumented)public <T> Source<T,org.reactivestreams.Subscriber<T>> asSubscriber()
Source
that is materialized as a Subscriber
public <T> Source<T,ActorRef> actorPublisher(Props props)
Source
that is materialized to an ActorRef
which points to an Actor
created according to the passed in Props
. Actor created by the props
should
be ActorPublisher
.props
- (undocumented)public <T> Source<T,ActorRef> actorRef(int bufferSize, OverflowStrategy overflowStrategy)
Source
that is materialized as an 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 OverflowStrategy
it might drop elements if
there is no space available in the buffer.
The strategy akka.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. When bufferSize
is 0 the overflowStrategy
does not matter. An async boundary is added after
this Source; as such, it is never safe to assume the downstream will always generate demand.
The stream can be completed successfully by sending the actor reference a Status.Success
(whose content will be ignored) in which case already buffered elements will be signaled before signaling
completion, or by sending PoisonPill
in which case completion will be signaled immediately.
The stream can be completed with failure by sending a Status.Failure
to the
actor reference. In case the Actor is still draining its internal buffer (after having received
a Status.Success
) before signaling completion and it receives a 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.
See also akka.stream.javadsl.Source.queue
.
bufferSize
- The size of the buffer in element countoverflowStrategy
- Strategy that is used when incoming elements cannot fit inside the bufferpublic <T,M> Source<T,M> fromGraph(Graph<SourceShape<T>,M> g)
g
- (undocumented)public <T,U> Source<U,NotUsed> combine(Source<T,?> first, Source<T,?> second, java.util.List<Source<T,?>> rest, Function<java.lang.Integer,? extends Graph<UniformFanInShape<T,U>,NotUsed>> strategy)
Merge
or Concat
and returns Source
.first
- (undocumented)second
- (undocumented)rest
- (undocumented)strategy
- (undocumented)public <T> Source<java.util.List<T>,NotUsed> zipN(java.util.List<Source<T,?>> sources)
sources
- (undocumented)public <T,O> Source<O,NotUsed> zipWithN(Function<java.util.List<T>,O> zipper, java.util.List<Source<T,?>> sources)
public <T> Source<T,SourceQueueWithComplete<T>> queue(int bufferSize, OverflowStrategy overflowStrategy)
Source
that is materialized as an SourceQueue
.
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 OverflowStrategy
it might drop elements if
there is no space available in the buffer.
Acknowledgement mechanism is available.
akka.stream.javadsl.SourceQueue.offer
returns CompletionStage
which completes with
QueueOfferResult.enqueued
if element was added to buffer or sent downstream. It completes with
QueueOfferResult.dropped
if element was dropped. Can also complete with QueueOfferResult.Failure
-
when stream failed or QueueOfferResult.QueueClosed
when downstream is completed.
The strategy akka.stream.OverflowStrategy.backpressure
will not complete last offer():CompletionStage
call when buffer is full.
You can watch accessibility of stream with akka.stream.javadsl.SourceQueue.watchCompletion
.
It returns future that completes with success when stream is completed or fail 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.
SourceQueue that current source is materialized to is for single thread usage only.
bufferSize
- size of buffer in element countoverflowStrategy
- Strategy that is used when incoming elements cannot fit inside the bufferpublic <T,S> Source<T,NotUsed> unfoldResource(Creator<S> create, Function<S,java.util.Optional<T>> read, Procedure<S> close)
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 by create
or close
will fail the stream.
Restart
supervision strategy will close and create blocking IO again. Default strategy is Stop
which means
that stream will be terminated on error in read
function by default.
You can configure the default dispatcher for this Source by changing the akka.stream.blocking-io-dispatcher
or
set it for a given Source by using ActorAttributes
.
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 resourcepublic <T,S> Source<T,NotUsed> unfoldResourceAsync(Creator<java.util.concurrent.CompletionStage<S>> create, Function<S,java.util.concurrent.CompletionStage<java.util.Optional<T>>> read, Function<S,java.util.concurrent.CompletionStage<Done>> close)
Source
from some resource which can be opened, read and closed.
It's similar to unfoldResource
but takes functions that return CompletionStage
instead of plain values.
You can use the supervision strategy to handle exceptions for read
function or failures of produced Futures
.
All exceptions thrown by create
or close
as well as fails of returned futures will fail the stream.
Restart
supervision strategy will close and create resource. Default strategy is Stop
which means
that stream will be terminated on error in read
function (or future) by default.
You can configure the default dispatcher for this Source by changing the akka.stream.blocking-io-dispatcher
or
set it for a given Source by using ActorAttributes
.
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