diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/links.json | 96 | ||||
-rw-r--r-- | examples/links.rb | 34 |
2 files changed, 126 insertions, 4 deletions
diff --git a/examples/links.json b/examples/links.json new file mode 100644 index 0000000..19959d6 --- /dev/null +++ b/examples/links.json @@ -0,0 +1,96 @@ +{ + "kls": "Edoors::Spin", + "timestamp": "2012-06-28 14:43:36 +0200", + "name": "dom0", + "hibernation": false, + "inner_room": { + "iotas": { + "input": { + "kls": "FileReader", + "name": "input", + "filepath": "./examples/data.json" + }, + "age_filter": { + "kls": "Filter", + "name": "age_filter" + }, + "output_f": { + "kls": "OutputDoor", + "name": "output_f", + "title": "woman" + }, + "output_m": { + "kls": "OutputDoor", + "name": "output_m", + "title": "man" + }, + "output_child": { + "kls": "OutputDoor", + "name": "output_child", + "title": "child" + }, + "output_parent": { + "kls": "OutputDoor", + "name": "output_parent", + "title": "parent" + } + }, + "links": { + "input": [ + { + "kls": "Edoors::Link", + "src": "input", + "dsts": "age_filter", + "keys": null, + "value": null + } + ], + "age_filter": [ + { + "kls": "Edoors::Link", + "src": "age_filter", + "dsts": "output_f", + "keys": null, + "value": { + "sex": "f" + } + }, + { + "kls": "Edoors::Link", + "src": "age_filter", + "dsts": "output_m", + "keys": null, + "value": { + "sex": "m" + } + }, + { + "kls": "Edoors::Link", + "src": "age_filter", + "dsts": "output_child", + "keys": null, + "value": { + "old": false + } + }, + { + "kls": "Edoors::Link", + "src": "age_filter", + "dsts": "output_parent", + "keys": null, + "value": { + "old": true + } + } + ] + } + }, + "sys_fifo": [ + + ], + "app_fifo": [ + + ], + "debug_garbage": false, + "debug_routing": false +} diff --git a/examples/links.rb b/examples/links.rb index b21a2e4..c5d80f5 100644 --- a/examples/links.rb +++ b/examples/links.rb @@ -6,16 +6,29 @@ # run this script which builds the example system and spin it untill it's empty: # $ ruby -Ilib examples/links.rb # +# or load the system from a JSON specification ( created with dom0.hibernate! ) +# $ ruby -Ilib -r ./examples/links.rb bin/edoors.rb examples/links.json +# +# require 'edoors' # class FileReader < Edoors::Door # - def initialize n, p, path + def initialize n, p, path=nil super n, p - @file = File.open(path,'r') + @filepath = path + end + # + def hibernate! + {'filepath'=>@filepath} + end + # + def resume! o + @filepath = o['filepath'] end # def start! + @file = File.open(@filepath,'r') # stimulate myself on system boot up send_p require_p(Edoors::Particle), Edoors::ACT_GET end @@ -29,7 +42,7 @@ class FileReader < Edoors::Door # see Room#_send and Room#_try_links send_p p # stimulate myself - start! + send_p require_p(Edoors::Particle), Edoors::ACT_GET end end # @@ -52,11 +65,19 @@ end # class OutputDoor < Edoors::Door # - def initialize n, p, t + def initialize n, p, t=nil super n, p @title = t end # + def hibernate! + {'title'=>@title} + end + # + def resume! o + @title = o['title'] + end + # def receive_p p if p.action!=Edoors::ACT_ERROR p = p.get_data('person') @@ -90,6 +111,11 @@ if $0 == __FILE__ # schedule the spinning particles untill the system cools down dom0.spin! # + # you can save the system state after it's run, + # but to be able to use it to bootstrap, the hibernation attribute must be set to false + # otherwise start! method is not called + dom0.hibernate! 'links.json' + # end # # EOF |