Class: Norikra::RPC::HTTP

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

Constant Summary collapse

DEFAULT_LISTEN_HOST =
'0.0.0.0'
DEFAULT_LISTEN_PORT =
26571
DEFAULT_THREADS =

26571 = 3026 + 3014 + 2968 + 2950 + 2891 + 2896 + 2975 + 2979 + 2872

2

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ HTTP

Returns a new instance of HTTP.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/norikra/rpc/http.rb', line 22

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

Instance Attribute Details

#engineObject

Returns the value of attribute engine.



20
21
22
# File 'lib/norikra/rpc/http.rb', line 20

def engine
  @engine
end

#hostObject

Returns the value of attribute host.



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

def host
  @host
end

#mizunoObject

Returns the value of attribute mizuno.



20
21
22
# File 'lib/norikra/rpc/http.rb', line 20

def mizuno
  @mizuno
end

#portObject

Returns the value of attribute port.



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

def port
  @port
end

#threadObject

Returns the value of attribute thread.



20
21
22
# File 'lib/norikra/rpc/http.rb', line 20

def thread
  @thread
end

#threadsObject

Returns the value of attribute threads.



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

def threads
  @threads
end

Instance Method Details

#shut_off(mode) ⇒ Object



53
54
55
# File 'lib/norikra/rpc/http.rb', line 53

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

#startObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/norikra/rpc/http.rb', line 34

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



47
48
49
50
51
# File 'lib/norikra/rpc/http.rb', line 47

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