Class: Fluent::PluginHelper::ServiceDiscovery::RoundRobinBalancer

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin_helper/service_discovery/round_robin_balancer.rb

Instance Method Summary collapse

Constructor Details

#initializeRoundRobinBalancer

Returns a new instance of RoundRobinBalancer.



21
22
23
24
# File 'lib/fluent/plugin_helper/service_discovery/round_robin_balancer.rb', line 21

def initialize
  @services = []
  @mutex = Mutex.new
end

Instance Method Details

#rebalance(services) ⇒ Object



26
27
28
29
30
# File 'lib/fluent/plugin_helper/service_discovery/round_robin_balancer.rb', line 26

def rebalance(services)
  @mutex.synchronize do
    @services = services
  end
end

#select_service {|s| ... } ⇒ Object

Yields:

  • (s)


32
33
34
35
36
37
38
39
# File 'lib/fluent/plugin_helper/service_discovery/round_robin_balancer.rb', line 32

def select_service
  s = @mutex.synchronize do
    s = @services.shift
    @services.push(s)
    s
  end
  yield(s)
end