Sha256: e0b423711de3ce7319e3597cf89c4a0568f04e6d2b9e16112e5504b51f67d8f1

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'mizuno/server'
require 'rack/builder'
require 'msgpack-rpc-over-http-jruby'

require_relative 'handler'
require_relative 'gatekeeper'

require 'norikra/logger'
include Norikra::Log

module Norikra::RPC
  class HTTP
    DEFAULT_LISTEN_HOST = '0.0.0.0'
    DEFAULT_LISTEN_PORT = 26571
    # 26571 = 3026 + 3014 + 2968 + 2950 + 2891 + 2896 + 2975 + 2979 + 2872

    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
      @handler = handler = Norikra::RPC::Handler.new(@engine)
      @app = Rack::Builder.new {
        use Norikra::RPC::Gatekeeper
        run MessagePack::RPCOverHTTP::Server.app(handler)
      }
    end

    def start
      info "RPC 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

    def shut_off(mode)
      @handler.shut_off(mode)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
norikra-1.3.0.beta.1-java lib/norikra/rpc/http.rb