module Dopi::State
Public Instance Methods
delete_on_signal(a_proc)
click to toggle source
# File lib/dopi/state.rb, line 213 def delete_on_signal(a_proc) signal_procs.delete(a_proc) end
on_signal(a_proc)
click to toggle source
# File lib/dopi/state.rb, line 209 def on_signal(a_proc) signal_procs << a_proc end
reset_signals()
click to toggle source
# File lib/dopi/state.rb, line 200 def reset_signals @signals = Hash.new(false) state_children.each {|child| child.reset_signals} end
send_signal(signal)
click to toggle source
# File lib/dopi/state.rb, line 217 def send_signal(signal) unless signals[signal] == true signal_procs.each {|p| p.call(signal)} state_children.each {|child| child.send_signal(signal)} signals[signal] = true end end
signal_procs()
click to toggle source
# File lib/dopi/state.rb, line 205 def signal_procs @signal_procs ||= [] end
signals()
click to toggle source
# File lib/dopi/state.rb, line 196 def signals @signals ||= Hash.new(false) end
state()
click to toggle source
# File lib/dopi/state.rb, line 15 def state @state ||= :ready end
state_add_child(child)
click to toggle source
# File lib/dopi/state.rb, line 32 def state_add_child(child) state_children << child child.add_observer(self) end
state_auto_evaluate_children()
click to toggle source
# File lib/dopi/state.rb, line 19 def state_auto_evaluate_children @auto_evaluate_children = true if @auto_evaluate_children.nil? @auto_evaluate_children end
state_auto_evaluate_children=(value)
click to toggle source
# File lib/dopi/state.rb, line 24 def state_auto_evaluate_children=(value) @auto_evaluate_children = value end
state_changed(notify_only = false)
click to toggle source
# File lib/dopi/state.rb, line 190 def state_changed(notify_only = false) Dopi.log.debug("State of '#{name}' updated to #{@state.to_s}, notifying observers") changed notify_observers(notify_only) end
state_children()
click to toggle source
# File lib/dopi/state.rb, line 28 def state_children @state_children ||= [] end
state_children_done?()
click to toggle source
# File lib/dopi/state.rb, line 57 def state_children_done? state_children.all? {|child| child.state_done?} end
state_children_failed?()
click to toggle source
# File lib/dopi/state.rb, line 53 def state_children_failed? state_children.any? {|child| child.state_failed?} end
state_children_partial?()
click to toggle source
# File lib/dopi/state.rb, line 61 def state_children_partial? state_partial? || state_children.any?{|c| c.state_children_partial?} end
state_children_ready?()
click to toggle source
# File lib/dopi/state.rb, line 37 def state_children_ready? state_children.any? {|child| child.state_ready?} end
state_children_running?()
click to toggle source
# File lib/dopi/state.rb, line 49 def state_children_running? state_children.any? {|child| child.state_running?} end
state_children_running_noop?()
click to toggle source
# File lib/dopi/state.rb, line 45 def state_children_running_noop? state_children.any? {|child| child.state_running_noop?} end
state_children_starting?()
click to toggle source
# File lib/dopi/state.rb, line 41 def state_children_starting? state_children.any? {|child| child.state_starting?} end
state_done?()
click to toggle source
# File lib/dopi/state.rb, line 117 def state_done? state == :done end
state_fail()
click to toggle source
# File lib/dopi/state.rb, line 167 def state_fail return if state == :failed raise Dopi::StateTransitionError, "Can't switch to failed from #{state.to_s}" unless state == :running @state = :failed state_changed end
state_failed?()
click to toggle source
# File lib/dopi/state.rb, line 121 def state_failed? state == :failed end
state_finish()
click to toggle source
# File lib/dopi/state.rb, line 160 def state_finish return if state == :done raise Dopi::StateTransitionError, "Can't switch to done from #{state.to_s}" unless state == :running @state = :done state_changed end
state_partial?()
click to toggle source
# File lib/dopi/state.rb, line 125 def state_partial? [:failed, :done, :running, :running_noop, :starting, :ready].each do |s| return false if state_children.all?{|c| c.state == s} end return true end
state_ready()
click to toggle source
# File lib/dopi/state.rb, line 153 def state_ready return if state == :ready raise Dopi::StateTransitionError, "Can't switch to ready from #{state.to_s}" unless state == :running_noop @state = :ready state_changed end
state_ready?()
click to toggle source
# File lib/dopi/state.rb, line 101 def state_ready? state == :ready end
state_reset(force = false)
click to toggle source
# File lib/dopi/state.rb, line 174 def state_reset(force = false) if force state_children.each {|child| child.state_reset(force)} @state = :ready state_changed else raise Dopi::StateTransitionError, "Can't switch to ready from #{state.to_s}" unless state == :failed || state == :ready if state_children.any? state_children.each {|child| child.state_reset unless (child.state_done? || child.state_ready?)} else @state = :ready state_changed end end end
state_reset_with_children(force = false)
click to toggle source
# File lib/dopi/state.rb, line 94 def state_reset_with_children(force = false) state_reset(force) if state_failed? or force if state_children_failed? or force state_children.each {|child| child.state_reset_with_children(force) } end end
state_run()
click to toggle source
# File lib/dopi/state.rb, line 139 def state_run return if state == :running raise Dopi::StateTransitionError, "Can't switch to running from #{state.to_s}" unless state == :ready || state == :starting @state = :running state_changed end
state_run_noop()
click to toggle source
# File lib/dopi/state.rb, line 146 def state_run_noop return if state == :running_noop raise Dopi::StateTransitionError, "Can't switch to running_noop from #{state.to_s}" unless state == :ready || state == :starting @state = :running_noop state_changed end
state_running?()
click to toggle source
# File lib/dopi/state.rb, line 109 def state_running? state == :running end
state_running_noop?()
click to toggle source
# File lib/dopi/state.rb, line 113 def state_running_noop? state == :running_noop end
state_start()
click to toggle source
# File lib/dopi/state.rb, line 132 def state_start return if state == :starting raise Dopi::StateTransitionError, "Can't switch to running from #{state.to_s}" unless state == :ready @state = :starting state_changed end
state_starting?()
click to toggle source
# File lib/dopi/state.rb, line 105 def state_starting? state == :starting end
to_yaml_properties()
click to toggle source
# File lib/dopi/state.rb, line 11 def to_yaml_properties instance_variables - [:@signal_procs] end
update(notify_only)
click to toggle source
# File lib/dopi/state.rb, line 69 def update(notify_only) update_mutex.synchronize do unless notify_only old_state = @state Dopi.log.debug("Checking if state of '#{name}' needs to be updated") unless state_children.empty? || !state_auto_evaluate_children if state_children_failed? then @state = :failed elsif state_children_done? then @state = :done elsif state_children_running? then @state = :running elsif state_children_running_noop? then @state = :running_noop elsif state_children_starting? then @state = :starting elsif state_children_ready? then @state = :ready end if old_state == @state state_changed(true) else state_changed(false) end end else state_changed(true) end end end
update_mutex()
click to toggle source
# File lib/dopi/state.rb, line 65 def update_mutex @upate_mutex || Mutex.new end