Class: Zapp::Server
- Inherits:
-
Object
- Object
- Zapp::Server
- Defined in:
- lib/zapp/server.rb
Overview
The Zap HTTP Server, listens on a TCP connection and processes incoming requests
Instance Attribute Summary collapse
-
#socket_pipe_receiver ⇒ Object
readonly
Returns the value of attribute socket_pipe_receiver.
-
#worker_pool ⇒ Object
readonly
Returns the value of attribute worker_pool.
Instance Method Summary collapse
-
#initialize ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #shutdown(err = nil) ⇒ Object
Constructor Details
#initialize ⇒ Server
Returns a new instance of Server.
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/zapp/server.rb', line 8 def initialize # Ensure config.ru file is loaded just once by main ractor Zapp.config.app @socket_pipe = Zapp::Pipe.for(TCPSocket) @context_pipe = Zapp::Pipe.for(Zapp::HTTPContext::Context, Symbol) @socket_pipe_receiver = Zapp::SocketPipe::Receiver.new(pipe: @socket_pipe) @worker_pool = Zapp::WorkerPool.new(socket_pipe: @socket_pipe, context_pipe: @context_pipe) end |
Instance Attribute Details
#socket_pipe_receiver ⇒ Object (readonly)
Returns the value of attribute socket_pipe_receiver.
6 7 8 |
# File 'lib/zapp/server.rb', line 6 def socket_pipe_receiver @socket_pipe_receiver end |
#worker_pool ⇒ Object (readonly)
Returns the value of attribute worker_pool.
6 7 8 |
# File 'lib/zapp/server.rb', line 6 def worker_pool @worker_pool end |
Instance Method Details
#run ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/zapp/server.rb', line 20 def run log_start loop do socket = socket_pipe_receiver.take next if socket.eof? parsing_thread_pool.post do ctx = Zapp::HTTPContext::Context.new(socket: socket) worker_pool.process(context: ctx) unless ctx.client_closed? # Parsing failed end rescue Errno::ECONNRESET next end rescue SignalException, IRB::Abort => e shutdown(e) end |
#shutdown(err = nil) ⇒ Object
40 41 42 43 44 45 46 47 48 |
# File 'lib/zapp/server.rb', line 40 def shutdown(err = nil) Zapp::Logger.info("Received signal #{err.class.name}") unless err.nil? Zapp::Logger.info("Gracefully shutting down workers, allowing request processing to finish") worker_pool.drain Zapp::Logger.info("Done. See you next time!") Zapp::Logger.flush end |