Class AskPattern
java.lang.Object
org.apache.pekko.actor.typed.javadsl.AskPattern
The ask-pattern implements the initiator side of a request–reply protocol.
Note that if you are inside of an actor you should prefer ActorContext.ask
as that provides better safety.
The party that asks may be within or without an Actor, since the
implementation will fabricate a (hidden) ActorRef
that is bound to a
CompletableFuture
. This ActorRef will need to be injected in the
message that is sent to the target Actor in order to function as a reply-to
address, therefore the argument to the ask method is not the message itself
but a function that given the reply-to address will create the message.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <Req,
Res> CompletionStage<Res> ask
(RecipientRef<Req> actor, Function<ActorRef<Res>, Req> messageFactory, Duration timeout, Scheduler scheduler) static <Req,
Res> CompletionStage<Res> askWithStatus
(RecipientRef<Req> actor, Function<ActorRef<StatusReply<Res>>, Req> messageFactory, Duration timeout, Scheduler scheduler) The same as<Req,Res>ask(org.apache.pekko.actor.typed.RecipientRef<Req>,org.apache.pekko.japi.function.Function<org.apache.pekko.actor.typed.ActorRef<Res>,Req>,java.time.Duration,org.apache.pekko.actor.typed.Scheduler)
but only for requests that result in a response of typepekko.pattern.StatusReply
.
-
Constructor Details
-
AskPattern
public AskPattern()
-
-
Method Details
-
ask
public static <Req,Res> CompletionStage<Res> ask(RecipientRef<Req> actor, Function<ActorRef<Res>, Req> messageFactory, Duration timeout, Scheduler scheduler) -
askWithStatus
public static <Req,Res> CompletionStage<Res> askWithStatus(RecipientRef<Req> actor, Function<ActorRef<StatusReply<Res>>, Req> messageFactory, Duration timeout, Scheduler scheduler) The same as<Req,Res>ask(org.apache.pekko.actor.typed.RecipientRef<Req>,org.apache.pekko.japi.function.Function<org.apache.pekko.actor.typed.ActorRef<Res>,Req>,java.time.Duration,org.apache.pekko.actor.typed.Scheduler)
but only for requests that result in a response of typepekko.pattern.StatusReply
. If the response is apekko.pattern.StatusReply#success
the returned future is completed successfully with the wrapped response. If the status response is apekko.pattern.StatusReply#error
the returned future will be failed with the exception in the error (normally apekko.pattern.StatusReply.ErrorMessage
).
-