class Fix::Engine::Server

Main FIX engine server class

Constants

REPORT_INTERVAL

Periodicity in seconds of logged status reports

Attributes

ip[RW]
port[RW]

Public Class Methods

new(ip, port, handler, &block) click to toggle source
# File lib/fix/engine/server.rb, line 24
def initialize(ip, port, handler, &block)
  @ip       = ip
  @port     = port
  @handler  = handler
  @block    = block
end

Public Instance Methods

report_status() click to toggle source

Logs a short summary of the current server status

# File lib/fix/engine/server.rb, line 54
def report_status
  log("#{Client.count} client(s) currently connected")
end
run!() click to toggle source

Starts running the server engine

# File lib/fix/engine/server.rb, line 34
def run!
  trap('INT') { EM.stop }
  log("Starting FIX engine v#{FE::VERSION}, listening on <#{ip}:#{port}>, exit with <Ctrl-C>")
  EM.run { start_server }
end
start_server() click to toggle source

Starts a listener inside a running reactor

# File lib/fix/engine/server.rb, line 43
def start_server
  raise "EventMachine must be running to start a server" unless EM.reactor_running?

  EM.start_server(ip, port, @handler) { |conn| @block && @block.call(conn) }

  REPORT_INTERVAL && EM.add_periodic_timer(REPORT_INTERVAL) { report_status }
end