Class: Backend

Inherits:
Object
  • Object
show all
Defined in:
lib/galerab/backend.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#confObject

Returns the value of attribute conf.



2
3
4
# File 'lib/galerab/backend.rb', line 2

def conf
  @conf
end

#not_readyObject

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_nextObject

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