Class: Fix::Engine::Server
- Inherits:
-
Object
- Object
- Fix::Engine::Server
- Includes:
- Logger
- Defined in:
- lib/fix/engine/server.rb
Overview
Main FIX engine server class
Constant Summary collapse
- REPORT_INTERVAL =
Periodicity in seconds of logged status reports
10
Instance Attribute Summary collapse
-
#ip ⇒ Object
Returns the value of attribute ip.
-
#port ⇒ Object
Returns the value of attribute port.
Instance Method Summary collapse
-
#initialize(ip, port, handler, &block) ⇒ Server
constructor
A new instance of Server.
-
#report_status ⇒ Object
Logs a short summary of the current server status.
-
#run! ⇒ Object
Starts running the server engine.
-
#start_server ⇒ Object
Starts a listener inside a running reactor.
Methods included from Logger
Constructor Details
#initialize(ip, port, handler, &block) ⇒ Server
Returns a new instance of Server.
24 25 26 27 28 29 |
# File 'lib/fix/engine/server.rb', line 24 def initialize(ip, port, handler, &block) @ip = ip @port = port @handler = handler @block = block end |
Instance Attribute Details
#ip ⇒ Object
Returns the value of attribute ip.
22 23 24 |
# File 'lib/fix/engine/server.rb', line 22 def ip @ip end |
#port ⇒ Object
Returns the value of attribute port.
22 23 24 |
# File 'lib/fix/engine/server.rb', line 22 def port @port end |
Instance Method Details
#report_status ⇒ Object
Logs a short summary of the current server status
54 55 56 |
# File 'lib/fix/engine/server.rb', line 54 def report_status log("#{Client.count} client(s) currently connected") end |
#run! ⇒ Object
Starts running the server engine
34 35 36 37 38 |
# 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 ⇒ Object
Starts a listener inside a running reactor
43 44 45 46 47 48 49 |
# 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 |