Module: Roby::ExecutionEngine::PropagationHandlerMethods Private
- Included in:
- Roby::ExecutionEngine, Roby::ExecutionEngine
- Defined in:
- lib/roby/execution_engine.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Add/remove propagation handler methods that are shared between the instance and the class
Instance Attribute Summary collapse
-
#external_events_handlers ⇒ Array<PollBlockDefinition>
readonly
private
Code blocks that get called at the beginning of each cycle.
-
#propagation_handlers ⇒ Array<PollBlockDefinition>
readonly
private
Code blocks that get called during propagation to handle some internal propagation mechanism.
-
#side_work_handlers ⇒ Array<PollBlockDefinition>
readonly
private
Code blocks that get called at the very end of the execution cycle, outside propagation context.
Instance Method Summary collapse
-
#add_propagation_handler(type: :external_events, description: "propagation handler", **poll_options, &block) ⇒ #dispose
private
The propagation handlers are blocks that should be called at various places during propagation for all plans.
-
#add_side_work_handler(description: "side work handler", **poll_options, &block) ⇒ Object
private
Execute the given block at the end of a cycle, just before sleeping until the beginning of the next cycle.
-
#at_cycle_begin(description: "at_cycle_begin", **options, &block) ⇒ Object
private
Add a handler that is called at the beginning of the execution cycle.
-
#create_propagation_handler(type: :external_events, description: "propagation handler", **poll_options, &block) ⇒ Object
private
Helper method that gets the arguments necessary top create a propagation handler, sanitizes and normalizes them, and returns both the propagation type and the PollBlockDefinition object.
-
#each_cycle(description: "each_cycle", &block) ⇒ Object
private
Execute the given block at the beginning of each cycle, in propagation context.
-
#remove_propagation_handler(id) ⇒ Object
private
This method removes a propagation handler which has been added by #add_propagation_handler.
-
#remove_side_work_handler(handler_id) ⇒ Object
private
Remove a handler registered with #add_side_work_handler.
Instance Attribute Details
#external_events_handlers ⇒ Array<PollBlockDefinition> (readonly)
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.
Code blocks that get called at the beginning of each cycle
273 274 275 |
# File 'lib/roby/execution_engine.rb', line 273 def external_events_handlers @external_events_handlers end |
#propagation_handlers ⇒ Array<PollBlockDefinition> (readonly)
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.
Code blocks that get called during propagation to handle some internal propagation mechanism
278 279 280 |
# File 'lib/roby/execution_engine.rb', line 278 def propagation_handlers @propagation_handlers end |
#side_work_handlers ⇒ Array<PollBlockDefinition> (readonly)
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.
Code blocks that get called at the very end of the execution cycle, outside propagation context
283 284 285 |
# File 'lib/roby/execution_engine.rb', line 283 def side_work_handlers @side_work_handlers end |
Instance Method Details
#add_propagation_handler(type: :external_events, description: "propagation handler", **poll_options, &block) ⇒ #dispose
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.
The propagation handlers are blocks that should be called at various places during propagation for all plans. These objects are called in propagation context, which means that the events they would call or emit are injected in the propagation process itself.
335 336 337 338 339 340 341 342 343 344 |
# File 'lib/roby/execution_engine.rb', line 335 def add_propagation_handler(type: :external_events, description: "propagation handler", **, &block) type, handler = create_propagation_handler(type: type, description: description, **, &block) case type when :propagation propagation_handlers << handler when :external_events external_events_handlers << handler end handler end |
#add_side_work_handler(description: "side work handler", **poll_options, &block) ⇒ 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.
Execute the given block at the end of a cycle, just before sleeping until the beginning of the next cycle.
The blocks are NOT called in propagation context, do NOT do anything event-related in there
381 382 383 384 385 386 387 |
# File 'lib/roby/execution_engine.rb', line 381 def add_side_work_handler(description: "side work handler", **, &block) # Reuse the propagation handler stuff, even if it's a bit # overkill handler = PollBlockDefinition.new(description, block, **) side_work_handlers << handler handler.id end |
#at_cycle_begin(description: "at_cycle_begin", **options, &block) ⇒ 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.
Add a handler that is called at the beginning of the execution cycle
360 361 362 |
# File 'lib/roby/execution_engine.rb', line 360 def at_cycle_begin(description: "at_cycle_begin", **, &block) add_propagation_handler(description: description, type: :external_events, **, &block) end |
#create_propagation_handler(type: :external_events, description: "propagation handler", **poll_options, &block) ⇒ 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.
Helper method that gets the arguments necessary top create a propagation handler, sanitizes and normalizes them, and returns both the propagation type and the Roby::ExecutionEngine::PollBlockDefinition object
297 298 299 300 301 302 303 304 305 306 307 308 309 |
# File 'lib/roby/execution_engine.rb', line 297 def create_propagation_handler(type: :external_events, description: "propagation handler", **, &block) check_arity block, 1 handler = PollBlockDefinition.new(description, block, **) if type == :external_events if handler.late? raise ArgumentError, "only :propagation handlers can be marked as 'late', the external event handlers cannot" end elsif type != :propagation raise ArgumentError, "invalid value for the :type option. Expected :propagation or :external_events, got #{type}" end [type, handler] end |
#each_cycle(description: "each_cycle", &block) ⇒ 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.
Execute the given block at the beginning of each cycle, in propagation context.
369 370 371 |
# File 'lib/roby/execution_engine.rb', line 369 def each_cycle(description: "each_cycle", &block) add_propagation_handler(description: description, &block) end |
#remove_propagation_handler(id) ⇒ 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.
This method removes a propagation handler which has been added by #add_propagation_handler.
351 352 353 354 355 356 357 |
# File 'lib/roby/execution_engine.rb', line 351 def remove_propagation_handler(id) # Some code relied on remove_propagation_handler being a no-op # if id is nil. Keep this, especially since # remove_propagation_handler will in-fine completely be removed id&.dispose nil end |
#remove_side_work_handler(handler_id) ⇒ 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.
Remove a handler registered with #add_side_work_handler
393 394 395 396 |
# File 'lib/roby/execution_engine.rb', line 393 def remove_side_work_handler(handler_id) side_work_handlers.delete_if { |p| p.id == handler_id } nil end |