From a65efbf0ca7bfad96b0f271796d04d789d45b051 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Thu, 28 Jun 2012 14:48:40 +0200 Subject: add examples board, JSON ready --- examples/board.json | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ examples/board.rb | 24 +++++++++++++++++++++--- 2 files changed, 73 insertions(+), 3 deletions(-) create mode 100644 examples/board.json diff --git a/examples/board.json b/examples/board.json new file mode 100644 index 0000000..40a8e20 --- /dev/null +++ b/examples/board.json @@ -0,0 +1,52 @@ +{ + "kls": "Edoors::Spin", + "timestamp": "2012-06-28 14:37:21 +0200", + "name": "dom0", + "hibernation": false, + "inner_room": { + "iotas": { + "input": { + "kls": "FileReader", + "name": "input", + "filepath": "./examples/data.json" + }, + "filter": { + "kls": "Filter", + "name": "filter" + }, + "stats": { + "kls": "Stats", + "name": "stats", + "postponed": { + } + }, + "output": { + "kls": "OutputDoor", + "name": "output" + } + }, + "links": { + "input": [ + { + "kls": "Edoors::Link", + "src": "input", + "dsts": [ + "filter", + "stats?follow", + "output" + ], + "keys": "filter_value", + "value": null + } + ] + } + }, + "sys_fifo": [ + + ], + "app_fifo": [ + + ], + "debug_garbage": false, + "debug_routing": false +} diff --git a/examples/board.rb b/examples/board.rb index b76679f..7ba7310 100644 --- a/examples/board.rb +++ b/examples/board.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 bin/edoors.rb -r examples/board.rb examples/board.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 unless path.nil? + 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 @@ -32,7 +45,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 end @@ -110,6 +123,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! 'board.json' + # end # # EOF -- cgit v1.1-2-g2b99