Class ActorFlow$

java.lang.Object
org.apache.pekko.stream.typed.scaladsl.ActorFlow$

public class ActorFlow$ extends Object
Collection of Flows aimed at integrating with typed Actors.
  • Field Details

    • MODULE$

      public static final ActorFlow$ MODULE$
      Static reference to the singleton instance of this Scala object.
  • Constructor Details

    • ActorFlow$

      public ActorFlow$()
  • Method Details

    • ask

      public <I, Q, A> Flow<I,A,NotUsed> ask(ActorRef<Q> ref, scala.Function2<I,ActorRef<A>,Q> makeMessage, Timeout timeout)
      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 TimeoutException.

      Do not forget to include the expected response type in the method call, like so:

      
       flow.via(ActorFlow.ask[String, Asking, Reply](ref)((el, replyTo) => Asking(el, replyTo)))
      
       // or even:
       flow.via(ActorFlow.ask[String, Asking, Reply](ref)(Asking(_, _)))
       

      otherwise Nothing will be assumed, which is most likely not what you want.

      Defaults to parallelism of 2 messages in flight, since while one ask message may be being worked on, the second one still be in the mailbox, so defaulting to sending the second one a bit earlier than when first ask has replied maintains a slightly healthier throughput.

      The operator fails with an pekko.stream.WatchedActorTerminatedException if the target actor is terminated, or with an TimeoutException in case the ask exceeds the timeout passed in.

      Adheres to the ActorAttributes.SupervisionStrategy attribute.

      '''Emits when''' the futures (in submission order) created by the ask pattern internally are completed

      '''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

    • ask

      public <I, Q, A> Flow<I,A,NotUsed> ask(int parallelism, ActorRef<Q> ref, scala.Function2<I,ActorRef<A>,Q> makeMessage, Timeout timeout)
      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 TimeoutException.

      Do not forget to include the expected response type in the method call, like so:

      
       flow.via(ActorFlow.ask[String, Asking, Reply](parallelism = 4)(ref, (el, replyTo) => Asking(el, replyTo)))
      
       // or even:
       flow.via(ActorFlow.ask[String, Asking, Reply](parallelism = 4)(ref, Asking(_, _)))
       

      otherwise Nothing will be assumed, which is most likely not what you want.

      The operator fails with an pekko.stream.WatchedActorTerminatedException if the target actor is terminated, or with an TimeoutException in case the ask exceeds the timeout passed in.

      Adheres to the ActorAttributes.SupervisionStrategy attribute.

      '''Emits when''' the futures (in submission order) created by the ask pattern internally are completed

      '''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

    • askWithStatus

      public <I, Q, A> Flow<I,A,NotUsed> askWithStatus(ActorRef<Q> ref, scala.Function2<I,ActorRef<StatusReply<A>>,Q> makeMessage, Timeout timeout)
      Use for messages whose response is known to be a pekko.pattern.StatusReply. When a pekko.pattern.StatusReply#success response arrives the future is completed with the wrapped value, if a pekko.pattern.StatusReply#error arrives the future is instead failed.
    • askWithStatus

      public <I, Q, A> Flow<I,A,NotUsed> askWithStatus(int parallelism, ActorRef<Q> ref, scala.Function2<I,ActorRef<StatusReply<A>>,Q> makeMessage, Timeout timeout)
      Use for messages whose response is known to be a pekko.pattern.StatusReply. When a pekko.pattern.StatusReply#success response arrives the future is completed with the wrapped value, if a pekko.pattern.StatusReply#error arrives the future is instead failed.
    • askWithContext

      public <I, Q, A, Ctx> Flow<scala.Tuple2<I,Ctx>,scala.Tuple2<A,Ctx>,NotUsed> askWithContext(ActorRef<Q> ref, scala.Function2<I,ActorRef<A>,Q> makeMessage, Timeout timeout)
      Use the ask pattern to send a request-reply message to the target ref actor without including the context.
    • askWithContext

      public <I, Q, A, Ctx> Flow<scala.Tuple2<I,Ctx>,scala.Tuple2<A,Ctx>,NotUsed> askWithContext(int parallelism, ActorRef<Q> ref, scala.Function2<I,ActorRef<A>,Q> makeMessage, Timeout timeout)
      Use the ask pattern to send a request-reply message to the target ref actor without including the context.
    • askWithStatusAndContext

      public <I, Q, A, Ctx> Flow<scala.Tuple2<I,Ctx>,scala.Tuple2<A,Ctx>,NotUsed> askWithStatusAndContext(ActorRef<Q> ref, scala.Function2<I,ActorRef<StatusReply<A>>,Q> makeMessage, Timeout timeout)
      Use for messages whose response is known to be a pekko.pattern.StatusReply. When a pekko.pattern.StatusReply#success response arrives the future is completed with the wrapped value, if a pekko.pattern.StatusReply#error arrives the future is instead failed.
    • askWithStatusAndContext

      public <I, Q, A, Ctx> Flow<scala.Tuple2<I,Ctx>,scala.Tuple2<A,Ctx>,NotUsed> askWithStatusAndContext(int parallelism, ActorRef<Q> ref, scala.Function2<I,ActorRef<StatusReply<A>>,Q> makeMessage, Timeout timeout)
      Use for messages whose response is known to be a pekko.pattern.StatusReply. When a pekko.pattern.StatusReply#success response arrives the future is completed with the wrapped value, if a pekko.pattern.StatusReply#error arrives the future is instead failed.