n the previous section
(
Customization of Scheduler
section
) we introduced the user interface of the Scheduler. The file
PythonRegistrationOfScheduler.cpp contains boost::python statements that
export such interface into Python and provide some testing functions.
Consider the following Python script (placed in the file test.py in the
SchedulerTest directory).
import Scheduler as s
sch=s.Scheduler()
counter=1
createEventA1=s.CreateEvent("nodeA1",
s.makeFileProxy("proxyA1","proxyA1.txt"),
s.makeFileOrigin("originA1","originA1.txt"),
counter)
sch(createEventA1)
createEventA1.origin().waitOn(counter,1)
createEventB1=s.CreateEvent("nodeB1",
s.makeFileProxy("proxyB1","proxyB1.txt"),
s.makeFileOrigin("originB1","originB1.txt"),
counter)
createEventB2=s.CreateEvent("nodeB2",
s.makeFileProxy("proxyB2","proxyB2.txt"),
s.makeFileOrigin("originB2","originB2.txt"),
counter)
createEventB1.add("nodeA1")
createEventB2.add("nodeA1")
sch(createEventB1)
sch(createEventB2)
createEventB1.origin().waitOn(counter,1)
createEventB2.origin().waitOn(counter,1)
This script creates a simple dependency tree. The nodes "nodeB1" and "nodeB2"
listen to "nodeA1". We need the "createEventA1.origin().waitOn(counter,1)"
statement because we do not want to create nodeB1 and nodeB2 until we are sure
that the nodeA1 is already present.
We execute the script from Release directory of the SchedulerTest_ide_msvc71
directory:
In [1]: execfile('../../test.py')
At this point 6 test files were created: proxyA1.txt, proxyB1.txt,
prixyB2.txt, originA1.txt, originB1.txt and originB2.txt. The proxy*.txt files
are empty. The origin*.txt files contain notification about creation of the
object. For example, the file originA1.txt has the line:
originA1 : 1 : created
Next, we print the Scheduler:
In [2]: print sch
Scheduler
Switch : input 1, processing 0
index 0
nodeA1
Node(
0x01cb04c8
nodeA1
isInWaitingQueue=0
isInUpdateQueue=0
theNumberOfSourcesOutOfDate=0
theNeedToUpdate=0
theOrigin=FileOrigin(originA1)
theProxy=ConsoleProxy(proxyA1)
theSynchCounter=1
theListeners=nodeB2(0x01b34080),nodeB1(0x01bad4b0),
)
nodeB1
Node(
0x01bad4b0
nodeB1
isInWaitingQueue=0
isInUpdateQueue=0
theNumberOfSourcesOutOfDate=0
theNeedToUpdate=0
theOrigin=FileOrigin(originB1)
theProxy=ConsoleProxy(proxyB1)
theSynchCounter=1
theListeners=
)
nodeB2
Node(
0x01b34080
nodeB2
isInWaitingQueue=0
isInUpdateQueue=0
theNumberOfSourcesOutOfDate=0
theNeedToUpdate=0
theOrigin=FileOrigin(originB2)
theProxy=ConsoleProxy(proxyB2)
theSynchCounter=1
theListeners=
)
index 1
nodeA1
Node(
0x01c24688
nodeA1
isInWaitingQueue=0
isInUpdateQueue=0
theNumberOfSourcesOutOfDate=0
theNeedToUpdate=0
theOrigin=FileOrigin(originA1)
theProxy=ConsoleProxy(proxyA1)
theSynchCounter=1
theListeners=nodeB2(0x01cf8940),nodeB1(0x01ab5f18),
)
nodeB1
Node(
0x01ab5f18
nodeB1
isInWaitingQueue=0
isInUpdateQueue=0
theNumberOfSourcesOutOfDate=0
theNeedToUpdate=0
theOrigin=FileOrigin(originB1)
theProxy=ConsoleProxy(proxyB1)
theSynchCounter=1
theListeners=
)
nodeB2
Node(
0x01cf8940
nodeB2
isInWaitingQueue=0
isInUpdateQueue=0
theNumberOfSourcesOutOfDate=0
theNeedToUpdate=0
theOrigin=FileOrigin(originB2)
theProxy=ConsoleProxy(proxyB2)
theSynchCounter=1
theListeners=
)
The print statements shows to copies of the tree. One copy accepts events and
another processes it.
Let us supply an update event.
In [3]: sch(s.UpdateEvent("nodeB1",2))
The contents of the file originB1.txt and proxyB1.txt has changed.
originB1.txt:
originB1 : 1 : created
originB1 : 2 : updated
<eof>
proxyB1.txt:
proxyB1 : Updated
<eof>
Let us supply another update event.
In [4]: sch(s.UpdateEvent("nodeA1",3))
All six files have changed.originA1.txt:
originA1 : 1 : created
originA1 : 3 : updated
<eof>
originB1.txt:
originB1 : 1 : created
originB1 : 2 : updated
originB1 : 2 : updated
<eof>
originB2.txt:
originB2 : 1 : created
originB2 : 1 : updated
<eof>
proxyA1.txt:
proxyA1 : Updated
<eof>
proxyB1.txt:
proxyB1 : Updated
proxyB1 : Updated
<eof>
proxyB2.txt:
proxyB2 : Updated
<eof>
Let us now delete the nodeA1.
In [6]: sch(s.DeleteEvent("nodeA1"))
In [7]: print sch
Scheduler
Switch : input 0, processing 1
index 0
index 1
As we can see, if node is deleted then all listeners are deleted also. All six
files received notification about deletion.
The test functions implemented in the file PythonRegistrationOfScheduler.cpp
allow for some heavy duty testing. A call to s.testTree() creates a dependency
tree with 17 nodes. A call to s.testTree2(...) creates a randomly structured
tree of arbitrary complexity. Each calls to s.testThread(...) starts a thread
that bombards the Scheduler with update events. Simultaneously the user may
experiment by sending additional events and examining the results.
|