mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-16 22:50:10 +03:00
OpenNebulaDriver now is an ActionManager
git-svn-id: http://svn.opennebula.org/one/trunk@336 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
b31669f4ff
commit
39a6460cb4
@ -46,7 +46,7 @@ class Sample
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
s = Sample.new
|
||||
|
||||
s.@am.start_listener
|
||||
@ -96,11 +96,11 @@ class ActionManager
|
||||
# +aname+ name of the action
|
||||
# +aargs+ arguments to call the action
|
||||
def trigger_action(aname,*aargs)
|
||||
|
||||
|
||||
return if @finalize
|
||||
|
||||
|
||||
@threads_mutex.synchronize {
|
||||
|
||||
|
||||
if aname == "FINALIZE"
|
||||
@finalize = true
|
||||
@threads_cond.signal if @running_actions == 0
|
||||
@ -129,10 +129,10 @@ class ActionManager
|
||||
while ((@concurrency - @running_actions)==0) ||
|
||||
@action_queue.size==0
|
||||
@threads_cond.wait(@threads_mutex)
|
||||
|
||||
return if ( @finalize && @running_actions == 0)
|
||||
|
||||
return if (@finalize && @running_actions == 0)
|
||||
end
|
||||
|
||||
|
||||
run_action
|
||||
}
|
||||
end
|
||||
@ -162,7 +162,6 @@ private
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if __FILE__ == $0
|
||||
@ -187,7 +186,6 @@ if __FILE__ == $0
|
||||
def nop_action
|
||||
p " - Just an action"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
s = Sample.new
|
||||
@ -200,11 +198,11 @@ if __FILE__ == $0
|
||||
}
|
||||
|
||||
s.am.trigger_action("FINALIZE")
|
||||
|
||||
|
||||
s.am.trigger_action("SLEEP",rand(3)+1,999)
|
||||
s.am.trigger_action("SLEEP",rand(3)+1,333)
|
||||
}
|
||||
|
||||
|
||||
s.am.start_listener
|
||||
end
|
||||
|
||||
|
@ -28,11 +28,10 @@ require "ActionManager"
|
||||
# for each action it wants to receive. The method must be associated
|
||||
# with the action name through the register_action func
|
||||
|
||||
class OpenNebulaDriver
|
||||
class OpenNebulaDriver < ActionManager
|
||||
def initialize(concurrency=10, threaded=true)
|
||||
super(concurrency,threaded)
|
||||
@send_mutex=Mutex.new
|
||||
|
||||
@am = ActionManager.new(concurrency,threaded)
|
||||
end
|
||||
|
||||
def send_message(*args)
|
||||
@ -53,9 +52,7 @@ class OpenNebulaDriver
|
||||
|
||||
def start_driver
|
||||
loop_thread = Thread.new { loop }
|
||||
|
||||
@am.start_listener
|
||||
|
||||
start_listener
|
||||
loop_thread.kill!
|
||||
end
|
||||
|
||||
@ -73,7 +70,7 @@ private
|
||||
|
||||
action = args.shift.upcase
|
||||
|
||||
@am.trigger_action(action,*args)
|
||||
trigger_action(action,*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -82,9 +79,9 @@ if __FILE__ == $0
|
||||
|
||||
class SampleDriver < OpenNebulaDriver
|
||||
def initialize
|
||||
super(5,true)
|
||||
super(15,true)
|
||||
|
||||
@am.register_action("SLEEP",method("my_sleep"))
|
||||
register_action("SLEEP",method("my_sleep"))
|
||||
end
|
||||
|
||||
def response(action,result,info)
|
||||
|
Loading…
x
Reference in New Issue
Block a user