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 |
# 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' Officer::Log.set_log_level params[:log_level] end |
Instance Method Details
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/officer/server.rb', line 26 def run 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) {Officer::LockStore.instance.log_state} 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
53 54 55 |
# File 'lib/officer/server.rb', line 53 def running? @semaphore.synchronize {@running} end |