+str #18142 ask pattern integration for akka streams

progressed with cleanup, removing the same thread exec context is
weird... causes issues :-/ Need to debug more, could be that some race
also exists in mapAsync then :\

WIP

finish ask impl via watch stage

mima

consistency spec

fix paradox, and fix adding ask/watch to javadsl source

follow up review
This commit is contained in:
Konrad Malawski 2018-01-14 00:21:00 +09:00 committed by Konrad `ktoso` Malawski
parent 5040ce82f1
commit 4714f16dcf
18 changed files with 643 additions and 47 deletions

View file

@ -6,7 +6,7 @@ package akka.stream.javadsl
import java.util
import java.util.Optional
import akka.util.ConstantFun
import akka.util.{ ConstantFun, Timeout }
import akka.{ Done, NotUsed }
import akka.actor.{ ActorRef, Cancellable, Props }
import akka.event.LoggingAdapter
@ -1253,6 +1253,52 @@ final class Source[+Out, +Mat](delegate: scaladsl.Source[Out, Mat]) extends Grap
def mapAsyncUnordered[T](parallelism: Int, f: function.Function[Out, CompletionStage[T]]): javadsl.Source[T, Mat] =
new Source(delegate.mapAsyncUnordered(parallelism)(x f(x).toScala))
/**
* Use the `ask` pattern to send a request-reply message to the target `ref` actor.
* If any of the asks times out it will fail the stream with a [[akka.pattern.AskTimeoutException]].
*
* The `mapTo` class parameter is used to cast the incoming responses to the expected response type.
*
* Similar to the plain ask pattern, the target actor is allowed to reply with `akka.util.Status`.
* An `akka.util.Status#Failure` will cause the stage to fail with the cause carried in the `Failure` message.
*
* Parallelism limits the number of how many asks can be "in flight" at the same time.
* Please note that the elements emitted by this stage are in-order with regards to the asks being issued
* (i.e. same behaviour as mapAsync).
*
* The stage fails with an [[akka.stream.WatchedActorTerminatedException]] if the target actor is terminated.
*
* Adheres to the [[ActorAttributes.SupervisionStrategy]] attribute.
*
* '''Emits when''' any of the CompletionStages returned by the provided function complete
*
* '''Backpressures when''' the number of futures reaches the configured parallelism and the downstream backpressures
*
* '''Completes when''' upstream completes and all futures have been completed and all elements have been emitted
*
* '''Fails when''' the passed in actor terminates, or a timeout is exceeded in any of the asks performed
*
* '''Cancels when''' downstream cancels
*/
def ask[S](parallelism: Int, ref: ActorRef, mapTo: Class[S], timeout: Timeout): javadsl.Source[S, Mat] =
new Source(delegate.ask[S](parallelism)(ref)(timeout, ClassTag(mapTo)))
/**
* The stage fails with an [[akka.stream.WatchedActorTerminatedException]] if the target actor is terminated.
*
* '''Emits when''' upstream emits
*
* '''Backpressures when''' downstream backpressures
*
* '''Completes when''' upstream completes
*
* '''Fails when''' the watched actor terminates
*
* '''Cancels when''' downstream cancels
*/
def watch(ref: ActorRef): javadsl.Source[Out, Mat] =
new Source(delegate.watch(ref))
/**
* Only pass on those elements that satisfy the given predicate.
*