Class: Pione::Front::BasicFront
- Inherits:
-
PioneObject
- Object
- PioneObject
- Pione::Front::BasicFront
- Includes:
- DRbUndumped
- Defined in:
- lib/pione/front/basic-front.rb
Overview
This is base class for all PIONE front classes. PIONE fronts exist in each command and behave as remote control interface.
Direct Known Subclasses
ClientFront, DiagnosisNotificationFront, InteractiveFront, NotificationListenerFront, RelayFront, TaskWorkerBrokerFront, TaskWorkerFront, TupleSpaceProviderFront
Instance Attribute Summary collapse
-
#uri ⇒ Object
readonly
front server's URI string.
Instance Method Summary collapse
- #[](name) ⇒ Object
- #[]=(name, val) ⇒ Object
-
#child_front_uri(pid) ⇒ String
Return a front URI of the child PID.
-
#child_pids ⇒ Array
Return list of child process's PIDs.
-
#initialize(cmd, port) ⇒ BasicFront
constructor
Creates a front server as druby's service.
-
#pid ⇒ Object
Return PID of the process.
-
#register_child(pid, front_uri) ⇒ void
Register the process as a child of this process.
- #system_logger ⇒ Object
-
#terminate ⇒ Object
Terminate the front server.
-
#terminate_command ⇒ Object
Terminate the command.
-
#unregister_child(pid) ⇒ Object
Unregister the child process.
Constructor Details
#initialize(cmd, port) ⇒ BasicFront
Creates a front server as druby's service.
11 12 13 14 15 16 17 18 |
# File 'lib/pione/front/basic-front.rb', line 11 def initialize(cmd, port) @cmd = cmd @uri = URI.parse(start_service(port, {})) # port is number or range @attr = {} @child = {} @child_lock = Mutex.new @child_watchers = ThreadGroup.new end |
Instance Attribute Details
#uri ⇒ Object (readonly)
front server's URI string
8 9 10 |
# File 'lib/pione/front/basic-front.rb', line 8 def uri @uri end |
Instance Method Details
#[](name) ⇒ Object
25 26 27 |
# File 'lib/pione/front/basic-front.rb', line 25 def [](name) @attr[name] end |
#[]=(name, val) ⇒ Object
29 30 31 |
# File 'lib/pione/front/basic-front.rb', line 29 def []=(name, val) @attr[name] = val end |
#child_front_uri(pid) ⇒ String
Return a front URI of the child PID.
91 92 93 |
# File 'lib/pione/front/basic-front.rb', line 91 def child_front_uri(pid) @child[pid] end |
#child_pids ⇒ Array
Return list of child process's PIDs.
83 84 85 |
# File 'lib/pione/front/basic-front.rb', line 83 def child_pids @child.keys end |
#pid ⇒ Object
Return PID of the process.
21 22 23 |
# File 'lib/pione/front/basic-front.rb', line 21 def pid Process.pid end |
#register_child(pid, front_uri) ⇒ void
This method returns an undefined value.
Register the process as a child of this process. It is unregistered when the child is terminated.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/pione/front/basic-front.rb', line 41 def register_child(pid, front_uri) unless @cmd.current_phase == :termination # register child's PID @child_lock.synchronize {@child[pid] = front_uri} # unregister automatically when the child is terminated thread = Thread.new do Util.ignore_exception(Errno::ECHILD) do Process.waitpid(pid) unregister_child(pid) end end thread[:pid] = pid @child_watchers.add(thread) return nil else raise ChildRegistrationError.new end end |
#system_logger ⇒ Object
95 96 97 |
# File 'lib/pione/front/basic-front.rb', line 95 def system_logger Log::SystemLog.logger end |
#terminate ⇒ Object
Terminate the front server. This method assumes to be not called from other processes. Note that front servers have no responsibility of killing child processes.
102 103 104 |
# File 'lib/pione/front/basic-front.rb', line 102 def terminate DRb.stop_service end |
#terminate_command ⇒ Object
Terminate the command. This is a nonblocking method because callee process cannot tell its termination to caller, so it returns true immediately.
109 110 111 112 |
# File 'lib/pione/front/basic-front.rb', line 109 def terminate_command Thread.new {@cmd.terminate} return true end |
#unregister_child(pid) ⇒ Object
Unregister the child process.
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/pione/front/basic-front.rb', line 66 def unregister_child(pid) # unregister the pid @child_lock.synchronize {@child.delete(pid)} # kill the watcher thread @child_watchers.list.each do |thread| if thread[:pid] == pid thread.kill break end end end |