georgeOsdDev / xitrum-leochat

Chat demo of xitrum with LeoFS
https://slid.es/georgeosd/introduction-of-xitrum
1 stars 0 forks source link

Use glokka #1

Closed georgeOsdDev closed 11 years ago

georgeOsdDev commented 11 years ago

https://github.com/ngocdaothanh/glokka

georgeOsdDev commented 11 years ago

@ngocdaothanh How can I detect new actor have been registered in glokka. I want ton know all of names who are registered. Is there any way which like akka's cluster member up event listener?

http://doc.akka.io/docs/akka/2.2.1/scala/cluster-usage.html

ngocdaothanh commented 11 years ago

Please give a use case (scenario) where you want to detect new actor registration and to know all registered names.

georgeOsdDev commented 11 years ago

Manager has client actor(s) and work as pubSub. And I register manager in glokka.

  registry 
         ├── manager1
         │      ├── actor10
         │      ├── actor11
         │      :
         │      └── actor1X
         ├── manager2
         │      ├── actor2X
         │      :
         ├── manager3
         :      ├── actor3X
         :      :

I want to use like below

class MessageQueManager extends Actor with Logger{
  var clients = Seq[ActorRef]()
  var managers = Seq[ActorRef]()

  def receive{
    case pub:Publish =>
      clients.foreach{client =>
        client !  MsgsFromQueue(pub.msg)
      }
      managers.foreach{manager
        manager ! MsgsFromRegistry(pub.msg)
      }

    case msg:MsgsFromRegistry =>
      clients.foreach{client =>
        client !  MsgsFromQueue(pub.msg)
      }

    case sub: Subscribe =>
      clients = clients :+ sender
      val messages = LeoFS.readHead(sub.num)
      sender ! MsgsFromQueue(messages)

    //case new_registry: NewRegistry =>
    //  managers = managers :+ new_registry
  }
}

So each manager have to know other manager's name or actorRef as new_registry

If glokka.Registry#doRegister send message to all registerd actorRef

        sender ! RegisterResultOk(name, actorRef)

        // notice all items that register event happen
        name2Ref.foreach{item =>
          item._2 ! NewRegistry(name,actorRef)
        }
georgeOsdDev commented 11 years ago

Register manager as global.