Class: Orocos::RubyTasks::ProcessManager

Inherits:
Object
  • Object
show all
Defined in:
lib/orocos/ruby_tasks/process_manager.rb

Overview

This is a drop-in replacement for ProcessClient. It creates Ruby tasks in the local process, based on the deployment models

Defined Under Namespace

Classes: Status

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loader = Orocos.default_loader, task_context_class: TaskContext) ⇒ ProcessManager

Returns a new instance of ProcessManager



32
33
34
35
36
37
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 32

def initialize(loader = Orocos.default_loader, task_context_class: TaskContext)
    @loader = loader
    @deployments = Hash.new
    @terminated_deployments = Hash.new
    @task_context_class = task_context_class
end

Instance Attribute Details

#deploymentsObject (readonly)

Returns the value of attribute deployments



21
22
23
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 21

def deployments
  @deployments
end

#loaderObject (readonly)

Returns the value of attribute loader



22
23
24
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 22

def loader
  @loader
end

#task_context_classClass (readonly)

The task context class that should be used on the client side

Defaults to TaskContext, another option is StubTaskContext

Returns:

  • (Class)


30
31
32
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 30

def task_context_class
  @task_context_class
end

#terminated_deploymentsObject (readonly)

Returns the value of attribute terminated_deployments



23
24
25
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 23

def terminated_deployments
  @terminated_deployments
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)



73
74
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 73

def create_log_dir(log_dir, time_tag,  = Hash.new)
end

#dead_deployment(deployment_name, status = Status.new(exit_code: 0)) ⇒ Object



98
99
100
101
102
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 98

def dead_deployment(deployment_name, status = Status.new(exit_code: 0))
    if deployment = deployments.delete(deployment_name)
        terminated_deployments[deployment] = status
    end
end

#disconnectObject



39
40
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 39

def disconnect
end

#register_deployment_model(model) ⇒ Object



42
43
44
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 42

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



68
69
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 68

def save_log_dir(log_dir, results_dir)
end

#start(name, deployment_name, name_mappings, options) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 46

def start(name, deployment_name, name_mappings, options)
    model = if deployment_name.respond_to?(:to_str)
                loader.deployment_model_from_name(deployment_name)
            else deployment_name
            end
    if deployments[name]
        raise ArgumentError, "#{name} is already started in #{self}"
    end

    prefix_mappings = Orocos::ProcessBase.resolve_prefix(model, options.delete(:prefix))
    name_mappings = prefix_mappings.merge(name_mappings)

    task_context_class = options.fetch(:task_context_class, self.task_context_class)
    ruby_deployment = Process.new(self, name, model,
                                  task_context_class: task_context_class)
    ruby_deployment.name_mappings = name_mappings
    ruby_deployment.spawn
    deployments[name] = ruby_deployment
end

#stop(deployment_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.



92
93
94
95
96
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 92

def stop(deployment_name)
    if deployment = deployments[deployment_name]
        deployment.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.



82
83
84
85
86
# File 'lib/orocos/ruby_tasks/process_manager.rb', line 82

def wait_termination(timeout = nil)
    result, @terminated_deployments =
       terminated_deployments, Hash.new
    result
end