lib/modern_times/base/supervisor.rb in modern_times-0.1.1 vs lib/modern_times/base/supervisor.rb in modern_times-0.1.2

- old
+ new

@@ -1,17 +1,22 @@ module ModernTimes module Base class Supervisor - attr_reader :manager, :worker_klass + attr_reader :manager, :worker_klass, :name, :worker_options - def initialize(manager, worker_klass, options) - @stopped = false - @manager = manager - @worker_klass = worker_klass - @workers = [] - @worker_mutex = Mutex.new - @failure_mutex = Mutex.new + # 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 + def initialize(manager, worker_klass, supervisor_options, worker_options) + @stopped = false + @manager = manager + @worker_klass = worker_klass + @name = worker_options.delete(:name) || worker_klass.default_name + @worker_options = worker_options + @workers = [] + @worker_mutex = Mutex.new + @failure_mutex = Mutex.new end def worker_count @workers.size end @@ -21,10 +26,10 @@ 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 = @worker_klass.new(@worker_options) worker.supervisor = self 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 \ No newline at end of file