Class: Xconsul::LoadBalance::RoundRobin
- Inherits:
-
Object
- Object
- Xconsul::LoadBalance::RoundRobin
- Defined in:
- lib/xconsul/load_balance/round_robin.rb
Instance Attribute Summary collapse
-
#counter ⇒ Object
attr_accessor :hosts # [‘192.168.0.1:8909’].
Instance Method Summary collapse
-
#initialize ⇒ RoundRobin
constructor
A new instance of RoundRobin.
-
#select(hosts) ⇒ Object
hosts [‘192.168.0.1:8909’, ‘192.168.0.2:8901’].
Constructor Details
#initialize ⇒ RoundRobin
Returns a new instance of RoundRobin.
10 11 12 |
# File 'lib/xconsul/load_balance/round_robin.rb', line 10 def initialize @counter = 0 end |
Instance Attribute Details
#counter ⇒ Object
attr_accessor :hosts # [‘192.168.0.1:8909’]
8 9 10 |
# File 'lib/xconsul/load_balance/round_robin.rb', line 8 def counter @counter end |
Instance Method Details
#select(hosts) ⇒ Object
hosts [‘192.168.0.1:8909’, ‘192.168.0.2:8901’]
15 16 17 18 19 |
# File 'lib/xconsul/load_balance/round_robin.rb', line 15 def select(hosts) idx = @counter % hosts.size @counter += 1 hosts[idx] end |