Class: MaZMQ::Proxy::Balancer

Inherits:
Object
  • Object
show all
Defined in:
lib/ma-zmq/proxy/balancer.rb

Constant Summary collapse

@@strategies =
[
  :round_robin,
  :connections,
  :load, # Cucub podria usar algo como 'less_jobs'
  :priority,
  :directed
]

Instance Method Summary collapse

Constructor Details

#initializeBalancer

Returns a new instance of Balancer.



12
13
14
15
16
# File 'lib/ma-zmq/proxy/balancer.rb', line 12

def initialize
  self.strategy = :round_robin # default strategy is round_robin
  @index = []
  # @data = [] # connections, load
end

Instance Method Details

#add(index) ⇒ Object



23
24
25
# File 'lib/ma-zmq/proxy/balancer.rb', line 23

def add(index)
  @index << index
end

#currentObject



31
32
33
# File 'lib/ma-zmq/proxy/balancer.rb', line 31

def current
  @index[0]
end

#nextObject



35
36
37
38
39
40
# File 'lib/ma-zmq/proxy/balancer.rb', line 35

def next
  case @strategy
    when :round_robin
      @index.push(@index.shift)
  end
end

#remove(index) ⇒ Object



27
28
29
# File 'lib/ma-zmq/proxy/balancer.rb', line 27

def remove(index)
  @index.delete(index)
end

#strategy=(strategy) ⇒ Object



18
19
20
21
# File 'lib/ma-zmq/proxy/balancer.rb', line 18

def strategy=(strategy)
  return false if not @@strategies.include? strategy
  @strategy = strategy
end