Class: RightSpeed::Processor::RoundRobinProcessor

Inherits:
Base
  • Object
show all
Defined in:
lib/right_speed/processor.rb

Instance Method Summary collapse

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

#runObject



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

#waitObject



93
94
95
96
# File 'lib/right_speed/processor.rb', line 93

def wait
  @workers.each{|w| w.wait}
  @closer.wait
end