Class: MaZMQ::Proxy::Balancer
- Inherits:
-
Object
- Object
- MaZMQ::Proxy::Balancer
- 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
- #add(index) ⇒ Object
- #current ⇒ Object
-
#initialize ⇒ Balancer
constructor
A new instance of Balancer.
- #next ⇒ Object
- #remove(index) ⇒ Object
- #strategy=(strategy) ⇒ Object
Constructor Details
#initialize ⇒ Balancer
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 |
#current ⇒ Object
31 32 33 |
# File 'lib/ma-zmq/proxy/balancer.rb', line 31 def current @index[0] end |
#next ⇒ Object
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 |