Class: Hystrix::CommandExecutorPool

Inherits:
Object
  • Object
show all
Defined in:
lib/hystrix/executor_pool.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, size) ⇒ CommandExecutorPool

Returns a new instance of CommandExecutorPool.



34
35
36
37
38
39
40
41
42
43
# File 'lib/hystrix/executor_pool.rb', line 34

def initialize(name, size)
  self.name = name
  self.size = size
  self.executors = []
  self.lock = Mutex.new
  self.circuit_supervisor = Circuit.supervise
  size.times do
    self.executors << CommandExecutor.new
  end
end

Instance Attribute Details

#circuit_supervisorObject

Returns the value of attribute circuit_supervisor.



32
33
34
# File 'lib/hystrix/executor_pool.rb', line 32

def circuit_supervisor
  @circuit_supervisor
end

#executorsObject

Returns the value of attribute executors.



31
32
33
# File 'lib/hystrix/executor_pool.rb', line 31

def executors
  @executors
end

#lockObject

Returns the value of attribute lock.



31
32
33
# File 'lib/hystrix/executor_pool.rb', line 31

def lock
  @lock
end

#nameObject

Returns the value of attribute name.



30
31
32
# File 'lib/hystrix/executor_pool.rb', line 30

def name
  @name
end

#sizeObject

Returns the value of attribute size.



30
31
32
# File 'lib/hystrix/executor_pool.rb', line 30

def size
  @size
end

Instance Method Details

#shutdownObject



58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hystrix/executor_pool.rb', line 58

def shutdown
  lock.synchronize do
    until executors.size == 0 do
      for i in (0...executors.size)
        unless executors[i].locked?
          executors[i] = nil
        end
      end
      executors.compact!
      sleep 0.1
    end
  end
end

#takeObject



45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/hystrix/executor_pool.rb', line 45

def take
  lock.synchronize do
    for executor in self.executors
      unless executor.locked?
        executor.lock
        return executor
      end
    end
  end

  raise ExecutorPoolFullError.new("Unable to get executor from #{self.name} pool.")
end