Class: HawatelTlb::Mode::RoundRobin
- Inherits:
-
Object
- Object
- HawatelTlb::Mode::RoundRobin
- Defined in:
- lib/hawatel_tlb/mode/roundrobin.rb
Overview
Overview
Details
Instance Attribute Summary collapse
-
#name ⇒ Type
Description.
Instance Method Summary collapse
-
#initialize(group) ⇒ RoundRobin
constructor
A new instance of RoundRobin.
-
#node ⇒ Hash
Return ip address based on Round Robin algorithm.
-
#refresh(group) ⇒ Object
Refresh group table after delete or add host.
Constructor Details
#initialize(group) ⇒ RoundRobin
Returns a new instance of RoundRobin.
13 14 15 16 |
# File 'lib/hawatel_tlb/mode/roundrobin.rb', line 13 def initialize(group) @group = group @round = Array.new end |
Instance Attribute Details
#name ⇒ Type
Returns description.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hawatel_tlb/mode/roundrobin.rb', line 11 class RoundRobin def initialize(group) @group = group @round = Array.new end # Refresh group table after delete or add host # # @param group [Array<Hash>] def refresh(group) @group = group end # Return ip address based on Round Robin algorithm # # @return [Hash] hostname/ip address and port number def node counter = 0 first_item = '' @group.each do |node| if !node.status.empty? if node.status[:state] == 'online' && node.state == 'enable' first_item = {:host => node.host, :port => node.port} if counter == 0 if !@round.include?(node.id) @round.push(node.id) return {:host => node.host, :port => node.port} end counter += 1 end end end @round = Array.new return first_item if !first_item.empty? false end end |
Instance Method Details
#node ⇒ Hash
Return ip address based on Round Robin algorithm
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/hawatel_tlb/mode/roundrobin.rb', line 28 def node counter = 0 first_item = '' @group.each do |node| if !node.status.empty? if node.status[:state] == 'online' && node.state == 'enable' first_item = {:host => node.host, :port => node.port} if counter == 0 if !@round.include?(node.id) @round.push(node.id) return {:host => node.host, :port => node.port} end counter += 1 end end end @round = Array.new return first_item if !first_item.empty? false end |
#refresh(group) ⇒ Object
Refresh group table after delete or add host
21 22 23 |
# File 'lib/hawatel_tlb/mode/roundrobin.rb', line 21 def refresh(group) @group = group end |