Class: ModernTimes::Base::Supervisor
- Inherits:
-
Object
- Object
- ModernTimes::Base::Supervisor
- Defined in:
- lib/modern_times/base/supervisor.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#manager ⇒ Object
readonly
Returns the value of attribute manager.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#worker_klass ⇒ Object
readonly
Returns the value of attribute worker_klass.
-
#worker_options ⇒ Object
readonly
Returns the value of attribute worker_options.
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
- #create_mbean(domain) ⇒ Object
-
#initialize(manager, worker_klass, supervisor_options, worker_options) ⇒ Supervisor
constructor
Create new supervisor to manage a number of similar workers supervisor_options are those options defined on the Worker’s Supervisor line worker_options are options passed in when creating a new instance.
- #join ⇒ Object
- #mbean_description ⇒ Object
- #mbean_name(domain) ⇒ Object
- #stop ⇒ Object
- #stopped? ⇒ Boolean
- #worker_count ⇒ Object
- #worker_count=(count) ⇒ Object
- #worker_statuses ⇒ Object
Constructor Details
#initialize(manager, worker_klass, supervisor_options, worker_options) ⇒ Supervisor
Create new supervisor to manage a number of similar workers supervisor_options are those options defined on the Worker’s Supervisor line worker_options are options passed in when creating a new instance
9 10 11 12 13 14 15 16 17 |
# File 'lib/modern_times/base/supervisor.rb', line 9 def initialize(manager, worker_klass, , ) @stopped = false @manager = manager @worker_klass = worker_klass @name = [:name] || worker_klass.default_name @worker_options = @workers = [] @worker_mutex = Mutex.new end |
Instance Attribute Details
#manager ⇒ Object (readonly)
Returns the value of attribute manager.
4 5 6 |
# File 'lib/modern_times/base/supervisor.rb', line 4 def manager @manager end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/modern_times/base/supervisor.rb', line 4 def name @name end |
#worker_klass ⇒ Object (readonly)
Returns the value of attribute worker_klass.
4 5 6 |
# File 'lib/modern_times/base/supervisor.rb', line 4 def worker_klass @worker_klass end |
#worker_options ⇒ Object (readonly)
Returns the value of attribute worker_options.
4 5 6 |
# File 'lib/modern_times/base/supervisor.rb', line 4 def @worker_options end |
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
4 5 6 |
# File 'lib/modern_times/base/supervisor.rb', line 4 def workers @workers end |
Instance Method Details
#create_mbean(domain) ⇒ Object
84 85 86 |
# File 'lib/modern_times/base/supervisor.rb', line 84 def create_mbean(domain) SupervisorMBean.new(mbean_name(domain), mbean_description, self, {}) end |
#join ⇒ Object
72 73 74 |
# File 'lib/modern_times/base/supervisor.rb', line 72 def join @workers.each { |worker| worker.join } end |
#mbean_description ⇒ Object
80 81 82 |
# File 'lib/modern_times/base/supervisor.rb', line 80 def mbean_description "Supervisor for #{@worker_klass.name} under #{@name}" end |
#mbean_name(domain) ⇒ Object
76 77 78 |
# File 'lib/modern_times/base/supervisor.rb', line 76 def mbean_name(domain) "#{domain}.Worker.#{@name}" end |
#stop ⇒ Object
61 62 63 64 65 66 |
# File 'lib/modern_times/base/supervisor.rb', line 61 def stop @worker_mutex.synchronize do @stopped = true @workers.each { |worker| worker.stop } end end |
#stopped? ⇒ Boolean
68 69 70 |
# File 'lib/modern_times/base/supervisor.rb', line 68 def stopped? @stopped end |
#worker_count ⇒ Object
19 20 21 |
# File 'lib/modern_times/base/supervisor.rb', line 19 def worker_count @workers.size end |
#worker_count=(count) ⇒ Object
23 24 25 26 27 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 55 |
# File 'lib/modern_times/base/supervisor.rb', line 23 def worker_count=(count) @worker_mutex.synchronize do ModernTimes.logger.info "#{@worker_klass.name}: Changing number of workers from #{@workers.size} to #{count}" raise "#{@worker_klass.name}: Can't change worker_count, this manager has been stopped" if stopped? curr_count = @workers.size if curr_count < count (curr_count...count).each do |index| worker = @worker_klass.new(@worker_options) worker.index = index if index == 0 # HornetQ hack: If I create the session in the jmx thread, it dies with no feedback #tmp_thread = Thread.new do worker.setup #end #tmp_thread.join end worker.thread = Thread.new do java.lang.Thread.current_thread.name = "ModernTimes worker: #{worker}" #ModernTimes.logger.debug "#{worker}: Started thread with priority #{Thread.current.priority}" worker.start end @workers << worker end elsif curr_count > count (count...curr_count).each { |index| @workers[index].stop } (count...curr_count).each { |index| @workers[index].thread.join } @workers = @workers[0, count] else return end manager.save_persist_state end end |
#worker_statuses ⇒ Object
57 58 59 |
# File 'lib/modern_times/base/supervisor.rb', line 57 def worker_statuses @workers.map { |w| w.status } end |