Sha256: def68d37252735dea2bee4c7dbec2a99c8dbf44bdc31a75a8d1c9c21b87dc360

Contents?: true

Size: 729 Bytes

Versions: 2

Compression:

Stored size: 729 Bytes

Contents

module JCukeForker
  class StatusServer
    include Observable

    attr_reader :io_in

    def initialize(io_in)
      @io_in = File.open(io_in, 'r')
      @io_in.sync = true
    end

    def run
      @master_thread = Thread.new do
        loop do
          raw_message = @io_in.gets(sep=$-0)
          next if raw_message.nil?
          handle_message(raw_message)
        end
      end
    end

    def shutdown
      if @io_in
        @io_in.close
        @master_thread.terminate
      end
    end

    def handle_message(raw_message)
      json_obj = JSON.parse raw_message
      fire json_obj.first, *json_obj[1..-1]
    end

    private

    def fire(*args)
      changed
      notify_observers *args
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
jcukeforker-0.4.0 lib/jcukeforker/status_server.rb
jcukeforker-0.3.1 lib/jcukeforker/status_server.rb