From 2182cfe6ca675c5d2af98c42fc5a3f22b7e32369 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javier=20Font=C3=A1n=20Mui=C3=B1os?= Date: Fri, 6 Feb 2009 15:13:10 +0000 Subject: [PATCH] Let the machine shutdown before destroying in xen driver git-svn-id: http://svn.opennebula.org/one/trunk@341 3034c82b-c49b-4eb3-8279-a7acafdc01c0 --- src/mad/ruby/ActionManager.rb | 56 ++++++++++++++++++---------------- src/vmm_mad/xen/one_vmm_xen.rb | 2 +- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/mad/ruby/ActionManager.rb b/src/mad/ruby/ActionManager.rb index c2b3c69630..09b845a6d5 100644 --- a/src/mad/ruby/ActionManager.rb +++ b/src/mad/ruby/ActionManager.rb @@ -27,33 +27,33 @@ can be used to synchronize different objects in different threads == Example -class Sample - attr_reader :am + class Sample + attr_reader :am - def initialize - @am = ActionManager.new(15,true) + def initialize + @am = ActionManager.new(15,true) - @am.register_action("SLEEP",method("sleep_action")) + @am.register_action("SLEEP",method("sleep_action")) + end + + def sleep_action(secs) + sleep(secs) + end + + def finalize_action + p "Exiting..." + @am.stop_listener + end end - def sleep_action(secs) - sleep(secs) - end - - def finalize_action - p "Exiting..." - @am.stop_listener - end -end - s = Sample.new s.@am.start_listener -# Objects in other threads can trigger actions like this -# s.am.trigger_action("SLEEP",rand(3)+1) -# s.am.trigger_action("FINALIZE") +# Objects in other threads can trigger actions like this +# s.am.trigger_action("SLEEP",rand(3)+1) +# s.am.trigger_action("FINALIZE") =end class ActionManager @@ -65,16 +65,16 @@ class ActionManager # +threaded+ if true actions will be executed by default in a different # thread def initialize(concurrency=10, threaded=true) - @finalize = false - @actions = Hash.new - @threaded = threaded + @finalize = false + @actions = Hash.new + @threaded = threaded - @concurrency = concurrency - @action_queue = Array.new - @running_actions = 0 + @concurrency = concurrency + @action_queue = Array.new + @running_actions= 0 - @threads_mutex = Mutex.new - @threads_cond = ConditionVariable.new + @threads_mutex = Mutex.new + @threads_cond = ConditionVariable.new end # Registers a new action in the manager. An action is defined by: @@ -110,8 +110,10 @@ class ActionManager if !@actions.has_key?(aname) return end + + method_obj = method(@actions[aname][:method]) - if @actions[aname][:method].arity != aargs.length + if method_obj.arity != aargs.length return end diff --git a/src/vmm_mad/xen/one_vmm_xen.rb b/src/vmm_mad/xen/one_vmm_xen.rb index 4e74e62eb7..451b7d80b7 100755 --- a/src/vmm_mad/xen/one_vmm_xen.rb +++ b/src/vmm_mad/xen/one_vmm_xen.rb @@ -122,7 +122,7 @@ class DM < ONEMad end def action_shutdown(args) - std_action("SHUTDOWN", "shutdown #{args[3]} \\&\\& sudo #{XM_PATH} destroy #{args[3]} \\&\\& sleep 4", args) + std_action("SHUTDOWN", "shutdown #{args[3]} \\&\\& sleep 10 \\&\\& sudo #{XM_PATH} destroy #{args[3]} \\&\\& sleep 4", args) end def action_cancel(args)