Class: Cylons::ServiceManager

Inherits:
Object
  • Object
show all
Defined in:
lib/cylons/service_manager.rb

Class Method Summary collapse

Class Method Details

.build_service(model_klass) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/cylons/service_manager.rb', line 20

def self.build_service(model_klass)
  proxy_service_class_name = "#{model_klass.name}Service"
  ::Object.const_set(proxy_service_class_name, ::Class.new(::Cylons::Service))
  service_klass = proxy_service_class_name.constantize
  service_klass.model = model_klass

  ::Cylons.logger.info "REGISTERING_SERVICE_FOR #{model_klass}"

  service_klass
end

.remotes?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cylons/service_manager.rb', line 43

def self.remotes?
  ::Cylons::RemoteRegistry.remotes.any?
end

.service_defined?(model_klass) ⇒ Boolean

Returns:

  • (Boolean)


31
32
33
34
35
# File 'lib/cylons/service_manager.rb', line 31

def self.service_defined?(model_klass)
  proxy_service_class_name = "#{model_klass.name}Service"

  const_defined?(:"#{proxy_service_class_name}")
end

.startObject



6
7
8
9
# File 'lib/cylons/service_manager.rb', line 6

def self.start
  ::Cylons.logger.info "STARTING CYLON SERVICES"
  start_services
end

.start_service(model_klass) ⇒ Object

todo: split supervision and building



12
13
14
15
16
17
18
# File 'lib/cylons/service_manager.rb', line 12

def self.start_service(model_klass)
  unless service_defined?(model_klass)
    service_klass = build_service(model_klass)

    service_klass.supervise_as service_klass.name.to_sym
  end
end

.start_servicesObject



37
38
39
40
41
# File 'lib/cylons/service_manager.rb', line 37

def self.start_services
  ::Cylons::RemoteRegistry.remotes.each do |remote|
    start_service(remote)
  end if remotes?
end

.stopObject



47
48
49
50
51
52
# File 'lib/cylons/service_manager.rb', line 47

def self.stop
  ::Cylons::RemoteRegistry.remotes.each do |remote|
    ::Cylons.logger.info{ "Shutting Down #{remote.name}"}
    remote.stop
  end
end