-
Notifications
You must be signed in to change notification settings - Fork 1
componentFactoryClasses
laforge49 edited this page Jul 31, 2011
·
4 revisions
#Actor.componentFactoryClasses
Actor.componentFactoryClassesis a sequence of all the ComponentFactory classes, Class[_ <: ComponentFactory], of the components of an actor.
Test.
case class Set(value: Int)
case class Get()
case class Times2()
class SaverComponentFactory extends ComponentFactory {
override def instantiate(actor: Actor) = new SaverComponent(actor)
}
class SaverComponent(actor: Actor) extends Component(actor) {
var i = 0
bind(classOf[Set], setFunc)
private def setFunc(msg: AnyRef, rf: Any => Unit) {
i = msg.asInstanceOf[Set].value
rf(null)
}
bind(classOf[Get], getFunc)
private def getFunc(msg: AnyRef, rf: Any => Unit) {rf(i)}
}
class DoubleComponentFactory extends ComponentFactory {
addDependency(classOf[SaverComponentFactory])
override def instantiate(actor: Actor) = new DoubleComponent(actor)
}
class DoubleComponent(actor: Actor) extends Component(actor) {
val saver = actor.component(classOf[SaverComponentFactory]).asInstanceOf[SaverComponent]
bind(classOf[Times2], doubleFunc)
private def doubleFunc(msg: AnyRef, rf: Any => Unit) {
saver.i *= 2
rf(null)
}
}
class DoubleFactory extends Factory(null) {
include(new DoubleComponentFactory)
}
val doubleFactory = new DoubleFactory
val double = doubleFactory.newActor(new Mailbox)
val componentFactoryClasses= double.componentFactoryClasses
Future(componentFactoryClasses,
Loop((key: Class[_ <: ComponentFactory], value: Class[_ <: ComponentFactory]) => println(value)))
Output.
class org.agilewiki.blip.seq.componentFactoryClasses.DoubleComponentFactory
class org.agilewiki.blip.seq.componentFactoryClasses.SaverComponentFactory