Class: Noda::JobMonitor
- Inherits:
-
Object
- Object
- Noda::JobMonitor
- Defined in:
- lib/noda/job_monitor.rb
Overview
$ noda_job_server start
Instance Attribute Summary collapse
-
#job_server ⇒ Object
Returns the value of attribute job_server.
-
#web_server ⇒ Object
Returns the value of attribute web_server.
Instance Method Summary collapse
-
#init_webrick ⇒ Object
内部で使うWEBRickをインスタンス化してマウントします..
-
#initialize(addr = "localhost", port = "10080", job_server = "druby://localhost:10001") ⇒ JobMonitor
constructor
A new instance of JobMonitor.
- #start_monitor ⇒ Object
- #stop_monitor ⇒ Object
Constructor Details
#initialize(addr = "localhost", port = "10080", job_server = "druby://localhost:10001") ⇒ JobMonitor
Returns a new instance of JobMonitor.
17 18 19 20 21 22 |
# File 'lib/noda/job_monitor.rb', line 17 def initialize(addr="localhost",port="10080",job_server="druby://localhost:10001") @job_server = DRbObject.new_with_uri(job_server) @addr = addr @port = port self.init_webrick end |
Instance Attribute Details
#job_server ⇒ Object
Returns the value of attribute job_server.
16 17 18 |
# File 'lib/noda/job_monitor.rb', line 16 def job_server @job_server end |
#web_server ⇒ Object
Returns the value of attribute web_server.
16 17 18 |
# File 'lib/noda/job_monitor.rb', line 16 def web_server @web_server end |
Instance Method Details
#init_webrick ⇒ Object
内部で使うWEBRickをインスタンス化してマウントします.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/noda/job_monitor.rb', line 31 def init_webrick config = WEBrick::Config::HTTP config[:Port] = @port config[:BindAddress]=@addr config[:AccessLog] = WEBrick::Log.new("/dev/null",1) #ログ要らない. config[:Logger] = Logger.new("/dev/null") #ログ要らない. @web_server = WEBrick::HTTPServer.new(config) @web_server.mount_proc '/' do |req,res| res.content_type="text/plain" res.body = "running" if @job_server.alive? res.body = "stopped" unless @job_server.alive? end @web_server.mount_proc '/in_queue' do |req,res| res.content_type="text/plain" if req.path_info =~ %r'^/(\d+)$' then num = $1.to_i res.body = @job_server.input._at(num).to_s end if req.path_info =~ %r'^/$' then res.body = @job_server.input.size.to_s end end @web_server.mount_proc '/out_queue' do |req,res| res.content_type="text/plain" if req.path_info =~ %r'^/(\d+)$' then num = $1.to_i res.body = @job_server.output._at(num).to_s end if req.path_info =~ %r'^/$' then res.body = @job_server.output.size.to_s end end @web_server.mount_proc '/hash_table' do |req,res| res.content_type="text/plain" res.body = @job_server.hash_table.size.to_s end @web_server.mount_proc '/hash_table/keys' do |req,res| res.content_type="text/plain" res.body = @job_server.hash_table.keys.inspect end @web_server.mount_proc '/hash_table/fetch' do |req,res| res.content_type="text/plain" if req.path_info =~ %r'^/([^/]+)$' then key = $1.to_s res.body = @job_server.hash_table.get(key).to_s end end end |
#start_monitor ⇒ Object
23 24 25 26 |
# File 'lib/noda/job_monitor.rb', line 23 def start_monitor trap("INT"){ @web_server.shutdown } @thread = Thread.new{ @web_server.start} end |
#stop_monitor ⇒ Object
27 28 29 |
# File 'lib/noda/job_monitor.rb', line 27 def stop_monitor @web_server.stop end |