summaryrefslogtreecommitdiffstats
path: root/lib/evendoors
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2012-05-12 23:46:06 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2012-05-12 23:46:06 +0200
commitf39792003a0a02dccc927ec41735aace687071ca (patch)
treef5bdd6164d8dad1e170372b213a14dc42f1d3bf3 /lib/evendoors
parentbd77f096ee70c011f27afa59817db8f7c4b29977 (diff)
downloadedoors-ruby-f39792003a0a02dccc927ec41735aace687071ca.zip
edoors-ruby-f39792003a0a02dccc927ec41735aace687071ca.tar.gz
Spin: add #hibernate!
Diffstat (limited to 'lib/evendoors')
-rw-r--r--lib/evendoors/spin.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/lib/evendoors/spin.rb b/lib/evendoors/spin.rb
index 7fb4218..e4f61cf 100644
--- a/lib/evendoors/spin.rb
+++ b/lib/evendoors/spin.rb
@@ -31,6 +31,7 @@ module EvenDoors
@app_fifo = [] # application particles fifo list
#
@run = false
+ @hibernate_path = 'evendoors-hibernate-'+n+'.json'
@debug_errors = o[:debug_errors]||o['debug_errors']||false
@debug_routing = o[:debug_routing]||o['debug_routing']||false
#
@@ -52,6 +53,7 @@ module EvenDoors
def to_json *a
{
'kls' => self.class.name,
+ 'timestamp' => Time.now,
'name' => @name,
'spots' => @spots,
'sys_fifo' => @sys_fifo,
@@ -99,6 +101,14 @@ module EvenDoors
@sys_fifo << p
end
#
+ def process_sys_p p
+ if p.action==EvenDoors::SYS_ACT_HIBERNATE
+ hibernate! p[FIELD_HIBERNATE_PATH]
+ else
+ super p
+ end
+ end
+ #
def spin!
@spots.values.each do |spot| spot.start! end
@run = true
@@ -120,6 +130,11 @@ module EvenDoors
@run=false
end
#
+ def hibernate! path=nil
+ stop!
+ File.open(path||@hibernate_path,'w') do |f| f << JSON.pretty_generate(self) end
+ end
+ #
end
#
end