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

Constructor Details

#initialize(arguments = {}) ⇒ RoundRobin

Returns a new instance of RoundRobin.

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):



53
54
55
56
57
# File 'lib/elasticsearch/transport/transport/connections/selector.rb', line 53

def initialize(arguments = {})
  super
  @mutex = Mutex.new
  @current = nil
end

Instance Method Details

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

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



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/elasticsearch/transport/transport/connections/selector.rb', line 63

def select(options={})
  @mutex.synchronize do
    conns = connections
    if @current && (@current < conns.size-1)
      @current += 1
    else
      @current = 0
    end
    conns[@current]
  end
end