Class ActorSource
- java.lang.Object
-
- akka.stream.typed.javadsl.ActorSource
-
public class ActorSource extends java.lang.Object
Collection of Sources aimed at integrating with typed Actors.
-
-
Constructor Summary
Constructors Constructor Description ActorSource()
-
Method Summary
All Methods Static Methods Concrete Methods Deprecated Methods Modifier and Type Method Description static <T> Source<T,ActorRef<T>>
actorRef(java.util.function.Predicate<T> completionMatcher, Function<T,java.util.Optional<java.lang.Throwable>> failureMatcher, int bufferSize, OverflowStrategy overflowStrategy)
Creates aSource
that is materialized as anActorRef
.static <T,Ack>
Source<T,ActorRef<T>>actorRefWithAck(ActorRef<Ack> ackTo, Ack ackMessage, Function<T,java.util.Optional<CompletionStrategy>> completionMatcher, Function<T,java.util.Optional<java.lang.Throwable>> failureMatcher)
Deprecated.Use actorRefWithBackpressure insteadstatic <T,Ack>
Source<T,ActorRef<T>>actorRefWithBackpressure(ActorRef<Ack> ackTo, Ack ackMessage, Function<T,java.util.Optional<CompletionStrategy>> completionMatcher, Function<T,java.util.Optional<java.lang.Throwable>> failureMatcher)
Creates aSource
that is materialized as anActorRef
.
-
-
-
Method Detail
-
actorRef
public static <T> Source<T,ActorRef<T>> actorRef(java.util.function.Predicate<T> completionMatcher, Function<T,java.util.Optional<java.lang.Throwable>> failureMatcher, int bufferSize, OverflowStrategy overflowStrategy)
Creates aSource
that is materialized as anActorRef
. 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. WhenbufferSize
is 0 theoverflowStrategy
does not matter.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 sendingPoisonPill
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 aStatus.Success
) before signaling completion and it receives aStatus.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
.- Parameters:
bufferSize
- The size of the buffer in element countoverflowStrategy
- Strategy that is used when incoming elements cannot fit inside the buffer
-
actorRefWithBackpressure
public static <T,Ack> Source<T,ActorRef<T>> actorRefWithBackpressure(ActorRef<Ack> ackTo, Ack ackMessage, Function<T,java.util.Optional<CompletionStrategy>> completionMatcher, Function<T,java.util.Optional<java.lang.Throwable>> failureMatcher)
Creates aSource
that is materialized as anActorRef
. 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 by sending a message that is matched by
completionMatcher
which decides if the stream is to drained before completion or should complete immediately.A message that is matched by
failureMatcher
fails the stream. The extractedThrowable
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.
-
actorRefWithAck
public static <T,Ack> Source<T,ActorRef<T>> actorRefWithAck(ActorRef<Ack> ackTo, Ack ackMessage, Function<T,java.util.Optional<CompletionStrategy>> completionMatcher, Function<T,java.util.Optional<java.lang.Throwable>> failureMatcher)
Deprecated.Use actorRefWithBackpressure insteadCreates aSource
that is materialized as anActorRef
. 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 extractedThrowable
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.
-
-