Sha256: 5bb23e31d5aaa73f93b0dcbc58a52a59004576f791cd980bcdd0d20c819bf2f4

Contents?: true

Size: 1.19 KB

Versions: 15

Compression:

Stored size: 1.19 KB

Contents

require 'mizuno/server'
require 'rack/builder'

require_relative 'handler'
require_relative 'api'

require 'norikra/logger'
include Norikra::Log

module Norikra::WebUI
  class HTTP
    DEFAULT_LISTEN_HOST = '0.0.0.0'
    DEFAULT_LISTEN_PORT = 26578
    # 26578 from 26571 and magic number 8 (for web)

    DEFAULT_THREADS = 2

    attr_accessor :host, :port, :threads
    attr_accessor :engine, :mizuno, :thread

    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 '/api' do
          run Norikra::WebUI::API
        end
        run Norikra::WebUI::Handler
      }
    end

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

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

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
norikra-1.2.2-java lib/norikra/webui/http.rb
norikra-1.2.1-java lib/norikra/webui/http.rb
norikra-1.2.0-java lib/norikra/webui/http.rb
norikra-1.1.2-java lib/norikra/webui/http.rb
norikra-1.1.1-java lib/norikra/webui/http.rb
norikra-1.1.0-java lib/norikra/webui/http.rb
norikra-1.0.8-java lib/norikra/webui/http.rb
norikra-1.0.7-java lib/norikra/webui/http.rb
norikra-1.0.6-java lib/norikra/webui/http.rb
norikra-1.0.5-java lib/norikra/webui/http.rb
norikra-1.0.4-java lib/norikra/webui/http.rb
norikra-1.0.3-java lib/norikra/webui/http.rb
norikra-1.0.2-java lib/norikra/webui/http.rb
norikra-1.0.1-java lib/norikra/webui/http.rb
norikra-1.0.0-java lib/norikra/webui/http.rb