Class: Roby::Schedulers::State
Overview
Objects representing the reports from a scheduler object
They are saved in logs, and can also be listened to through Interface::Interface
Instance Attribute Summary collapse
-
#actions ⇒ {Task=>[String,Array]}
The list of actions that have been taken by the scheduler.
-
#called_generators ⇒ EventGenerator
The list of event generators triggered by the scheduler.
-
#non_scheduled_tasks ⇒ {Task=>[String,Array]}
The list of tasks that have been considered for scheduling, but could not be scheduled, along with the reason.
-
#pending_non_executable_tasks ⇒ Object
Tasks that are pending in the plan, but are not executable.
Class Method Summary collapse
-
.format_message_into_string(msg, *args) ⇒ Object
Formats a message stored in #non_scheduled_tasks into a plain string.
Instance Method Summary collapse
-
#initialize ⇒ State
constructor
A new instance of State.
-
#merge!(state) ⇒ Object
Add information contained in ‘state’ to this object.
- #pretty_print(pp) ⇒ Object
- #report_action(msg, task, *args) ⇒ Object
- #report_holdoff(msg, task, *args) ⇒ Object
- #report_pending_non_executable_task(msg, task, *args) ⇒ Object
- #report_trigger(generator) ⇒ Object
Constructor Details
#initialize ⇒ State
Returns a new instance of State.
32 33 34 35 36 37 |
# File 'lib/roby/schedulers/state.rb', line 32 def initialize @pending_non_executable_tasks = Set.new @called_generators = Set.new @non_scheduled_tasks = Hash.new { |h, k| h[k] = Set.new } @actions = Hash.new { |h, k| h[k] = Set.new } end |
Instance Attribute Details
#actions ⇒ {Task=>[String,Array]}
The list of actions that have been taken by the scheduler
30 31 32 |
# File 'lib/roby/schedulers/state.rb', line 30 def actions @actions end |
#called_generators ⇒ EventGenerator
The list of event generators triggered by the scheduler
15 16 17 |
# File 'lib/roby/schedulers/state.rb', line 15 def called_generators @called_generators end |
#non_scheduled_tasks ⇒ {Task=>[String,Array]}
The list of tasks that have been considered for scheduling, but could not be scheduled, along with the reason
23 24 25 |
# File 'lib/roby/schedulers/state.rb', line 23 def non_scheduled_tasks @non_scheduled_tasks end |
#pending_non_executable_tasks ⇒ Object
Tasks that are pending in the plan, but are not executable
11 12 13 |
# File 'lib/roby/schedulers/state.rb', line 11 def pending_non_executable_tasks @pending_non_executable_tasks end |
Class Method Details
.format_message_into_string(msg, *args) ⇒ Object
Formats a message stored in #non_scheduled_tasks into a plain string
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/roby/schedulers/state.rb', line 118 def self.(msg, *args) args.each_with_index.inject(msg) do |msg, (a, i)| a = if a.respond_to?(:map) a.map(&:to_s).join(", ") else a.to_s end msg.gsub "%#{i + 1}", a end end |
Instance Method Details
#merge!(state) ⇒ Object
Add information contained in ‘state’ to this object
56 57 58 59 60 61 62 63 64 65 |
# File 'lib/roby/schedulers/state.rb', line 56 def merge!(state) pending_non_executable_tasks.merge(state.pending_non_executable_tasks) called_generators.merge(state.called_generators) non_scheduled_tasks.merge!(state.non_scheduled_tasks) do |task, msg0, msg1| msg0.merge(msg1) end actions.merge!(state.actions) do |task, msg0, msg1| msg0.merge(msg1) end end |
#pretty_print(pp) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/roby/schedulers/state.rb', line 67 def pretty_print(pp) unless pending_non_executable_tasks.empty? has_text = true pp.text "Pending non-executable tasks" pp.nest(2) do pending_non_executable_tasks.each do |args| pp.breakable pp.text self.class.(*args) end end end unless non_scheduled_tasks.empty? pp.breakable if has_text has_text = true pp.text "Non scheduled tasks" pp.nest(2) do non_scheduled_tasks.each do |task, msgs| pp.breakable task.pretty_print(pp) pp.nest(2) do msgs.each do |msg, *args| pp.breakable pp.text self.class.(msg, task, *args) end end end end end unless actions.empty? pp.breakable if has_text has_text = true pp.text "Actions taken" pp.nest(2) do actions.each do |task, msgs| pp.breakable task.pretty_print(pp) pp.nest(2) do msgs.each do |msg, *args| pp.breakable pp.text self.class.(msg, task, *args) end end end end end end |
#report_action(msg, task, *args) ⇒ Object
51 52 53 |
# File 'lib/roby/schedulers/state.rb', line 51 def report_action(msg, task, *args) actions[task] << [msg, *args] end |
#report_holdoff(msg, task, *args) ⇒ Object
47 48 49 |
# File 'lib/roby/schedulers/state.rb', line 47 def report_holdoff(msg, task, *args) non_scheduled_tasks[task] << [msg, *args] end |
#report_pending_non_executable_task(msg, task, *args) ⇒ Object
39 40 41 |
# File 'lib/roby/schedulers/state.rb', line 39 def report_pending_non_executable_task(msg, task, *args) pending_non_executable_tasks << [msg, task, *args] end |
#report_trigger(generator) ⇒ Object
43 44 45 |
# File 'lib/roby/schedulers/state.rb', line 43 def report_trigger(generator) called_generators << generator end |