Hi,
the callbacks are definitely not a good idea. The idiomatic way is sending 
messages that are pure immutable data.
In your case, this means that the ExecuteOnPlayersByPosition message should 
act as an envelope for another message specifying the details of the 
operation.
It's not clear to me which actor tracks the positions of players. Supposing 
that it's the room supervisor actor: upon reception of 
ExecuteOnPlayersByPosition it filters the list of players by position and 
forwards the embedded message to their respective actors. Supposing that 
each player's actor tracks her own position, room supervisor forwards 
ExecuteOnPlayersByPosition verbatim to all players in the room, and 
player's actor checks the envelope and if position matches sends the 
extracted command to self, otherwise ignores the message.

Cheers,
Rafał


W dniu środa, 2 listopada 2016 14:18:43 UTC+1 użytkownik Steve Winfield 
napisał:
>
> Hey,
>
> I got a question regarding a project I'm working on.
>
> There are player actors that can be managed by a "player director" actor 
> which belongs to a virtual room and supervises the players. A player 
> maintains its current position and name as a mutable state.
>
> The director looks like this:
>
> class PlayerDirector extends Actor {
>      ....
>      private val players = mutable.Map[Int, ActorRef]() // Id, Player ref
>      ....
>      override def receive = {
>           case SpawnPlayer(playerReference) => players += 
> (incrementAndGetId() -> context.actorOf(Player.props(playerReference)))
>           case RemovePlayer(id) => ...
>      }
> }
>
>
> Now I'd like to execute some operations on all players which are 
> positioned at x, y
>
> My first attempt:
>
> class PlayerDirector ...
>    receive = {
>           ....
>           case ExecuteOnPlayersByPosition(position, callback) => {
>                 for ((id, player) <- players) {
>                    player ! ExecuteIfPositionMatches(position, callback)
>                 }
>           }
>           ....
>
>
> Then, the player would check its position and execute the callback from 
> its context. I don't like this implementation because it forces me to have 
> the callback executed on the player's actor, but It's the only way to 
> guarantee synchronization (I guess).
>
> Do you have any advice for me?
>
> Cheers!
>

-- 
>>>>>>>>>>      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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.

Reply via email to