Skip to content
laforge49 edited this page Sep 9, 2011 · 3 revisions

Properties are used to configure both the top-level system and subsystems. This is best demonstrated by an example. First, a simple driver.

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)
  }
}

The driver displays several properties to illustrate various cases. The properties are taken, implicitly, from the system services of the actor. Now lets look at the test code.

val p1 = new Properties
p1.put("a", "1")
p1.put("b", "2")
p1.put("c", "3")
val systemServices = SystemServices(new PropertiesComponentFactory, properties = p1)
val p2 = new Properties
p2.put("b", null)
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())

The test code defines a number of properties (p1) which are used to configure the top-level system. Additional properties (p2) are then used to configure a subsystem--which is passed to the driver.

Output.

a = 1
b = null
c = 11
d = 12
e = null

PropertiesTest

Tutorial

Clone this wiki locally