Class AskPattern.Askable<Req>
- java.lang.Object
-
- scala.AnyVal
-
- akka.actor.typed.scaladsl.AskPattern.Askable<Req>
-
- Type Parameters:
Req
- The request protocol, what the other actor accepts
- Enclosing class:
- AskPattern
public static final class AskPattern.Askable<Req> extends scala.AnyVal
-
-
Constructor Summary
Constructors Constructor Description Askable(RecipientRef<Req> ref)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <Res> scala.concurrent.Future<Res>
$qmark(scala.Function1<ActorRef<Res>,Req> replyTo, Timeout timeout, Scheduler scheduler)
The ask-pattern implements the initiator side of a request–reply protocol.<Res> scala.concurrent.Future<Res>
ask(scala.Function1<ActorRef<Res>,Req> replyTo, Timeout timeout, Scheduler scheduler)
The ask-pattern implements the initiator side of a request–reply protocol.<Res> scala.concurrent.Future<Res>
askWithStatus(scala.Function1<ActorRef<StatusReply<Res>>,Req> replyTo, Timeout timeout, Scheduler scheduler)
The same as<Res>ask(scala.Function1<akka.actor.typed.ActorRef<Res>,Req>,akka.util.Timeout,akka.actor.typed.Scheduler)
but only for requests that result in a response of typeStatusReply
.boolean
equals(java.lang.Object x$1)
int
hashCode()
RecipientRef<Req>
ref()
-
-
-
Constructor Detail
-
Askable
public Askable(RecipientRef<Req> ref)
-
-
Method Detail
-
ref
public RecipientRef<Req> ref()
-
$qmark
public <Res> scala.concurrent.Future<Res> $qmark(scala.Function1<ActorRef<Res>,Req> replyTo, Timeout timeout, Scheduler scheduler)
The ask-pattern implements the initiator side of a request–reply protocol. The?
operator is pronounced as "ask" (and a convenience symbolic operation kept since the previous ask API, if unsure which one to use, prefer the non-symbolic method as it leads to fewer surprises with the scope of thereplyTo
function)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 aPromise
. 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 /?
operator is not the message itself but a function that given the reply-to address will create the message.case class Request(msg: String, replyTo: ActorRef[Reply]) case class Reply(msg: String) implicit val system = ... implicit val timeout = Timeout(3.seconds) val target: ActorRef[Request] = ... val f: Future[Reply] = target ? (replyTo => Request("hello", replyTo))
Note: it is preferrable to use the non-symbolic ask method as it easier allows for wildcards for the
replyTo: ActorRef
.
-
ask
public <Res> scala.concurrent.Future<Res> ask(scala.Function1<ActorRef<Res>,Req> replyTo, Timeout timeout, Scheduler scheduler)
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 aPromise
. 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 /?
operator is not the message itself but a function that given the reply-to address will create the message.case class Request(msg: String, replyTo: ActorRef[Reply]) case class Reply(msg: String) implicit val system = ... implicit val timeout = Timeout(3.seconds) val target: ActorRef[Request] = ... val f: Future[Reply] = target.ask(replyTo => Request("hello", replyTo)) // alternatively val f2: Future[Reply] = target.ask(Request("hello", _))
-
askWithStatus
public <Res> scala.concurrent.Future<Res> askWithStatus(scala.Function1<ActorRef<StatusReply<Res>>,Req> replyTo, Timeout timeout, Scheduler scheduler)
The same as<Res>ask(scala.Function1<akka.actor.typed.ActorRef<Res>,Req>,akka.util.Timeout,akka.actor.typed.Scheduler)
but only for requests that result in a response of typeStatusReply
. If the response is aakka.pattern.StatusReply.Success
the returned future is completed successfully with the wrapped response. If the status response is aakka.pattern.StatusReply.Error
the returned future will be failed with the exception in the error (normally aStatusReply.ErrorMessage
).
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object x$1)
- Overrides:
equals
in classjava.lang.Object
-
-