GrapheStage implementation for actorRef source (#25324) (#26054)

* Adds internal access to materializer before initialization (#25324)

* Implements new actorRef source based on graph stage  (#25324)

* Removes obsolete actorRef source (#25324)

* Improves backwards compatibility with old implementation (#25324)

* Removes dedicated new subclass for materializer access again  (#25324)

* Improves implementation (#25324)

* Finalizes implementation (#25324)

* Small improvements to API and documentation (#25324)

* Completion strategy as a replacement for poison pill (#25324)

* Adding more tests and updating the documentation (#25324)
This commit is contained in:
Nicolas Vollmar 2019-03-27 14:16:38 +01:00 committed by Patrik Nordwall
parent 39c06c7c34
commit c9b3f1de6d
15 changed files with 328 additions and 201 deletions

View file

@ -508,20 +508,15 @@ object Source {
* @param overflowStrategy Strategy that is used when incoming elements cannot fit inside the buffer
*/
@InternalApi private[akka] def actorRef[T](
completionMatcher: PartialFunction[Any, Unit],
completionMatcher: PartialFunction[Any, CompletionStrategy],
failureMatcher: PartialFunction[Any, Throwable],
bufferSize: Int,
overflowStrategy: OverflowStrategy): Source[T, ActorRef] = {
require(bufferSize >= 0, "bufferSize must be greater than or equal to 0")
require(!overflowStrategy.isBackpressure, "Backpressure overflowStrategy not supported")
fromGraph(
new ActorRefSource(
completionMatcher,
failureMatcher,
bufferSize,
overflowStrategy,
DefaultAttributes.actorRefSource,
shape("ActorRefSource")))
Source
.fromGraph(new ActorRefSource(bufferSize, overflowStrategy, completionMatcher, failureMatcher))
.withAttributes(DefaultAttributes.actorRefSource)
}
/**
@ -539,9 +534,11 @@ object Source {
* 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 [[akka.actor.Status.Success]]
* (whose content will be ignored) in which case already buffered elements will be signaled before signaling
* completion, or by sending [[akka.actor.PoisonPill]] in which case completion will be signaled immediately.
* The stream can be completed successfully by sending the actor reference a [[akka.actor.Status.Success]].
* If the content is [[akka.stream.CompletionStrategy.immediately]] the completion will be signaled immidiately,
* otherwise if the content is [[akka.stream.CompletionStrategy.draining]] (or anything else)
* already buffered elements will be signaled before siganling completion.
* Sending [[akka.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 [[akka.actor.Status.Failure]] to the
* actor reference. In case the Actor is still draining its internal buffer (after having received
@ -559,9 +556,10 @@ object Source {
*/
def actorRef[T](bufferSize: Int, overflowStrategy: OverflowStrategy): Source[T, ActorRef] =
actorRef({
case akka.actor.Status.Success =>
case akka.actor.Status.Success(_) =>
}, { case akka.actor.Status.Failure(cause) => cause }, bufferSize, overflowStrategy)
case akka.actor.Status.Success(s: CompletionStrategy) => s
case akka.actor.Status.Success(_) => CompletionStrategy.Draining
case akka.actor.Status.Success => CompletionStrategy.Draining
}, { case akka.actor.Status.Failure(cause) => cause }, bufferSize, overflowStrategy)
/**
* Combines several sources with fan-in strategy like `Merge` or `Concat` and returns `Source`.