Class: Baleen::Server
- Inherits:
-
Object
- Object
- Baleen::Server
- Includes:
- Celluloid::IO
- Defined in:
- lib/baleen/server.rb
Instance Attribute Summary collapse
-
#containers ⇒ Object
Returns the value of attribute containers.
Instance Method Summary collapse
- #handle_connection(socket) ⇒ Object
- #handle_request(socket) ⇒ Object
-
#initialize(host, port: 4243) ⇒ Server
constructor
A new instance of Server.
- #parse_request(message) ⇒ Object
- #run ⇒ Object
- #shutdown ⇒ Object
Constructor Details
#initialize(host, port: 4243) ⇒ Server
Returns a new instance of Server.
16 17 18 19 20 21 22 |
# File 'lib/baleen/server.rb', line 16 def initialize(host, port: 4243) @base_url = "http://#{host}:#{port}" @docker = Docker::API.new(base_url: @base_url) @containers = @docker.containers @server = TCPServer.new("127.0.0.1", 12345) async.run end |
Instance Attribute Details
#containers ⇒ Object
Returns the value of attribute containers.
14 15 16 |
# File 'lib/baleen/server.rb', line 14 def containers @containers end |
Instance Method Details
#handle_connection(socket) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/baleen/server.rb', line 32 def handle_connection(socket) loop { handle_request(socket) } rescue Exception => ex case ex when IOError; nil # when trying to close already closed socket else warn "Unknown exception occured" ap ex raise ex end end |
#handle_request(socket) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/baleen/server.rb', line 45 def handle_request(socket) = socket.gets if .nil? socket.close return end msg = parse_request() case msg when Message::Request::PingPong socket.puts "pong" when Message::Request::ClientDisconnect socket.close when Message::Request::Cucumber manager = RunnerManager.new(@containers, socket, msg) manager.run else warn "Received unknown request" ap msg end end |
#parse_request(message) ⇒ Object
68 69 70 71 72 |
# File 'lib/baleen/server.rb', line 68 def parse_request() #info "Got request from client" #ap message Baleen::Message::Decoder.new().decode end |
#run ⇒ Object
24 25 26 |
# File 'lib/baleen/server.rb', line 24 def run loop { async.handle_connection @server.accept } end |
#shutdown ⇒ Object
28 29 30 |
# File 'lib/baleen/server.rb', line 28 def shutdown @server.close if @server end |