Module: Roby::Coordination::Models::FaultHandler
- Included in:
- FaultHandler
- Defined in:
- lib/roby/coordination/models/fault_handler.rb
Overview
Definition of a single fault handler in a FaultResponseTable
Defined Under Namespace
Classes: FinalizeReplacement, ReplaceBy, ResponseLocationVisitor
Instance Attribute Summary
Attributes included from Actions
Attributes included from Base
Instance Method Summary collapse
-
#__carry_on ⇒ Boolean
If true, the action location will be retried after the fault response table, otherwise whatever should happen will happen (other error handling, …).
-
#action ⇒ #instanciate
An object that allows to create the toplevel task of the fault response.
-
#activate(exception, arguments = {}) ⇒ Object
private
Activate this fault handler for the given exception and arguments.
-
#carry_on ⇒ Object
Try the repaired action again when the fault handler successfully finishes.
-
#carry_on? ⇒ Boolean
If true, the last action of the response will be to retry whichever action/missions/tasks have been interrupted by the fault.
-
#execution_exception_matcher ⇒ Queries::ExecutionExceptionMatcher
The object defining for which faults this handler should be activated.
-
#fault_response_table ⇒ FaultResponseTable
The table this handler is part of.
- #find_response_locations(origin) ⇒ Object
- #locate_on_actions ⇒ Object
- #locate_on_missions ⇒ Object
- #locate_on_origin ⇒ Object
-
#priority ⇒ Integer
This handler’s priority.
-
#replace_by(task, until_event = nil) ⇒ Object
Replace the response’s location by this task when the fault handler script is finished.
-
#response_location ⇒ :missions, ...
The fault response location.
- #to_s ⇒ Object
-
#try_again ⇒ Object
deprecated
Deprecated.
use #carry_on
-
#try_again? ⇒ Boolean
deprecated
Deprecated.
use #carry_on?
Methods included from Script
#add, #call, #emit, #execute, #instructions, #sleep, #start, #terminal, #terminal?, #timeout_start, #timeout_stop, #wait
Methods included from Actions
#dependency, #depends_on, #event_active_in_state?, #forward, #from, #from_state, #map_tasks, #method_missing, #parse, #rebind, #required_tasks_for, #respond_to_missing?, #root_event?, #setup_submodel, #toplevel_state?
Methods included from Base
#find_event, #find_task_by_name, #map_tasks, #method_missing, #parse_names, #respond_to_missing?, #setup_submodel, #task, #task_model, #use_fault_response_table, #used_fault_response_table, #validate_event, #validate_or_create_task, #validate_task
Methods included from Arguments
#argument, #validate_arguments
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Roby::Coordination::Models::Actions
Instance Method Details
#__carry_on ⇒ Boolean
Returns if true, the action location will be retried after the fault response table, otherwise whatever should happen will happen (other error handling, …).
26 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 26 inherited_single_value_attribute(:__carry_on) { false } |
#action ⇒ #instanciate
Returns an object that allows to create the toplevel task of the fault response.
40 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 40 inherited_single_value_attribute :action |
#activate(exception, arguments = {}) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Activate this fault handler for the given exception and arguments. It creates the FaultHandlingTask and attaches the handler on it as an action script.
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 198 def activate(exception, arguments = {}) locations = find_response_locations(exception.origin) if locations.empty? Roby.warn "#{self} did match an exception, but the response location #{response_location} does not match anything" return end plan = exception.origin.plan # Create the response task plan.add(response_task = FaultHandlingTask.new) response_task.fault_handler = self new(response_task, arguments) response_task.start! locations.each do |task| # Mark :stop as handled by the response task and kill # the task # # In addition, if origin == task, we need to handle the # error events as well task.add_error_handler( response_task, [task.stop_event.to_execution_exception_matcher, execution_exception_matcher].to_set ) end locations.each do |task| # rubocop:disable Style/CombinableLoops # This should not be needed. However, the current GC # implementation in ExecutionEngine does not stop at # finished tasks, and therefore would not GC the # underlying tasks task.remove_children(Roby::TaskStructure::Dependency) task.stop! if task.running? end end |
#carry_on ⇒ Object
Try the repaired action again when the fault handler successfully finishes
It can be called anytime in the script, but will have an effect only at the end of the fault handler
66 67 68 69 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 66 def carry_on __carry_on(true) terminal end |
#carry_on? ⇒ Boolean
Returns if true, the last action of the response will be to retry whichever action/missions/tasks have been interrupted by the fault.
30 31 32 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 30 def carry_on? !!__carry_on end |
#execution_exception_matcher ⇒ Queries::ExecutionExceptionMatcher
Returns the object defining for which faults this handler should be activated.
17 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 17 inherited_single_value_attribute(:execution_exception_matcher) { Queries.none } |
#fault_response_table ⇒ FaultResponseTable
Returns the table this handler is part of.
12 13 14 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 12 def fault_response_table action_interface end |
#find_response_locations(origin) ⇒ Object
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 171 def find_response_locations(origin) return [origin].to_set if response_location == :origin predicate = case response_location when :missions proc { |t| t.mission? && t.running? } when :actions proc { |t| t.running? && t.planning_task && t.planning_task.kind_of?(Roby::Actions::Task) } end search_graph = origin.plan .task_relation_graph_for(TaskStructure::Dependency) .reverse visitor = ResponseLocationVisitor.new(search_graph, predicate) search_graph.depth_first_visit(origin, visitor) {} visitor.selected end |
#locate_on_actions ⇒ Object
51 52 53 54 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 51 def locate_on_actions response_location :actions self end |
#locate_on_missions ⇒ Object
46 47 48 49 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 46 def locate_on_missions response_location :missions self end |
#locate_on_origin ⇒ Object
56 57 58 59 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 56 def locate_on_origin response_location :origin self end |
#priority ⇒ Integer
Returns this handler’s priority.
19 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 19 inherited_single_value_attribute(:priority) { 0 } |
#replace_by(task, until_event = nil) ⇒ Object
Replace the response’s location by this task when the fault handler script is finished
It terminates the script, i.e. no instructions can be added after it is called
136 137 138 139 140 141 142 143 144 145 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 136 def replace_by(task, until_event = nil) __carry_on(false) replacement_task = validate_or_create_task(task) start replacement_task instructions << ReplaceBy.new(replacement_task) wait(until_event || replacement_task.success_event) instructions << FinalizeReplacement.new emit success_event terminal end |
#response_location ⇒ :missions, ...
Returns the fault response location.
22 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 22 inherited_single_value_attribute(:response_location) { :actions } |
#to_s ⇒ Object
42 43 44 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 42 def to_s "#{fault_response_table}.on_fault(#{execution_exception_matcher})" end |
#try_again ⇒ Object
use #carry_on
72 73 74 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 72 def try_again carry_on end |
#try_again? ⇒ Boolean
use #carry_on?
35 36 37 |
# File 'lib/roby/coordination/models/fault_handler.rb', line 35 def try_again? carry_on? end |