Module: ServiceManager
- Included in:
- Daemon
- Defined in:
- lib/service_manager.rb
Overview
A service must implement at least:
- start_service(uri, *args, &block)
- stop_service
- server
- thread
- uri
Instance Method Summary collapse
- #count_services ⇒ Object
- #each_services(&block) ⇒ Object
- #join_services ⇒ Object
- #list_services ⇒ Object
- #service_server(uri) ⇒ Object
- #start_service(service, uri = nil, *args, &block) ⇒ Object
- #stop_service(uri) ⇒ Object
- #stop_services ⇒ Object
Instance Method Details
#count_services ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/service_manager.rb', line 40 def count_services if defined? @services @services.size else 0 end end |
#each_services(&block) ⇒ Object
62 63 64 65 66 |
# File 'lib/service_manager.rb', line 62 def each_services(&block) if defined? @services @services.each { |uri, service| block[uri, service] } end end |
#join_services ⇒ Object
56 57 58 59 60 |
# File 'lib/service_manager.rb', line 56 def join_services if defined? @services @services.each { |uri, service| service.thread.join } end end |
#list_services ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/service_manager.rb', line 48 def list_services if defined? @services @services.values else [] end end |
#service_server(uri) ⇒ Object
68 69 70 |
# File 'lib/service_manager.rb', line 68 def service_server(uri) @services[uri].server if defined? @services end |
#start_service(service, uri = nil, *args, &block) ⇒ Object
18 19 20 21 22 |
# File 'lib/service_manager.rb', line 18 def start_service(service, uri=nil, *args, &block) @services = {} unless defined? @services service.start_service(uri, *args, &block) @services[service.uri] = service end |
#stop_service(uri) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/service_manager.rb', line 24 def stop_service(uri) if defined? @services if service = @services.delete(uri) service.stop_service end end end |
#stop_services ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/service_manager.rb', line 32 def stop_services if defined? @services @services.keys.each do |uri| stop_service(uri) end end end |