mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
Let the machine shutdown before destroying in xen driver
git-svn-id: http://svn.opennebula.org/one/trunk@341 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
5269d55770
commit
2182cfe6ca
@ -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
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user