Class: Syskit::RobyApp::UnmanagedTasksManager
- Defined in:
- lib/syskit/roby_app/unmanaged_tasks_manager.rb
Overview
A class API-compatible with Orocos::RemoteProcesses::Client but that handle components started externally to syskit
Defined Under Namespace
Classes: NameMappingsForbidden, Status
Instance Attribute Summary collapse
-
#loader ⇒ Object
readonly
The OroGen loader.
-
#name_service ⇒ #get
readonly
The name service that should be used to resolve the tasks.
-
#processes ⇒ Hash<String,UnmanagedProcess>
readonly
The set of processes started so far.
Instance Method Summary collapse
-
#create_log_dir(log_dir, time_tag, metadata = Hash.new) ⇒ Object
Creates a new log dir, and save the given time tag in it (used later on by save_log_dir).
- #disconnect ⇒ Object
-
#initialize(loader: Roby.app.default_loader, name_service: Orocos::CORBA.name_service) ⇒ UnmanagedTasksManager
constructor
A new instance of UnmanagedTasksManager.
-
#register_deployment_model(model) ⇒ Object
Register a new deployment model on this server.
-
#save_log_dir(log_dir, results_dir) ⇒ Object
Requests that the process server moves the log directory at
log_dir
toresults_dir
. -
#start(name, deployment_name = name, name_mappings = Hash.new, prefix: nil, **options) ⇒ UnmanagedProcess
Start a registered deployment.
-
#stop(world_name) ⇒ Object
Requests to stop the given deployment.
-
#wait_termination(timeout = nil) ⇒ Object
Waits for processes to terminate.
Constructor Details
#initialize(loader: Roby.app.default_loader, name_service: Orocos::CORBA.name_service) ⇒ UnmanagedTasksManager
Returns a new instance of UnmanagedTasksManager
41 42 43 44 45 46 47 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 41 def initialize(loader: Roby.app.default_loader, name_service: Orocos::CORBA.name_service) @loader = loader @processes = Hash.new @name_service = name_service @deployments = Hash.new end |
Instance Attribute Details
#loader ⇒ Object (readonly)
The OroGen loader
39 40 41 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 39 def loader @loader end |
#name_service ⇒ #get (readonly)
The name service that should be used to resolve the tasks
36 37 38 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 36 def name_service @name_service end |
#processes ⇒ Hash<String,UnmanagedProcess> (readonly)
The set of processes started so far
31 32 33 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 31 def processes @processes end |
Instance Method Details
#create_log_dir(log_dir, time_tag, metadata = Hash.new) ⇒ Object
Creates a new log dir, and save the given time tag in it (used later on by save_log_dir)
106 107 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 106 def create_log_dir(log_dir, time_tag, = Hash.new) end |
#disconnect ⇒ Object
49 50 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 49 def disconnect end |
#register_deployment_model(model) ⇒ Object
Register a new deployment model on this server.
If name mappings are needed, they must have been done in the model. #start does not support name mappings
56 57 58 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 56 def register_deployment_model(model) loader.register_deployment_model(model) end |
#save_log_dir(log_dir, results_dir) ⇒ Object
Requests that the process server moves the log directory at
log_dir
to results_dir
101 102 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 101 def save_log_dir(log_dir, results_dir) end |
#start(name, deployment_name = name, name_mappings = Hash.new, prefix: nil, **options) ⇒ UnmanagedProcess
Start a registered deployment
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 76 def start(name, deployment_name = name, name_mappings = Hash.new, prefix: nil, **) model = if deployment_name.respond_to?(:to_str) loader.deployment_model_from_name(deployment_name) else deployment_name end if processes[name] raise ArgumentError, "#{name} is already started in #{self}" end prefix_mappings = Orocos::ProcessBase.resolve_prefix(model, prefix) name_mappings = prefix_mappings.merge(name_mappings) name_mappings.each do |from, to| if from != to raise NameMappingsForbidden, "cannot do name mapping in unmanaged processes" end end process = UnmanagedProcess.new(self, name, model) process.spawn processes[name] = process end |
#stop(world_name) ⇒ Object
Requests to stop the given deployment
The call does not block until the process has quit. You will have to call #wait_termination to wait for the process end.
140 141 142 143 144 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 140 def stop(world_name) if w = processes[world_name] w.kill end end |
#wait_termination(timeout = nil) ⇒ Object
Waits for processes to terminate. timeout
is the number of
milliseconds we should wait. If set to nil, the call will block until a
process terminates
Returns a hash that maps deployment names to the Status object that represents their exit status.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/syskit/roby_app/unmanaged_tasks_manager.rb', line 115 def wait_termination(timeout = nil) # Verify that the monitor threads are in a good state, and # gather the ones that are actually dead dead_processes = Set.new processes.delete_if do |_, process| begin process.verify_threads_state rescue Exception => e process.fatal "assuming #{process} died because the background thread died with" Roby.log_exception(e, process, :fatal) dead_processes << process end if process.dead? dead_processes << process end dead_processes.include?(process) end dead_processes end |