Define ! and ? in EntityRef. ticket #24922
This commit is contained in:
parent
216025b03f
commit
e8a955cdef
1 changed files with 38 additions and 30 deletions
|
|
@ -253,9 +253,45 @@ object EntityTypeKey {
|
|||
/**
|
||||
* Send a message to the entity referenced by this EntityRef using *at-most-once*
|
||||
* messaging semantics.
|
||||
*
|
||||
* Example usage:
|
||||
* {{{
|
||||
* val target: EntityRef[String] = ...
|
||||
* target.tell("Hello")
|
||||
* }}}
|
||||
*/
|
||||
def tell(msg: A): Unit
|
||||
|
||||
/**
|
||||
* Send a message to the entity referenced by this EntityRef using *at-most-once*
|
||||
* messaging semantics.
|
||||
*
|
||||
* Example usage:
|
||||
* {{{
|
||||
* val target: EntityRef[String] = ...
|
||||
* target ! "Hello"
|
||||
* }}}
|
||||
*/
|
||||
def !(msg: A): Unit = this.tell(msg)
|
||||
|
||||
/**
|
||||
* Allows to "ask" the [[EntityRef]] for a reply.
|
||||
* See [[akka.actor.typed.scaladsl.AskPattern]] for a complete write-up of this pattern
|
||||
*
|
||||
* Example usage:
|
||||
* {{{
|
||||
* case class Request(msg: String, replyTo: ActorRef[Reply])
|
||||
* case class Reply(msg: String)
|
||||
*
|
||||
* implicit val timeout = Timeout(3.seconds)
|
||||
* val target: EntityRef[Request] = ...
|
||||
* val f: Future[Reply] = target.ask(Request("hello", _))
|
||||
* }}}
|
||||
*
|
||||
* Please note that an implicit [[akka.util.Timeout]] and [[akka.actor.Scheduler]] must be available to use this pattern.
|
||||
*/
|
||||
def ask[U](f: ActorRef[U] ⇒ A)(implicit timeout: Timeout, scheduler: Scheduler): Future[U]
|
||||
|
||||
/**
|
||||
* Allows to "ask" the [[EntityRef]] for a reply.
|
||||
* See [[akka.actor.typed.scaladsl.AskPattern]] for a complete write-up of this pattern
|
||||
|
|
@ -272,39 +308,11 @@ object EntityTypeKey {
|
|||
*
|
||||
* Please note that an implicit [[akka.util.Timeout]] and [[akka.actor.Scheduler]] must be available to use this pattern.
|
||||
*/
|
||||
def ask[U](f: ActorRef[U] ⇒ A)(implicit timeout: Timeout, scheduler: Scheduler): Future[U]
|
||||
def ?[U](message: ActorRef[U] ⇒ A)(implicit timeout: Timeout, scheduler: Scheduler): Future[U] =
|
||||
this.ask(message)(timeout, scheduler)
|
||||
|
||||
}
|
||||
|
||||
object EntityRef {
|
||||
implicit final class EntityRefOps[A](val ref: EntityRef[A]) extends AnyVal {
|
||||
/**
|
||||
* Send a message to the Actor referenced by this ActorRef using *at-most-once*
|
||||
* messaging semantics.
|
||||
*/
|
||||
def !(msg: A): Unit = ref.tell(msg)
|
||||
|
||||
/**
|
||||
* Allows to "ask" the [[EntityRef]] for a reply.
|
||||
* See [[akka.actor.typed.scaladsl.AskPattern]] for a complete write-up of this pattern
|
||||
*
|
||||
* Example usage:
|
||||
* {{{
|
||||
* case class Request(msg: String, replyTo: ActorRef[Reply])
|
||||
* case class Reply(msg: String)
|
||||
*
|
||||
* implicit val timeout = Timeout(3.seconds)
|
||||
* val target: EntityRef[Request] = ...
|
||||
* val f: Future[Reply] = target ? (Request("hello", _))
|
||||
* }}}
|
||||
*
|
||||
* Please note that an implicit [[akka.util.Timeout]] and [[akka.actor.Scheduler]] must be available to use this pattern.
|
||||
*/
|
||||
def ?[U](message: ActorRef[U] ⇒ A)(implicit timeout: Timeout, scheduler: Scheduler): Future[U] =
|
||||
ref.ask(message)(timeout, scheduler)
|
||||
}
|
||||
}
|
||||
|
||||
object ClusterShardingSetup {
|
||||
def apply[T <: Extension](createExtension: ActorSystem[_] ⇒ ClusterSharding): ClusterShardingSetup =
|
||||
new ClusterShardingSetup(new java.util.function.Function[ActorSystem[_], ClusterSharding] {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue