Class: Orocos::RubyTasks::Process
- Inherits:
-
ProcessBase
- Object
- ProcessBase
- Orocos::RubyTasks::Process
- Defined in:
- lib/orocos/ruby_tasks/process.rb
Overview
Representation and management of a set of ruby tasks
This provides a Process-compatible API to ruby tasks. It allows to define tasks in an oroGen deployment model and “spawn” them all at once, as well as dispose of them all at once.
Instance Attribute Summary collapse
-
#deployed_tasks ⇒ {String=>TaskContext}
readonly
The set of deployed tasks.
-
#ruby_process_server ⇒ #dead_deployment?
readonly
The Ruby process server that spawned this process.
-
#task_context_class ⇒ Class
readonly
The task context class that should be used on the client side.
Attributes inherited from ProcessBase
#default_logger, #logged_ports, #model, #name, #name_mappings, #tasks
Instance Method Summary collapse
-
#alive? ⇒ Boolean
True if the process is running.
- #dead!(status = ProcessManager::Status.new(:exit_code => 0)) ⇒ Object
-
#host_id ⇒ String
The host on which this process' tasks run.
-
#initialize(ruby_process_server, name, model, task_context_class: TaskContext) ⇒ Process
constructor
Creates a new ruby task process.
- #join ⇒ Object
- #kill(wait = true, status = ProcessManager::Status.new(:exit_code => 0)) ⇒ Object
-
#on_localhost? ⇒ Boolean
Whether the tasks in this process are running on the same machine than the ruby process.
-
#pid ⇒ Integer
The PID of the process in which the tasks run.
- #resolve_all_tasks(cache = Hash.new) ⇒ Object
-
#running? ⇒ Boolean
True if the process is running.
-
#spawn(options = Hash.new) ⇒ void
Deploys the tasks defined in ProcessBase#model as ruby tasks.
- #task(task_name) ⇒ Object
-
#wait_running(blocking = false) ⇒ Object
Waits for the tasks to be ready.
Methods inherited from ProcessBase
#default_log_file_name, #default_logger_name, #each_task, #get_mapped_name, #log_all_ports, #map_name, #orogen, #register_task, resolve_prefix, #setup_default_logger, #task_names
Constructor Details
#initialize(ruby_process_server, name, model, task_context_class: TaskContext) ⇒ Process
Creates a new ruby task process
63 64 65 66 67 68 |
# File 'lib/orocos/ruby_tasks/process.rb', line 63 def initialize(ruby_process_server, name, model, task_context_class: TaskContext) @ruby_process_server = ruby_process_server @deployed_tasks = Hash.new @task_context_class = task_context_class super(name, model) end |
Instance Attribute Details
#deployed_tasks ⇒ {String=>TaskContext} (readonly)
The set of deployed tasks
22 23 24 |
# File 'lib/orocos/ruby_tasks/process.rb', line 22 def deployed_tasks @deployed_tasks end |
#ruby_process_server ⇒ #dead_deployment? (readonly)
The Ruby process server that spawned this process
If non-nil, the object's #dead_deployment will be called when self is stopped
16 17 18 |
# File 'lib/orocos/ruby_tasks/process.rb', line 16 def ruby_process_server @ruby_process_server end |
#task_context_class ⇒ Class (readonly)
The task context class that should be used on the client side
Defaults to TaskContext, another option is StubTaskContext
54 55 56 |
# File 'lib/orocos/ruby_tasks/process.rb', line 54 def task_context_class @task_context_class end |
Instance Method Details
#alive? ⇒ Boolean
True if the process is running. This is an alias for running?
124 |
# File 'lib/orocos/ruby_tasks/process.rb', line 124 def alive?; @alive end |
#dead!(status = ProcessManager::Status.new(:exit_code => 0)) ⇒ Object
112 113 114 115 116 117 |
# File 'lib/orocos/ruby_tasks/process.rb', line 112 def dead!(status = ProcessManager::Status.new(:exit_code => 0)) @alive = false if ruby_process_server ruby_process_server.dead_deployment(name, status) end end |
#host_id ⇒ String
The host on which this process' tasks run
This is always 'localhost' as ruby tasks are instanciated inside the ruby process
30 |
# File 'lib/orocos/ruby_tasks/process.rb', line 30 def host_id; 'localhost' end |
#join ⇒ Object
119 120 121 |
# File 'lib/orocos/ruby_tasks/process.rb', line 119 def join raise NotImplementedError, "RemoteProcess#join is not implemented" end |
#kill(wait = true, status = ProcessManager::Status.new(:exit_code => 0)) ⇒ Object
105 106 107 108 109 110 |
# File 'lib/orocos/ruby_tasks/process.rb', line 105 def kill(wait = true, status = ProcessManager::Status.new(:exit_code => 0)) deployed_tasks.each_value do |task| task.dispose end dead!(status) end |
#on_localhost? ⇒ Boolean
Whether the tasks in this process are running on the same machine than the ruby process
This is always true as ruby tasks are instanciated inside the ruby process
39 |
# File 'lib/orocos/ruby_tasks/process.rb', line 39 def on_localhost?; true end |
#pid ⇒ Integer
The PID of the process in which the tasks run
This is always Process.pid as ruby tasks are instanciated inside the ruby process
47 |
# File 'lib/orocos/ruby_tasks/process.rb', line 47 def pid; ::Process.pid end |
#resolve_all_tasks(cache = Hash.new) ⇒ Object
99 100 101 102 103 |
# File 'lib/orocos/ruby_tasks/process.rb', line 99 def resolve_all_tasks(cache = Hash.new) Orocos::Process.resolve_all_tasks(self, cache) do |task_name| task(task_name) end end |
#running? ⇒ Boolean
True if the process is running. This is an alias for alive?
126 |
# File 'lib/orocos/ruby_tasks/process.rb', line 126 def running?; @alive end |
#spawn(options = Hash.new) ⇒ void
This method returns an undefined value.
Deploys the tasks defined in ProcessBase#model as ruby tasks
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/orocos/ruby_tasks/process.rb', line 73 def spawn( = Hash.new) model.task_activities.each do |deployed_task| name = get_mapped_name(deployed_task.name) Orocos.allow_blocking_calls do deployed_tasks[name] = task_context_class. from_orogen_model(name, deployed_task.task_model) end end @alive = true end |
#task(task_name) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/orocos/ruby_tasks/process.rb', line 92 def task(task_name) if t = deployed_tasks[task_name] t else raise ArgumentError, "#{self} has no task called #{task_name}, known tasks: #{deployed_tasks.keys.sort.join(", ")}" end end |
#wait_running(blocking = false) ⇒ Object
Waits for the tasks to be ready
This is a no-op for ruby tasks as they are ready as soon as they are created
88 89 90 |
# File 'lib/orocos/ruby_tasks/process.rb', line 88 def wait_running(blocking = false) true end |