Skip to content
laforge49 edited this page Oct 28, 2011 · 4 revisions

The Actors service is implemented by the ActorRegistry. This service is invoked by sending an Actors message to system services.

case class Actors()

The returned result is a Sequence[String, Actor], where the keys are the ActorId values and the values are the registered actors.

The test for the Actors service is the same as the test for ActorRegistry, except that we changed the Driver class to print the contents of the Actors sequence.

class Driver extends Actor {
  setMailbox(new ReactorMailbox)
  bind(classOf[DoIt1], doit1)
  bind(classOf[DoIt2], doit2)

  def doit1(msg: AnyRef, rf: Any => Unit) {
    systemServices(Instantiate(FactoryId("greeter"), null)) {rsp =>
      val greeter = rsp.asInstanceOf[Actor]
      greeter.id(ActorId("a"))
      systemServices(Register(greeter)) {rsp => {}}
    }
    systemServices(ResolveName(FactoryId("greeter"), null)) {rsp =>
      val greeter = rsp.asInstanceOf[Actor]
      greeter.id(ActorId("b"))
      systemServices(Register(greeter)) {rsp => {}}
    }
    rf(null)
  }

  def doit2(msg: AnyRef, rf: Any => Unit) {
    systemServices(Unregister(ActorId("a"))) {rsp => {}}
    systemServices(Actors()) {
      rsp =>
        val actors = rsp.asInstanceOf[Actor]
        actors(
          Loop((key: String, value: Actor) => println(key + " " + value.getClass.getName))) {
          rsp => rf(null)
        }
    }
  }
}

Output.

b org.agilewiki.blip.seq.actors.Greeter

ActorsTest

Tutorial

Clone this wiki locally