Class: EM::ProcessBuffer::Watcher
- Inherits:
-
Object
- Object
- EM::ProcessBuffer::Watcher
- Defined in:
- lib/eventmachine/process_buffer/watcher.rb
Instance Attribute Summary collapse
-
#pid ⇒ Object
readonly
Returns the value of attribute pid.
-
#pid_file ⇒ Object
readonly
Returns the value of attribute pid_file.
-
#pipe_directory ⇒ Object
readonly
Returns the value of attribute pipe_directory.
-
#working_directory ⇒ Object
readonly
Returns the value of attribute working_directory.
Instance Method Summary collapse
- #attach_to_process ⇒ Object
-
#initialize(pid_file, pipe_directory, working_directory, *args) ⇒ Watcher
constructor
A new instance of Watcher.
- #pipe_stdin ⇒ Object
- #pipe_stdout ⇒ Object
- #post_init ⇒ Object
- #process_exited ⇒ Object
- #process_started ⇒ Object
- #process_watched ⇒ Object
- #receive_stdout(line) ⇒ Object
- #send_stdin(line) ⇒ Object
Constructor Details
#initialize(pid_file, pipe_directory, working_directory, *args) ⇒ Watcher
Returns a new instance of Watcher.
7 8 9 10 11 12 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 7 def initialize pid_file, pipe_directory, working_directory, *args @pid_file = pid_file @pipe_directory = pipe_directory @working_directory = working_directory @pid = File.read(pid_file).strip.to_i end |
Instance Attribute Details
#pid ⇒ Object (readonly)
Returns the value of attribute pid.
5 6 7 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 5 def pid @pid end |
#pid_file ⇒ Object (readonly)
Returns the value of attribute pid_file.
5 6 7 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 5 def pid_file @pid_file end |
#pipe_directory ⇒ Object (readonly)
Returns the value of attribute pipe_directory.
5 6 7 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 5 def pipe_directory @pipe_directory end |
#working_directory ⇒ Object (readonly)
Returns the value of attribute working_directory.
5 6 7 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 5 def working_directory @working_directory end |
Instance Method Details
#attach_to_process ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 40 def attach_to_process EM.attach(File.open(pipe_stdout, File::NONBLOCK + File::RDONLY), LineProcessor) do |lp| lp.on_line = method(:receive_stdout) end EM::PidPoller.on_exit pid, method(:process_exited) EM.next_tick { post_init process_watched } end |
#pipe_stdin ⇒ Object
32 33 34 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 32 def pipe_stdin File.join pipe_directory, 'pipe_stdin' end |
#pipe_stdout ⇒ Object
36 37 38 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 36 def pipe_stdout File.join pipe_directory, 'pipe_stdout' end |
#post_init ⇒ Object
14 15 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 14 def post_init end |
#process_exited ⇒ Object
28 29 30 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 28 def process_exited puts "watched process exited" end |
#process_started ⇒ Object
21 22 23 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 21 def process_started puts "watched process started" end |
#process_watched ⇒ Object
25 26 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 25 def process_watched end |
#receive_stdout(line) ⇒ Object
17 18 19 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 17 def receive_stdout line puts ">> #{line}" end |
#send_stdin(line) ⇒ Object
53 54 55 56 57 |
# File 'lib/eventmachine/process_buffer/watcher.rb', line 53 def send_stdin line File.open(pipe_stdin, 'w+') do |f| f.write "#{line}\n" end end |