Class: Servicy::RoundRobinLoadBalancer
- Inherits:
-
LoadBalancer
- Object
- LoadBalancer
- Servicy::RoundRobinLoadBalancer
- Defined in:
- lib/load_balancer/round_robin.rb
Instance Attribute Summary
Attributes inherited from LoadBalancer
Instance Method Summary collapse
-
#initialize ⇒ RoundRobinLoadBalancer
constructor
A new instance of RoundRobinLoadBalancer.
- #next_for_service(service_name) ⇒ Object
Methods inherited from LoadBalancer
Constructor Details
#initialize ⇒ RoundRobinLoadBalancer
Returns a new instance of RoundRobinLoadBalancer.
3 4 5 6 |
# File 'lib/load_balancer/round_robin.rb', line 3 def initialize super @last_host_index = {} end |
Instance Method Details
#next_for_service(service_name) ⇒ Object
8 9 10 11 12 13 14 15 16 |
# File 'lib/load_balancer/round_robin.rb', line 8 def next_for_service(service_name) @last_host_index[service_name] ||= 0 service = hosts[service_name][@last_host_index[service_name]] @last_host_index[service_name] += 1 if @last_host_index[service_name] >= hosts[service_name].length @last_host_index[service_name] = 0 end service end |