Class: Officer::Server
- Inherits:
-
Object
- Object
- Officer::Server
- Defined in:
- lib/officer/server.rb
Defined Under Namespace
Classes: ShutdownConnection
Instance Method Summary collapse
-
#initialize(params = {}) ⇒ Server
constructor
A new instance of Server.
- #run ⇒ Object
- #running? ⇒ Boolean
Constructor Details
#initialize(params = {}) ⇒ Server
Returns a new instance of Server.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/officer/server.rb', line 10 def initialize params={} @semaphore = Mutex.new set_running(false) @params = params params[:socket_type] ||= 'TCP' params[:port] ||= 11500 params[:host] ||= '0.0.0.0' params[:socket_file] ||= '/tmp/officer.sock' params[:stats] ||= false params[:log_level] ||= 'error' params[:close_idle] = params.include?(:close_idle) ? params[:close_idle] : true params[:max_idle] ||= 60 # Seconds. Officer::Log.set_log_level params[:log_level] end |
Instance Method Details
#run ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/officer/server.rb', line 28 def run Officer::Log.debug 'Starting Officer with params:' @params.each do |param, value| Officer::Log.debug " #{param} => #{value}" end EM.error_handler {|e| Officer::Log.error e} EM.kqueue = true if EM.kqueue? EM.epoll = true if EM.epoll? EM::run do if @params[:stats] EM::PeriodicTimer.new(5) do Officer::LockStore.instance.log_state end end if @params[:close_idle] EM::PeriodicTimer.new(5) do Officer::LockStore.instance.close_idle_connections @params[:max_idle] end end if @enable_shutdown_port EM::start_server '127.0.0.1', 11501, ShutdownConnection end if @params[:socket_type] == 'TCP' EM::start_server @params[:host], @params[:port], Connection::Connection else EM::start_unix_domain_server @params[:socket_file], Connection::Connection end set_running(true) end set_running(false) end |
#running? ⇒ Boolean
69 70 71 |
# File 'lib/officer/server.rb', line 69 def running? @semaphore.synchronize {@running} end |