class Elasticsearch::Transport::Transport::Connections::Selector::RoundRobin

“Round-robin” selector strategy (default).

Public Class Methods

new(arguments = {}) click to toggle source

@option arguments [Connections::Collection] :connections Collection with connections.

# File lib/elasticsearch/transport/transport/connections/selector.rb, line 66
def initialize(arguments = {})
  super
  @mutex = Mutex.new
  @current = nil
end

Public Instance Methods

select(options={}) click to toggle source

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

@return [Connections::Connection]

# File lib/elasticsearch/transport/transport/connections/selector.rb, line 76
def select(options={})
  @mutex.synchronize do
    conns = connections
    if @current && (@current < conns.size-1)
      @current += 1
    else
      @current = 0
    end
    conns[@current]
  end
end