Class: RestFtpDaemon::WorkerPool
- Inherits:
-
Object
- Object
- RestFtpDaemon::WorkerPool
- Includes:
- BmcDaemonLib::LoggerHelper, NewRelic::Agent::Instrumentation::ControllerInstrumentation, Singleton
- Defined in:
- lib/rest-ftp-daemon/worker_pool.rb
Instance Attribute Summary collapse
-
#logger ⇒ Object
readonly
Class options.
-
#wid ⇒ Object
readonly
Returns the value of attribute wid.
Instance Method Summary collapse
-
#initialize ⇒ WorkerPool
constructor
A new instance of WorkerPool.
- #start_em_all ⇒ Object
- #worker_alive?(wid) ⇒ Boolean
- #worker_variables ⇒ Object
Constructor Details
#initialize ⇒ WorkerPool
Returns a new instance of WorkerPool.
15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 15 def initialize # Logger @logger = BmcDaemonLib::LoggerPool.instance.get :workers # Prepare status hash and vars @statuses = {} @workers = {} @mutex = Mutex.new # Identifiers generator @seqno = 0 end |
Instance Attribute Details
#logger ⇒ Object (readonly)
Class options
12 13 14 |
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 12 def logger @logger end |
#wid ⇒ Object (readonly)
Returns the value of attribute wid.
13 14 15 |
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 13 def wid @wid end |
Instance Method Details
#start_em_all ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 28 def start_em_all # Read configuration or initialize with empty hash pools = Conf.at[:pools] pools = {} unless pools.is_a? Hash # Minimum one worker on DEFAULT_POOL if !(pools.is_a? Hash) log_error "create_threads: one JobWorker is the minimum (#{pools.inspect}" end log_info "WorkerPool creating all workers with #{pools.to_hash.inspect}" # Start ConchitaWorker and ReporterWorker create_thread ConchitaWorker, :conchita create_thread ReporterWorker, :reporter # Start JobWorkers threads, ensure we have at least one worker in default pool pools[DEFAULT_POOL] ||= 1 pools.each do |pool, count| count.times do my_wid = next_wid() create_thread TransferWorker, my_wid, pool end end rescue StandardError => ex log_error "EXCEPTION: #{ex.}", ex.backtrace end |
#worker_alive?(wid) ⇒ Boolean
64 65 66 |
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 64 def worker_alive? wid @workers[wid] && @workers[wid].alive? end |
#worker_variables ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 56 def worker_variables vars = {} @workers.collect do |wid, worker| vars[wid] = thread_variables worker end vars end |