Class: Backend
- Inherits:
-
Object
- Object
- Backend
- Defined in:
- lib/galerab/backend.rb
Instance Attribute Summary collapse
-
#conf ⇒ Object
Returns the value of attribute conf.
-
#not_ready ⇒ Object
Returns the value of attribute not_ready.
Instance Method Summary collapse
-
#get_next ⇒ Object
round robin load-balancing.
-
#initialize(conf) ⇒ Backend
constructor
A new instance of Backend.
Constructor Details
#initialize(conf) ⇒ Backend
Returns a new instance of Backend.
4 5 6 7 8 9 |
# File 'lib/galerab/backend.rb', line 4 def initialize(conf) @next_host = 0 @list = conf['backends'] @conf = conf @not_ready = Array.new end |
Instance Attribute Details
#conf ⇒ Object
Returns the value of attribute conf.
2 3 4 |
# File 'lib/galerab/backend.rb', line 2 def conf @conf end |
#not_ready ⇒ Object
Returns the value of attribute not_ready.
2 3 4 |
# File 'lib/galerab/backend.rb', line 2 def not_ready @not_ready end |
Instance Method Details
#get_next ⇒ Object
round robin load-balancing
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/galerab/backend.rb', line 12 def get_next @next_host = @next_host + 1 @next_host = 0 if @next_host >= @list.size unless @not_ready.include?(@list[@next_host]) @list[@next_host] else begin get_next rescue SystemStackError nil end end end |