class Elastictastic::Rotor

Constants

NodeUnavailable

Public Class Methods

new(hosts, options) click to toggle source
# File lib/elastictastic/rotor.rb, line 11
def initialize(hosts, options)
  node_options = {}
  [:backoff_threshold, :backoff_start, :backoff_max].each do |key|
    node_options[key] = options.delete(key)
  end
  adapter = Adapter[options.delete(:adapter)]
  @connections = hosts.map do |host|
    Node.new(adapter.new(host, options), node_options)
  end
  @head_index = 0
end

Public Instance Methods

request(method, path, body = nil) click to toggle source
# File lib/elastictastic/rotor.rb, line 23
def request(method, path, body = nil)
  try_rotate { |node| node.request(method, path, body) }
end

Private Instance Methods

peek() click to toggle source
# File lib/elastictastic/rotor.rb, line 29
def peek
  @connections[@head_index]
end
shift() click to toggle source
# File lib/elastictastic/rotor.rb, line 33
def shift
  peek.tap { @head_index = (@head_index + 1) % @connections.length }
end
try_rotate() { |shift| ... } click to toggle source
# File lib/elastictastic/rotor.rb, line 37
def try_rotate
  last = peek
  begin
    yield shift
  rescue ConnectionFailed, NodeUnavailable => e
    raise NoServerAvailable, e if peek == last
    retry
  end
end