AsyncFP Properties - laforge49/Asynchronous-Functional-Programming GitHub Wiki
Factories are a good way to handle most configuration issues, but there are always a few things that seem to span multiple actors or which need to be set from the command line. The Properties component can be useful in these cases. This component can be added to the RootSystemServices actor and to Subsystem actors. An actor that is part of a subsystem has access to that subsystem's properties as well as the properties of the subsystem's superior, recursively.
Here's a simple test which illustrates the hierarchical nature of properties:
val p1 = new Properties
p1.put("a", "1")
p1.put("b", "2")
p1.put("c", "3")
val systemServices = SystemServices(new PropertiesComponentFactory, properties = p1)
try {
val p2 = new Properties
p2.put("c", "11")
p2.put("d", "12")
val aSubsystem = Subsystem(systemServices, new PropertiesComponentFactory, properties = p2)
val driver = new Driver
driver.setSystemServices(aSubsystem)
Future(driver, DoIt())
} finally {
systemServices.close
}
case class DoIt()
class Driver extends Actor {
bind(classOf[DoIt], doIt)
def doIt(msg: AnyRef, rf: Any => Unit) {
println("a = " + GetProperty("a")) //set in p1
println("b = " + GetProperty("b")) //reset in p2
println("c = " + GetProperty("c")) //overridden in p2
println("d = " + GetProperty("d")) //set in p2
println("e = " + GetProperty("e")) //unspecified
rf(null)
}
}
And here's the output:
a = 1
b = 2
c = 11
d = 12
e = null