Class: Elastictastic::Rotor

Inherits:
Object
  • Object
show all
Includes:
TransportMethods
Defined in:
lib/elastictastic/rotor.rb

Defined Under Namespace

Classes: Node

Constant Summary collapse

NodeUnavailable =
Class.new(StandardError)

Instance Method Summary collapse

Methods included from TransportMethods

#delete, #get, #head, #post, #put

Constructor Details

#initialize(hosts, options) ⇒ Rotor

Returns a new instance of Rotor.


11
12
13
14
15
16
17
18
19
20
21
# 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

Instance Method Details

#request(method, path, body = nil) ⇒ Object


23
24
25
# File 'lib/elastictastic/rotor.rb', line 23

def request(method, path, body = nil)
  try_rotate { |node| node.request(method, path, body) }
end