class Cottus::RoundRobinStrategy

Public Class Methods

new(connections, options={}) click to toggle source
Calls superclass method Cottus::Strategy::new
# File lib/cottus/strategies.rb, line 24
def initialize(connections, options={})
  super

  @index = 0
  @mutex = Mutex.new
end

Public Instance Methods

execute(meth, path, options={}) click to toggle source
# File lib/cottus/strategies.rb, line 31
def execute(meth, path, options={})
  tries = 0

  begin
    next_connection.send(meth, path, options)
  rescue *VALID_EXCEPTIONS => e
    if tries >= @connections.count
      raise e
    else
      tries += 1
      retry
    end
  end
end

Private Instance Methods

next_connection() click to toggle source
# File lib/cottus/strategies.rb, line 48
def next_connection
  @mutex.synchronize do
    connection = @connections[@index]
    @index = (@index + 1) % @connections.count
    connection
  end
end