Class: Wukong::Local::StdioDriver

Inherits:
EM::P::LineAndTextProtocol
  • Object
show all
Includes:
EventMachineDriver, Wukong::Logging, Processor::StdoutProcessor
Defined in:
lib/wukong/local/stdio_driver.rb

Overview

A class for driving processors over the STDIN/STDOUT protocol.

Instance Attribute Summary

Attributes included from DriverMethods

#dataflow, #settings

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Wukong::Logging

included

Methods included from Processor::StdoutProcessor

#process, #setup, #stop

Methods included from EventMachineDriver

included, #initialize

Methods included from DriverMethods

#add_serialization, #build_serializer, #construct_dataflow, #driver, #finalize_and_stop_dataflow, #finalize_dataflow, #lookup, #lookup_and_build, #setup_dataflow

Class Method Details

.start(label, settings = {}) ⇒ Object



11
12
13
# File 'lib/wukong/local/stdio_driver.rb', line 11

def self.start(label, settings = {})
  EM.attach($stdin, self, label, settings)
end

Instance Method Details

#post_initObject



15
16
17
18
# File 'lib/wukong/local/stdio_driver.rb', line 15

def post_init      
  self.class.add_signal_traps
  setup_dataflow
end

#receive_line(line) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/wukong/local/stdio_driver.rb', line 20

def receive_line line
  driver.send_through_dataflow(line)
rescue => e
  error = Wukong::Error.new(e)
  EM.stop
  
  # We'd to *raise* `error` here and have it be handled by
  # Wukong::Runner.run but we are fighting with EventMachine.
  # It seems no matter what we do, EventMachine will swallow any
  # Exception raised here (including SystemExit) and exit the
  # Ruby process with a return code of 0.
  #
  # Instead we just log the message that *would* have gotten
  # logged by Wukong::Runner.run and leave it to EventMachine to
  # exit very unnaturally.
  log.error(error.message)
end

#unbindObject



38
39
40
41
# File 'lib/wukong/local/stdio_driver.rb', line 38

def unbind
  finalize_and_stop_dataflow
  EM.stop
end