Class: Vrowser::HTTPDaemon

Inherits:
Object
  • Object
show all
Defined in:
lib/vrowser/http_daemon.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ HTTPDaemon

Returns a new instance of HTTPDaemon.

Yields:

  • (_self)

Yield Parameters:



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(options={})
  @config_path = options[:config_path] or raise ArgumentError("config_path")

  @server = WEBrick::HTTPServer.new(options)
  @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(options={})
  self.new(options) 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

#startObject



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

#stopObject



92
93
94
95
# File 'lib/vrowser/http_daemon.rb', line 92

def stop
  @server.shutdown if @server
  Thread.kill(@th) if @th
end