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.
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/vrowser/http_daemon.rb', line 63 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
56 57 58 59 60 |
# File 'lib/vrowser/http_daemon.rb', line 56 def self.start(={}) self.new() do |instance| instance.start end end |
Instance Method Details
#daemonize! ⇒ Object
88 89 90 |
# File 'lib/vrowser/http_daemon.rb', line 88 def daemonize! Process.daemon end |
#start ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/vrowser/http_daemon.rb', line 80 def start @th = Thread.start do fetch_and_update @config_path end regist_stop @server.start end |
#stop ⇒ Object
92 93 94 95 |
# File 'lib/vrowser/http_daemon.rb', line 92 def stop @server.shutdown if @server Thread.kill(@th) if @th end |