Version 2, last updated by David Lee at 19 Jan 19:18 UTC

When naming the cometactor in a snippet an instance of the cometActor is created for each different name.

From https://groups.google.com/forum/#!msg/liftweb/A9ql6e1Dx-A/Z-e8htnlj64J

To answer both the “how many times does a named comet actor get instantiated” and “how do I send a message to a named comet actor” I’ve put together the following code:
https://github.com/dpp/starting_point/tree/named_comet_fun

The comet actor that’s used on a given page is named based on the name parameter: http://localhost:8080/index?name=David will have a Comet Actor named “David” and http://localhost:8080/index will default to the name “Woof”

The comet actor is only instantiated once (you can see the console output).

The MakeOne.scala code demonstrates how to name the CometActor.

The code for sending a message to a named comet actor is in Boot.scala:

object SendToComet extends RestHelper {
serve {
case Get(“send” :: rest, _) => {
val (name, msg) = rest match {
case name :: msg :: _ => (name, msg)
case name :: _ => (name, “No Message”)
case _ => (“Woof”, “No message”)
}

for { sess <- S.session ?~ “Session not found” ca <- sess.findComet(“Tick”, Full(name)) ?~ “Comet actor not found” } yield { ca ! msg Thanks } } }

}

http://localhost:8080/send will send “No Message” to the “Woof” actor.

http://localhost:8080/send/David will send “No Message” to the “David” actor.

http://localhost:8080/send/David/Howdy will send "Howdy to the “David” actor.

If the actor isn’t found, the REST request will fail with an error message indicating why the request failed.

Please let me know if this helps.

Thanks,

David