Class: Norikra::WebUI::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/norikra/webui/http.rb

Constant Summary collapse

DEFAULT_LISTEN_HOST =
'0.0.0.0'
DEFAULT_LISTEN_PORT =
26578
DEFAULT_THREADS =

26578 from 26571 and magic number 8 (for web)

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ HTTP

Returns a new instance of HTTP.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/norikra/webui/http.rb', line 21

def initialize(opts={})
  @engine = opts[:engine]
  @host = opts[:host] || DEFAULT_LISTEN_HOST
  @port = opts[:port] || DEFAULT_LISTEN_PORT
  @threads = opts[:threads] || DEFAULT_THREADS
  Norikra::WebUI::Handler.engine = @engine
  Norikra::WebUI::API.engine = @engine
  @app = Rack::Builder.new {
    map opts[:context_path] do
      map '/api' do
        run Norikra::WebUI::API
      end
      run Norikra::WebUI::Handler
    end
  }
end

Instance Attribute Details

#engineObject

Returns the value of attribute engine.



19
20
21
# File 'lib/norikra/webui/http.rb', line 19

def engine
  @engine
end

#hostObject

Returns the value of attribute host.



18
19
20
# File 'lib/norikra/webui/http.rb', line 18

def host
  @host
end

#mizunoObject

Returns the value of attribute mizuno.



19
20
21
# File 'lib/norikra/webui/http.rb', line 19

def mizuno
  @mizuno
end

#portObject

Returns the value of attribute port.



18
19
20
# File 'lib/norikra/webui/http.rb', line 18

def port
  @port
end

#threadObject

Returns the value of attribute thread.



19
20
21
# File 'lib/norikra/webui/http.rb', line 19

def thread
  @thread
end

#threadsObject

Returns the value of attribute threads.



18
19
20
# File 'lib/norikra/webui/http.rb', line 18

def threads
  @threads
end

Instance Method Details

#shut_off(mode) ⇒ Object



57
58
59
60
# File 'lib/norikra/webui/http.rb', line 57

def shut_off(mode)
  Norikra::WebUI::Handler.shut_off = mode
  Norikra::WebUI::API.shut_off = mode
end

#startObject



38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/norikra/webui/http.rb', line 38

def start
  info "WebUI server #{@host}:#{@port}, #{@threads} threads"
  @thread = Thread.new do
    @mizuno = Mizuno::Server.new
    options = {
      embedded: true, reuse_address: true,
      threads: @threads, min_threads: @threads,
      port: @port, host: @host
    }
    @mizuno.run(@app, options)
  end
end

#stopObject



51
52
53
54
55
# File 'lib/norikra/webui/http.rb', line 51

def stop
  @mizuno.stop
  @thread.kill
  @thread.join
end