Class: Miu::RPC::Server

Inherits:
Object
  • Object
show all
Includes:
Celluloid::ZMQ, Helpers
Defined in:
lib/miu/rpc/server.rb

Defined Under Namespace

Classes: Evaluator

Instance Method Summary collapse

Methods included from Helpers

#read_parts

Constructor Details

#initialize(address, handler) ⇒ Server

Returns a new instance of Server.



17
18
19
20
21
22
23
# File 'lib/miu/rpc/server.rb', line 17

def initialize(address, handler)
  @socket = Celluloid::ZMQ::RouterSocket.new
  @socket.bind address
  @evaluator = Evaluator.new handler

  async.run
end

Instance Method Details

#closeObject



25
26
27
28
# File 'lib/miu/rpc/server.rb', line 25

def close
  @socket.close
  terminate
end

#handle_message(parts) ⇒ Object



37
38
39
40
41
# File 'lib/miu/rpc/server.rb', line 37

def handle_message(parts)
  id, request = parts
  response = @evaluator.process_request request
  @socket.write id, response
end

#runObject



30
31
32
33
34
35
# File 'lib/miu/rpc/server.rb', line 30

def run
  loop do
    parts = read_parts @socket
    async.handle_message parts
  end
end