Class: RestFtpDaemon::WorkerPool

Inherits:
Object
  • Object
show all
Includes:
NewRelic::Agent::Instrumentation::ControllerInstrumentation, LoggerHelper
Defined in:
lib/rest-ftp-daemon/worker_pool.rb

Overview

Handles a pool of Worker objects

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeWorkerPool

Returns a new instance of WorkerPool.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 14

def initialize
  # Logger
  @logger = RestFtpDaemon::LoggerPool.instance.get :workers

  # Prepare status hash and vars
  @statuses = {}
  @workers = {}
  @conchita = nil
  @mutex = Mutex.new

  # Identifiers generator
  @last_id = 0

  # Create worker threads
  create_threads
end

Instance Attribute Details

#loggerObject (readonly)

Returns the value of attribute logger.



6
7
8
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 6

def logger
  @logger
end

#widObject (readonly)

Returns the value of attribute wid.



8
9
10
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 8

def wid
  @wid
end

Instance Method Details

#worker_alive?(wid) ⇒ Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 41

def worker_alive? wid
  @workers[wid] && @workers[wid].alive?
end

#worker_variablesObject



31
32
33
34
35
36
37
38
39
# File 'lib/rest-ftp-daemon/worker_pool.rb', line 31

def worker_variables
  @workers.collect do |_wid, worker|
    vars = {}
    worker.thread_variables.each do |var|
      vars[var] = worker.thread_variable_get var
    end
    vars
  end
end