Class: Syskit::NetworkGeneration::Async
- Extended by:
- Logger::Hierarchy
- Includes:
- Logger::Hierarchy, Roby::DRoby::EventLogging
- Defined in:
- lib/syskit/network_generation/async.rb
Overview
A partially asynchronous requirement resolver built on top of Engine
Defined Under Namespace
Classes: Resolution
Instance Attribute Summary collapse
-
#event_logger ⇒ Object
readonly
The Roby::DRoby::EventLogger used to log timings.
-
#future ⇒ Resolution
readonly
The future that does the async work.
-
#plan ⇒ Object
readonly
The target plan.
-
#thread_pool ⇒ Object
readonly
The thread pool (or, really, any of Concurrent executor).
Instance Method Summary collapse
- #apply ⇒ Object
- #cancel ⇒ Object
- #finished? ⇒ Boolean
-
#initialize(plan, event_logger: plan.event_logger, thread_pool: Concurrent::CachedThreadPool.new) ⇒ Async
constructor
A new instance of Async.
- #join ⇒ Object
- #prepare(requirement_tasks = Engine.discover_requirement_tasks_from_plan(plan)) ⇒ Object
- #start(requirement_tasks = Engine.discover_requirement_tasks_from_plan(plan)) ⇒ Object
- #transaction_committed? ⇒ Boolean
- #transaction_finalized? ⇒ Boolean
- #valid?(current = Engine.discover_requirement_tasks_from_plan(plan)) ⇒ Boolean
Constructor Details
#initialize(plan, event_logger: plan.event_logger, thread_pool: Concurrent::CachedThreadPool.new) ⇒ Async
Returns a new instance of Async
25 26 27 28 29 |
# File 'lib/syskit/network_generation/async.rb', line 25 def initialize(plan, event_logger: plan.event_logger, thread_pool: Concurrent::CachedThreadPool.new) @plan = plan @event_logger = event_logger @thread_pool = thread_pool end |
Instance Attribute Details
#event_logger ⇒ Object (readonly)
The Roby::DRoby::EventLogger used to log timings
13 14 15 |
# File 'lib/syskit/network_generation/async.rb', line 13 def event_logger @event_logger end |
#future ⇒ Resolution (readonly)
The future that does the async work
It is created by #start
23 24 25 |
# File 'lib/syskit/network_generation/async.rb', line 23 def future @future end |
#plan ⇒ Object (readonly)
The target plan
10 11 12 |
# File 'lib/syskit/network_generation/async.rb', line 10 def plan @plan end |
#thread_pool ⇒ Object (readonly)
The thread pool (or, really, any of Concurrent executor)
16 17 18 |
# File 'lib/syskit/network_generation/async.rb', line 16 def thread_pool @thread_pool end |
Instance Method Details
#apply ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/syskit/network_generation/async.rb', line 100 def apply engine = future.engine if future.fulfilled? required_instances = future.value begin engine.apply_system_network_to_plan(required_instances) rescue ::Exception => e engine.handle_resolution_exception(e, on_error: Engine.on_error) raise e end else engine.handle_resolution_exception(e, on_error: Engine.on_error) raise future.reason end end |
#cancel ⇒ Object
84 85 86 |
# File 'lib/syskit/network_generation/async.rb', line 84 def cancel future.cancel end |
#finished? ⇒ Boolean
88 89 90 |
# File 'lib/syskit/network_generation/async.rb', line 88 def finished? future.fulfilled? || future.rejected? end |
#join ⇒ Object
92 93 94 95 96 97 98 |
# File 'lib/syskit/network_generation/async.rb', line 92 def join result = future.value if future.rejected? raise future.reason end result end |
#prepare(requirement_tasks = Engine.discover_requirement_tasks_from_plan(plan)) ⇒ Object
63 64 65 66 67 68 69 70 71 72 |
# File 'lib/syskit/network_generation/async.rb', line 63 def prepare(requirement_tasks = Engine.discover_requirement_tasks_from_plan(plan)) future.cancel if future resolver = Resolution.new(plan, event_logger, requirement_tasks, executor: thread_pool) do Thread.current.name = 'syskit-async-resolution' log_timepoint_group 'syskit-async-resolution' do resolver.engine.resolve_system_network(requirement_tasks) end end @future = resolver end |
#start(requirement_tasks = Engine.discover_requirement_tasks_from_plan(plan)) ⇒ Object
74 75 76 77 78 |
# File 'lib/syskit/network_generation/async.rb', line 74 def start(requirement_tasks = Engine.discover_requirement_tasks_from_plan(plan)) resolver = prepare(requirement_tasks) resolver.execute resolver end |
#transaction_committed? ⇒ Boolean
35 36 37 |
# File 'lib/syskit/network_generation/async.rb', line 35 def transaction_committed? future.engine.work_plan.committed? end |
#transaction_finalized? ⇒ Boolean
31 32 33 |
# File 'lib/syskit/network_generation/async.rb', line 31 def transaction_finalized? future.engine.work_plan.finalized? end |
#valid?(current = Engine.discover_requirement_tasks_from_plan(plan)) ⇒ Boolean
80 81 82 |
# File 'lib/syskit/network_generation/async.rb', line 80 def valid?(current = Engine.discover_requirement_tasks_from_plan(plan)) current.to_set == future.requirement_tasks end |