Class: DaemonicThreads::HTTP::Server
- Inherits:
-
Object
- Object
- DaemonicThreads::HTTP::Server
- Defined in:
- lib/ruby-daemonic-threads/http/server.rb
Overview
Почему я не использую Rack
1. У rack нет unregister handle
2. Не понятно - нужно ли хоть что-то из всего разнообразия веб-серверов доступных через Rack
3. Не понятно как работают тругие сервера с тредами.
Мы забираем тред из mongrel's ThreadGroup. Как на это отреагируют другие сервера.
4. У mongrel есть run/join/stop
Constant Summary collapse
- DEFAULT_HTTP_PORT =
4000
- DEFAULT_HTTP_BINDING =
"127.0.0.1"
Instance Attribute Summary collapse
-
#prefix ⇒ Object
readonly
Returns the value of attribute prefix.
Instance Method Summary collapse
-
#initialize(process) ⇒ Server
constructor
A new instance of Server.
- #join ⇒ Object
- #register(uri, handler) ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
- #unregister(uri) ⇒ Object
Constructor Details
#initialize(process) ⇒ Server
Returns a new instance of Server.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/ruby-daemonic-threads/http/server.rb', line 32 def initialize(process) argv = process.controller.argv argv.option "-b, --binding IPADDR", "IP address to bind to, #{DEFAULT_HTTP_BINDING} as default" argv.option "-p, --port PORT", "HTTP port to listen to, #{DEFAULT_HTTP_PORT} as default" argv.parse! @binding = argv["binding"] || DEFAULT_HTTP_BINDING @port = argv["port"] || DEFAULT_HTTP_PORT @prefix = process.name @server = Mongrel::HttpServer.new(@binding, @port) @mutex = Mutex.new end |
Instance Attribute Details
#prefix ⇒ Object (readonly)
Returns the value of attribute prefix.
49 50 51 |
# File 'lib/ruby-daemonic-threads/http/server.rb', line 49 def prefix @prefix end |
Instance Method Details
#join ⇒ Object
57 58 59 |
# File 'lib/ruby-daemonic-threads/http/server.rb', line 57 def join @server.acceptor.join if @server.acceptor end |
#register(uri, handler) ⇒ Object
65 66 67 68 69 |
# File 'lib/ruby-daemonic-threads/http/server.rb', line 65 def register uri, handler @mutex.synchronize do @server.register uri, handler end end |
#start ⇒ Object
51 52 53 54 55 |
# File 'lib/ruby-daemonic-threads/http/server.rb', line 51 def start @server.run register("/#{@prefix}/status", Mongrel::StatusHandler.new) end |
#stop ⇒ Object
61 62 63 |
# File 'lib/ruby-daemonic-threads/http/server.rb', line 61 def stop @server.stop end |
#unregister(uri) ⇒ Object
71 72 73 74 75 |
# File 'lib/ruby-daemonic-threads/http/server.rb', line 71 def unregister uri @mutex.synchronize do @server.unregister uri end end |