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

The Factories service is implemented by the FactoryRegistry. This service is invoked by sending a Factories message to system services.

case class Factories()

The returned result is a Sequence[String, Factory], where the keys are the FactoryId values and the values are the registered factories.

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

class Driver extends Actor {
  setMailbox(new ReactorMailbox)
  bind(classOf[DoIt], doit)
  def doit(msg: AnyRef, rf: Any => Unit) {
    systemServices(Factories()) {rsp =>
      val factories = rsp.asInstanceOf[Actor]
      factories(
        Loop((key: String, value: Factory) => println(key+" "+value.getClass.getName))) {
        rsp => rf(null)
      }
    }
  }
}

Output.

greeter org.agilewiki.blip.seq.factories.GreeterFactory

FatcoriesTest

Implementation of the Factories service uses the SafeConstant class, which always operates synchronously.

class SafeConstant(any: Any)
  extends Safe {
  def func(msg: AnyRef, rf: Any => Unit)(implicit sender: ActiveActor) {
    rf(any)
  }
}

In the FactoryRegistryComponent we bind Factories messages to a constant, a NavMapSeq.

  bindSafe(classOf[Factories],
    new SafeConstant(new NavMapSeq(componentFactory.factories)))

FactoryRegistry

Tutorial

Clone this wiki locally