Class: Protobuf::Rpc::EventedRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/protobuf/rpc/servers/evented_runner.rb

Class Method Summary collapse

Class Method Details

.run(server) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/protobuf/rpc/servers/evented_runner.rb', line 10

def self.run(server)
  # Ensure errors thrown within EM are caught and logged appropriately
  EventMachine.error_handler do |error|
    if error.message == 'no acceptor'
      raise 'Failed binding to %s:%d (%s)' % [server.host, server.port, error.message]
    else
      Protobuf::Logger.error error.message
      Protobuf::Logger.error error.backtrace.join("\n")
    end
  end

  # Startup and run the rpc server
  EM.schedule do
    EventMachine.start_server(server.host, server.port, Protobuf::Rpc::EventedServer) && \
      Protobuf::Logger.info('RPC Server listening at %s:%d in %s' % [server.host, server.port, server.env])
  end

  # Join or start the reactor
  EM.reactor_running? ? EM.reactor_thread.join : EM.run
end

.stopObject



5
6
7
8
# File 'lib/protobuf/rpc/servers/evented_runner.rb', line 5

def self.stop
  EventMachine.stop_event_loop if EventMachine.reactor_running?
  Protobuf::Logger.info 'Shutdown complete'
end