Class: JCukeForker::StatusServer

Inherits:
Object
  • Object
show all
Includes:
Observable
Defined in:
lib/jcukeforker/status_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io_in) ⇒ StatusServer

Returns a new instance of StatusServer.



8
9
10
11
# File 'lib/jcukeforker/status_server.rb', line 8

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

Instance Attribute Details

#io_inObject (readonly)

Returns the value of attribute io_in.



6
7
8
# File 'lib/jcukeforker/status_server.rb', line 6

def io_in
  @io_in
end

Instance Method Details

#handle_message(raw_message) ⇒ Object



30
31
32
33
# File 'lib/jcukeforker/status_server.rb', line 30

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

#runObject



13
14
15
16
17
18
19
20
21
# File 'lib/jcukeforker/status_server.rb', line 13

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

#shutdownObject



23
24
25
26
27
28
# File 'lib/jcukeforker/status_server.rb', line 23

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