Class: Elasticsearch::Transport::Transport::Connections::Selector::RoundRobin

Inherits:
Object
  • Object
show all
Includes:
Base
Defined in:
lib/elasticsearch/transport/transport/connections/selector.rb

Overview

“Round-robin” selector strategy (default).

Instance Attribute Summary

Attributes included from Base

#connections

Instance Method Summary collapse

Methods included from Base

#initialize

Instance Method Details

#select(options = {}) ⇒ Connections::Connection

Returns the next connection from the collection, rotating them in round-robin fashion.



68
69
70
71
72
73
# File 'lib/elasticsearch/transport/transport/connections/selector.rb', line 68

def select(options={})
  # On Ruby 1.9, Array#rotate could be used instead
  @current = !defined?(@current) || @current.nil? ? 0 : @current+1
  @current = 0 if @current >= connections.size
  connections[@current]
end