Class: DaemonicThreads::HTTP::Server

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#prefixObject (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

#joinObject



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

#startObject



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

#stopObject



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