Class: RightSpeed::Processor::RoundRobinProcessor
- Defined in:
- lib/right_speed/processor.rb
Instance Method Summary collapse
- #configure(listener:) ⇒ Object
-
#initialize(workers, handler) ⇒ RoundRobinProcessor
constructor
A new instance of RoundRobinProcessor.
- #process(conn) ⇒ Object
- #run ⇒ Object
- #wait ⇒ Object
Constructor Details
#initialize(workers, handler) ⇒ RoundRobinProcessor
Returns a new instance of RoundRobinProcessor.
70 71 72 73 74 75 76 |
# File 'lib/right_speed/processor.rb', line 70 def initialize(workers, handler) @worker_num = workers @handler = handler @workers = workers.times.map{|i| Worker::RoundRobin.new(id: i, handler: @handler)} @closer = ConnectionCloser.new @counter = 0 end |
Instance Method Details
#configure(listener:) ⇒ Object
78 79 80 |
# File 'lib/right_speed/processor.rb', line 78 def configure(listener:) @listener = listener end |
#process(conn) ⇒ Object
88 89 90 91 |
# File 'lib/right_speed/processor.rb', line 88 def process(conn) current, @counter = @counter, @counter + 1 @workers[current % @worker_num].process(conn) end |
#run ⇒ Object
82 83 84 85 86 |
# File 'lib/right_speed/processor.rb', line 82 def run @workers.each{|w| w.run} @closer.run(@workers.map{|w| w.ractor}) @listener.run(self) end |
#wait ⇒ Object
93 94 95 96 |
# File 'lib/right_speed/processor.rb', line 93 def wait @workers.each{|w| w.wait} @closer.wait end |