Created
January 25, 2013 07:49
-
-
Save metamorph/4632600 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
case class RegisterDispatcher(ref: ActorRef, matcher: String) | |
class MasterActor extends Actor { | |
def receive = { | |
case RegisterDispatcher(ref, matcher) => //.. add ref to registry. watch the ref to remove the entry should the actor terminate. | |
case s: String => // look in the registry for a match amd dispatch accordingly. | |
} | |
} | |
class ActorA(master: ActorRef) { | |
master ! RegisterDispatcher(self, "bar") | |
def receive = { | |
//.. Handle message | |
} | |
} | |
class ActorB(master: ActorRef) { | |
master ! RegisterDispatcher(self, "foo") | |
def receive = { | |
//.. Handle message | |
} | |
} | |
object Main extends App { | |
val sys = ActorSystem("sys") | |
val master = sys.actorOf(Props[MasterActor]) | |
sys.actorOf(Props(new ActorA(master))) | |
sys.actorOf(Props(new ActorB(master))) | |
// Time passes... | |
master ! "foo" | |
master ! "bar" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment