[Akka Typed] How Receptionist is going to work?

117 views
Skip to first unread message

Leszek Gruchała

unread,
Apr 23, 2015, 5:36:41 PM4/23/15
to akka...@googlegroups.com
Hi,
I would like to better understand how a Receptionist actor is going to work.

        val receptionist: ActorRef[Command] = ctx.spawn(Props(Receptionist.behavior), "receptionist")

        receptionist
! Register(MySystem, someActor)([1])
        receptionist
! Find(MySystem)([2])


[1] why it is expected to pass to “replyTo” argument already registered (ActorRef[Registered[MyCommand]])?

[2 ]If I want to find an actor I would like to have ask pattern like
val actor = receptionist ? Find(MySystem)(“some unique name”)

but now I am expected to pass type ActorRef[Listing[MyCommand]] which looks like a reply from a Find command.
What I get now is a list of actors of given type. Does it mean, that if I want to look for one specific actor I have to define multiple ServiceKey objects?

How to obtain an Actor to work with during message processing? Can it be passed only directly to behavior or through the message?
I can define behavior of type ActorRef[Registered[MyCommand]] but it cannot be at the same type ActorRef[Listing[MyCommand]],
so one actor cannot register and find actors.

Thank you,
Leszek

Leszek Gruchała

unread,
Apr 27, 2015, 2:28:25 AM4/27/15
to akka...@googlegroups.com

Friendly reminder :-)

Akka Team

unread,
May 4, 2015, 5:23:31 AM5/4/15
to Akka User List
On Thu, Apr 23, 2015 at 11:36 PM, Leszek Gruchała <leszekg...@gmail.com> wrote:
Hi,
I would like to better understand how a Receptionist actor is going to work.

        val receptionist: ActorRef[Command] = ctx.spawn(Props(Receptionist.behavior), "receptionist")

        receptionist
! Register(MySystem, someActor)([1])
        receptionist
! Find(MySystem)([2])


[1] why it is expected to pass to “replyTo” argument already registered (ActorRef[Registered[MyCommand]])?

Because the receptionist will reply with Registered[T] after the registration, therefore the actor that the receptionist replies to must be such an ActorRef type that accepts that message. It is similar to an interface Callback[Registered[T]], if you like to look it that way.
 

[2 ]If I want to find an actor I would like to have ask pattern like
val actor = receptionist ? Find(MySystem)(“some unique name”)

but now I am expected to pass type ActorRef[Listing[MyCommand]] which looks like a reply from a Find command.

Yes exactly. The type of the actor that receives the Listing should be such that it is able to accept a Listing[T] reply. Again, you can imagine it as a Callback[Listing[MyCommand]
 
What I get now is a list of actors of given type. Does it mean, that if I want to look for one specific actor I have to define multiple ServiceKey objects?

Yes, unique actors need to be registered with unique keys.
 

How to obtain an Actor to work with during message processing? Can it be passed only directly to behavior or through the message?

I don't understand this question. Once you have an ActorRef, you can use it directly, or pass it around.
 
I can define behavior of type ActorRef[Registered[MyCommand]] but it cannot be at the same type ActorRef[Listing[MyCommand]],
so one actor cannot register and find actors.

You can always use untyped actors, and AFAIK you can "cast" them to typed actor refs, but I don't know the details. Roland can probably answer in detail.

-Endre
 

Thank you,
Leszek

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam
Reply all
Reply to author
Forward
0 new messages