Class: Vrowser::HTTPDaemon
- Inherits:
-
Object
- Object
- Vrowser::HTTPDaemon
- Defined in:
- lib/vrowser/http_daemon.rb
Class Method Summary collapse
Instance Method Summary collapse
- #daemonize! ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ HTTPDaemon
constructor
A new instance of HTTPDaemon.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ HTTPDaemon
Returns a new instance of HTTPDaemon.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vrowser/http_daemon.rb', line 14 def initialize(={}) @config_path = [:config_path] or raise ArgumentError("config_path") @server = WEBrick::HTTPServer.new() @server.mount_proc("/api/updated/json"){ |req, res| res.header["Content-Type"] = "application/json" res.body = get_active_servers_nary.to_json } @server.mount_proc("/api/connected/json"){ |req, res| res.header["Content-Type"] = "application/json" res.body = get_active_servers.to_json } yield(self) if block_given? self end |
Class Method Details
.start(options = {}) ⇒ Object
7 8 9 10 11 |
# File 'lib/vrowser/http_daemon.rb', line 7 def self.start(={}) self.new() do |instance| instance.start end end |
Instance Method Details
#daemonize! ⇒ Object
39 40 41 |
# File 'lib/vrowser/http_daemon.rb', line 39 def daemonize! Process.daemon end |
#start ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/vrowser/http_daemon.rb', line 31 def start @th = Thread.start do fetch_and_update @config_path end regist_stop @server.start end |
#stop ⇒ Object
43 44 45 46 |
# File 'lib/vrowser/http_daemon.rb', line 43 def stop @server.shutdown if @server Thread.kill(@th) if @th end |