Module: RightScale::StdOutHandler

Defined in:
lib/linux/right_popen.rb

Overview

Provides an eventmachine callback handler for the stdout stream.

Instance Method Summary collapse

Instance Method Details

#initialize(target, stdout_handler, exit_handler, stderr_eventable, read_fd, write_fd) ⇒ Object

Parameters

target(Object): Object defining handler methods to be called.

stdout_handler(String): Token for stdout handler method name.

exit_handler(String): Token for exit handler method name.

stderr_eventable(Connector): EM object representing stderr handler.

read_fd(IO): Standard output read file descriptor.

write_fd(IO): Standard output write file descriptor.



49
50
51
52
53
54
55
56
57
# File 'lib/linux/right_popen.rb', line 49

def initialize(target, stdout_handler, exit_handler, stderr_eventable, read_fd, write_fd)
  @target = target
  @stdout_handler = stdout_handler
  @exit_handler = exit_handler
  @stderr_eventable = stderr_eventable
  # Just so they don't get GCed before the process goes away
  @read_fd = read_fd
  @write_fd = write_fd
end

#receive_data(data) ⇒ Object

Callback from EM to receive data.



60
61
62
# File 'lib/linux/right_popen.rb', line 60

def receive_data(data)
  @target.method(@stdout_handler).call(data) if @stdout_handler
end

#unbindObject

Callback from EM to unbind.



65
66
67
68
69
70
# File 'lib/linux/right_popen.rb', line 65

def unbind
  # We force the attached stderr handler to go away so that
  # we don't end up with a broken pipe
  @stderr_eventable.force_detach if @stderr_eventable
  @target.method(@exit_handler).call(get_status) if @exit_handler
end