Sha256: 067d1570dd26ed650653671c0b0ada2926b12f5e28ff7313831107b3f9450cfb

Contents?: true

Size: 930 Bytes

Versions: 2

Compression:

Stored size: 930 Bytes

Contents

module Wukong
  class StormRunner < EM::P::LineAndTextProtocol
    include DriverMethods

    attr_accessor :dataflow, :settings

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

    def initialize(label, settings)
      super
      @settings = settings
      @dataflow = construct_dataflow(label, settings)
      @messages = []
    end

    def post_init
      setup_dataflow      
    end

    def receive_line line
      driver.send_through_dataflow(line)
      send_messages
    rescue => e
      $stderr.puts e.message
      EM.stop
    end

    def send_messages
      $stdout.write(@messages.join("\n") + settings.delimiter)
      $stdout.flush
      @messages.clear
    end

    def unbind
      EM.stop
    end

    def setup()                             ; end
    def process(record) @messages << record ; end
    def stop()                              ; end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
wukong-storm-0.0.2 lib/wukong-storm/runner.rb
wukong-storm-0.0.1 lib/wukong-storm/runner.rb