Class: Smartware::Service
- Inherits:
-
Object
- Object
- Smartware::Service
- Defined in:
- lib/smartware/service.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
-
#initialize(config_file) ⇒ Service
constructor
A new instance of Service.
- #join ⇒ Object
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Service
Returns a new instance of Service.
5 6 7 8 |
# File 'lib/smartware/service.rb', line 5 def initialize(config_file) @config = YAML.load File.read(config_file) @interfaces = [] end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
3 4 5 |
# File 'lib/smartware/service.rb', line 3 def config @config end |
Instance Method Details
#join ⇒ Object
41 42 43 44 45 |
# File 'lib/smartware/service.rb', line 41 def join @interfaces.each do |server| server.thread.join end end |
#start ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/smartware/service.rb', line 10 def start EventMachine.epoll EventMachine.run do @interfaces = @config["interfaces"].map do |config| interface = Smartware::Interface.const_get(config['name']).new config DRb::DRbServer.new config["uri"], interface end unless @config["connection_timeout"].nil? Thread.new do begin monitor = ConnectionMonitor.new @config["connection_timeout"].to_i monitor.run rescue => e Smartware::Logging.logger.error "Exception in connection monitor thread: #{e}" e.backtrace.each { |line| Smartware::Logging.logger.error line } end end end end end |
#stop ⇒ Object
35 36 37 38 39 |
# File 'lib/smartware/service.rb', line 35 def stop @interfaces.each &:stop_service EventMachine.stop_event_loop end |