Class: JCukeForker::StatusServer

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port = '6333') ⇒ StatusServer

Returns a new instance of StatusServer.



11
12
13
14
15
# File 'lib/jcukeforker/status_server.rb', line 11

def initialize(port = '6333')
  server = ::TCPServer.new 'localhost', port
  @port = server.connect_address.ip_port
  @server = TCPServer.from_ruby_server server
end

Instance Attribute Details

#portObject (readonly)

Returns the value of attribute port.



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

def port
  @port
end

Instance Method Details

#handle_connection(socket) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/jcukeforker/status_server.rb', line 25

def handle_connection(socket)
  until socket.eof? do
    raw_message = socket.gets
    json_obj = JSON.parse raw_message
    fire json_obj.first, *json_obj[1..-1]
  end
  socket.close
end

#runObject



17
18
19
# File 'lib/jcukeforker/status_server.rb', line 17

def run
  loop { async.handle_connection @server.accept }
end

#shutdownObject



21
22
23
# File 'lib/jcukeforker/status_server.rb', line 21

def shutdown
  @server.close if @server
end