Class: Cloudmaster::PoolRunner

Inherits:
Object
  • Object
show all
Defined in:
app/pool_runner.rb

Overview

oolRunner

Manages separate PoolManagers, each in a separate thread.

Knows how to start (run) and stop (shutdown) the pools.

Creates a thread for each pool in config, and runs a PoolManager in it. This needs to be passed a configuration, normally a InifileConfig object The configuration object contains all the information needed to control the pools, including the number of pools and each one’s characteristics.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config) ⇒ PoolRunner

Create empty runner. Until the run method is called, the

individual pool managers are not created.


20
21
22
23
24
25
26
# File 'app/pool_runner.rb', line 20

def initialize(config)
  @config = config
  @pool_managers = []
  Signal.trap("INT") do
    self.shutdown
  end
end

Instance Attribute Details

#pool_managersObject (readonly)

for testing only



17
18
19
# File 'app/pool_runner.rb', line 17

def pool_managers
  @pool_managers
end

Instance Method Details

#run(limit = nil) ⇒ Object

Create each of the pool managers described in the configuration. We can limit the amount of time it runs, for testing purposes only In testing we can call run again after it returns, so we make sure that we only create pool managers the first time through.



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'app/pool_runner.rb', line 32

def run(limit = nil)
 if @pool_managers == []
    @config.pools.each do |pool_config|
      # Wrap pool config parameters up with defaults.
      config = PoolConfiguration.new(@config.aws, @config.default, pool_config)
      @pool_managers << PoolManager.new(config)
    end
  end
  threads = []
  @pool_managers.each do |pool_manager|
    threads << Thread.new(pool_manager) do |mgr|
      mgr.run(limit)
    end
  end
  threads.each { |thread| thread.join }
end

#shutdownObject

Shut down each of the pool managers.



50
51
52
# File 'app/pool_runner.rb', line 50

def shutdown
  @pool_managers.each { |mgr| mgr.shutdown }
end