lib/drbman/drb_pool.rb in royw-drbman-0.0.3 vs lib/drbman/drb_pool.rb in royw-drbman-0.0.4
- old
+ new
@@ -17,15 +17,20 @@
@logger = logger
@objects = []
threads = []
mutex = Mutex.new
+ @logger.debug { "drb_pool hosts => #{hosts.inspect}"}
hosts.each do |host_name, host_machine|
threads << Thread.new(host_machine) do |host|
- obj = get_drb_object(host.machine, host.port)
- mutex.synchronize do
- @objects << obj
+ if host.alive?
+ obj = get_drb_object(host.machine, host.port)
+ unless obj.nil?
+ mutex.synchronize do
+ @objects << obj
+ end
+ end
end
end
end
threads.each {|thrd| thrd.join}
@@ -38,9 +43,10 @@
# Use an object from the pool
# @yield [DRbObject]
# @example Usage
# pool.get_object {|obj| obj.do_something}
def get_object(&block)
+ raise EmptyDrbPoolError.new("No drb servers available") if @objects.empty?
mutex = Mutex.new
while((object = next_object(mutex)).nil?)
sleep 0.1
end
raise ArgumentError.new('a block is required') if block.nil?