[akka-user] Akka Actor Hierarchy Question

2016-03-13 Thread Neale Genereux
Hello all,

I'm playing around with Akka in conjunction with the Play framework, 
working in Java. I have a reasonable understanding of how the actor system 
works in general, but I need some help wrapping my head around how to set 
up the system efficiently. 

Let's take the Chat server example. Let's say my Play server has several 
chat rooms, each identified by an ID. Each chat room has a single actor 
which stores the chat history as state, and handles requests to post new 
messages, forwarding them in turn to all other listeners. It can also 
handle a request to get all previous chat history. My question is: How do 
you setup the actor hierarchy for this system to work efficiently?

My first instinct is to create some sort of chat room supervisor actor 
which will store a map of chat room id's to child actor refs. This 
supervisor can now handle chat room failures, and requests to create or 
remove chat rooms. However, every request to every chat room now has to go 
through this supervisor, creating a bottleneck. 

Additionally, if I decide to make my chat room actors persistent, I'm not 
sure whether it is this supervisor's job to recreate those actors after a 
system restart. If not, how can the supervisor get its list of child actors 
back?

I guess my root question is this: 
How do I setup a system which will have many stateful, persistent actors of 
the same type, all identified by a unique id such that:
1) Each actor is supervised by an actor which can handle issues with its 
lifecycle
2) Clients, such as HTTP requests from the Play framework, can efficiently 
communicate with these actors assuming they have that actor's ID

Thanks for any help you can give me!

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


Re: [akka-user] awaitTermination not working?

2016-03-13 Thread Eduardo Fernandes
Hum... it's look like an actor which uses an asynchronous DB persistor from 
an external library sometimes launches a thread. When the thread is running 
the shutdown() does nothing and the awaitTermination() doesn't block. If I 
stop the thread (I have to  say that in a not very documented way) the 
shutdown stops all Akka threads and the system appears to be released 
correctly (nevertheless in a single node configuration I don't see the 
typical shutdowing messages in the log).

Doing this the problem is solved. Thanks for your comments.

I still don't understand why the shutdown()/awaitTermination()  have no 
effect when those external threads are running. Probably when we migrate to 
2.4 the problem will just vanish.

Thanks again!


El viernes, 11 de marzo de 2016, 13:45:59 (UTC+1), Eduardo Fernandes 
escribió:
>
> Me too :(
>
> I'l prepare a minimum example. Typically when I do this the problem get 
> clear and I could fix my test code :)
>
> Regards.
>  
>
>

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


[akka-user] Akka game state

2016-03-13 Thread Владимир Морозов
Hi All, I have some simple Actor:

case class Item(id: String, description: String)


object Player {


  sealed trait PlayerMessage


  case class PickupItem(item: Item)


  case class GiveItem(itemId: String, player: ActorRef)


  case object ShowInventory


  def props(): Props =
Props(classOf[Player])
}


class Player extends Actor with ActorLogging {


  import Player._


  var inventory = Seq.empty[Item]


  override def receive: Receive = {
case PickupItem(item) =>
  inventory = inventory :+ item


case GiveItem(itemId, player) =>
  inventory
.find(_.id == itemId)
.map { item =>
  inventory = inventory.diff(Seq(item))
  player ! PickupItem(item)
}


case ShowInventory =>
  log.info(s"[${context.self.path.name}] [${inventory.mkString(", ")}]")
  }
}



If two Player's actors live in two different remote actor systems - how 
safely transfer item from one player to other (read transactionally or 
guaranteed) change state of two actor, by design all actions with inventory 
persisted to database (without akka-persistence).

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