Class: OpenSearch::Transport::Transport::Connections::Selector::RoundRobin
- Inherits:
-
Object
- Object
- OpenSearch::Transport::Transport::Connections::Selector::RoundRobin
- Includes:
- Base
- Defined in:
- lib/opensearch/transport/transport/connections/selector.rb
Overview
“Round-robin” selector strategy (default).
Instance Attribute Summary
Attributes included from Base
Instance Method Summary collapse
-
#initialize(arguments = {}) ⇒ RoundRobin
constructor
A new instance of RoundRobin.
-
#select(_options = {}) ⇒ Connections::Connection
Returns the next connection from the collection, rotating them in round-robin fashion.
Constructor Details
#initialize(arguments = {}) ⇒ RoundRobin
Returns a new instance of RoundRobin.
74 75 76 77 78 |
# File 'lib/opensearch/transport/transport/connections/selector.rb', line 74 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.
84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/opensearch/transport/transport/connections/selector.rb', line 84 def select( = {}) @mutex.synchronize do conns = connections if @current && (@current < conns.size - 1) @current += 1 else @current = 0 end conns[@current] end end |