Class: CARPS::Process
- Inherits:
-
SystemConfig
- Object
- YamlConfig
- SystemConfig
- CARPS::Process
- Defined in:
- lib/carps/util/process.rb
Overview
Responsible for launching other CARP processes
Class Method Summary collapse
- .filepath ⇒ Object
-
.singleton ⇒ Object
Get the process singleton.
Instance Method Summary collapse
-
#initialize(term, port, confirm = false) ⇒ Process
constructor
A new instance of Process.
-
#launch(resource, program) ⇒ Object
Launch a ruby program in another terminal window, which can access the resource over drb.
- #load_resources(term, port, confirm) ⇒ Object
- #parse_yaml(conf) ⇒ Object
-
#share(resource) ⇒ Object
Run a block in a new process, allowing access the first argument by passing it a URI referring to a DRb object.
-
#stop_sharing ⇒ Object
Stop sharing a resource.
Methods inherited from SystemConfig
Methods inherited from YamlConfig
Constructor Details
#initialize(term, port, confirm = false) ⇒ Process
Returns a new instance of Process.
44 45 46 |
# File 'lib/carps/util/process.rb', line 44 def initialize term, port, confirm = false load_resources term, port, confirm end |
Class Method Details
.filepath ⇒ Object
40 41 42 |
# File 'lib/carps/util/process.rb', line 40 def Process.filepath "process.yaml" end |
Instance Method Details
#launch(resource, program) ⇒ Object
Launch a ruby program in another terminal window, which can access the resource over drb
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/carps/util/process.rb', line 63 def launch resource, program @semaphore.synchronize do uri = share resource if uri cmd = shell_cmd program, uri puts "Launching: #{cmd}" system cmd stop_sharing end end end |
#load_resources(term, port, confirm) ⇒ Object
55 56 57 58 59 60 |
# File 'lib/carps/util/process.rb', line 55 def load_resources term, port, confirm @port = port @term = term @semaphore = Mutex.new @confirm = confirm end |
#parse_yaml(conf) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/carps/util/process.rb', line 48 def parse_yaml conf term = read_conf conf, "launch_terminal" port = read_conf(conf, "port").to_i confirm = read_conf conf, "wait" [term, port, confirm] end |
#share(resource) ⇒ Object
Run a block in a new process, allowing access the first argument by passing it a URI referring to a DRb object.
If already running, then the process will not launch until till the first process has completed.
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/carps/util/process.rb', line 90 def share resource begin local_only = ACL.new %w[deny all allow 127.0.0.1] DRb.install_acl local_only uri = "druby://localhost:" + @port.to_s DRb.start_service uri, resource return uri rescue StandardError => e UI::put_error "Error beginning CARPS-side IPC: #{e}" return nil end end |
#stop_sharing ⇒ Object
Stop sharing a resource.
76 77 78 79 80 81 82 83 84 85 |
# File 'lib/carps/util/process.rb', line 76 def stop_sharing if @confirm UI::question "Press enter when the sub-program has completed." end begin DRb.stop_service rescue StandardError => e UI::put_error "Could not stop IPC: #{e}" end end |