Sha256: 5af146017a2ec9cd29b5344e38604c2a46738e61da0240af8fb7ee019250f88d

Contents?: true

Size: 1.14 KB

Versions: 13

Compression:

Stored size: 1.14 KB

Contents

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

require_relative 'handler'

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 = Norikra::RPC::Handler.new(@engine)
      @app = Rack::Builder.new {
        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
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
norikra-0.1.4-java lib/norikra/rpc/http.rb
norikra-0.1.3-java lib/norikra/rpc/http.rb
norikra-0.1.2-java lib/norikra/rpc/http.rb
norikra-0.1.1-java lib/norikra/rpc/http.rb
norikra-0.1.0-java lib/norikra/rpc/http.rb
norikra-0.0.24-java lib/norikra/rpc/http.rb
norikra-0.0.23-java lib/norikra/rpc/http.rb
norikra-0.0.22-java lib/norikra/rpc/http.rb
norikra-0.0.21-java lib/norikra/rpc/http.rb
norikra-0.0.20-java lib/norikra/rpc/http.rb
norikra-0.0.19-java lib/norikra/rpc/http.rb
norikra-0.0.18-java lib/norikra/rpc/http.rb
norikra-0.0.17-java lib/norikra/rpc/http.rb