Class ActorSource
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionactorRef(Predicate<T> completionMatcher, Function<T, Optional<Throwable>> failureMatcher, int bufferSize, OverflowStrategy overflowStrategy) Creates aSourcethat is materialized as anpekko.actor.typed.ActorRef.actorRefWithBackpressure(ActorRef<Ack> ackTo, Ack ackMessage, Function<T, Optional<CompletionStrategy>> completionMatcher, Function<T, Optional<Throwable>> failureMatcher) Creates aSourcethat is materialized as anpekko.actor.ActorRef.
-
Constructor Details
-
ActorSource
public ActorSource()
-
-
Method Details
-
actorRef
public static <T> Source<T,ActorRef<T>> actorRef(Predicate<T> completionMatcher, Function<T, Optional<Throwable>> failureMatcher, int bufferSize, OverflowStrategy overflowStrategy) Creates aSourcethat is materialized as anpekko.actor.typed.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.OverflowStrategyit might drop elements if there is no space available in the buffer.The strategy
pekko.stream.OverflowStrategy.backpressureis 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
bufferSizeof 0 and then received messages are dropped if there is no demand from downstream. WhenbufferSizeis 0 theoverflowStrategydoes 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, or by sendingpekko.actor.PoisonPillin which case completion will be signaled immediately.The stream can be completed with failure by sending a
pekko.actor.Status.Failureto the actor reference. In case the Actor is still draining its internal buffer (after having received apekko.actor.Status.Success) before signaling completion and it receives apekko.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.
See also
pekko.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, Optional<CompletionStrategy>> completionMatcher, Function<T, Optional<Throwable>> failureMatcher) Creates aSourcethat is materialized as anpekko.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 by sending a message that is matched by
completionMatcherwhich decides if the stream is to drained before completion or should complete immediately.A message that is matched by
failureMatcherfails the stream. The extractedThrowablewill 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.
-