Class: Copland::Implementation::Startup

Inherits:
Object
  • Object
show all
Defined in:
lib/copland/impl/startup.rb

Overview

This class is accessed via the singleton system service copland.Startup. It listens to the registry, and when it receives notification that the registry has been initialized, it will start all (enabled) services listed in the copland.Startup configuration point.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#clients=(value) ⇒ Object (writeonly)

Setter for the clients collection



86
87
88
# File 'lib/copland/impl/startup.rb', line 86

def clients=(value)
  @clients = value
end

#registry=(value) ⇒ Object (writeonly)

Setter for the instantiating registry



89
90
91
# File 'lib/copland/impl/startup.rb', line 89

def registry=(value)
  @registry = value
end

Instance Method Details

#startObject

Invoked by Copland when the registry has been initialized. This allows the service to then instantiate each of its registered services in turn, in the order they were requested.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/copland/impl/startup.rb', line 94

def start
  list = []
  @clients.each do |client|
    enabled = client.fetch( 'enabled', true )
    if enabled
      service_name = client['service']
      before = [ *( client['before'] || [] ) ] 
      after = [ *( client['after'] || [] ) ]

      list << StartupClient.new(
        @registry.service_point( service_name ),
        before, after )
    end
  end

  list = Orderer.order( list )
  list.each { |client| client.point.instance }
end