Class: JCukeForker::StatusServer
- Inherits:
-
Object
- Object
- JCukeForker::StatusServer
- Includes:
- Celluloid::IO, Observable
- Defined in:
- lib/jcukeforker/status_server.rb
Instance Attribute Summary collapse
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #handle_connection(socket) ⇒ Object
-
#initialize(port = '6333') ⇒ StatusServer
constructor
A new instance of StatusServer.
- #run ⇒ Object
- #shutdown ⇒ Object
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
#port ⇒ Object (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 = socket.gets json_obj = JSON.parse fire json_obj.first, *json_obj[1..-1] end socket.close end |
#run ⇒ Object
17 18 19 |
# File 'lib/jcukeforker/status_server.rb', line 17 def run loop { async.handle_connection @server.accept } end |
#shutdown ⇒ Object
21 22 23 |
# File 'lib/jcukeforker/status_server.rb', line 21 def shutdown @server.close if @server end |