Class: Aerospike::Pool

Inherits:
Object
  • Object
show all
Defined in:
lib/aerospike/utils/pool.rb

Overview

:nodoc:

Direct Known Subclasses

ConnectionPool

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(max_size = 256, &block) ⇒ Pool

Returns a new instance of Pool.



23
24
25
26
27
28
29
30
# File 'lib/aerospike/utils/pool.rb', line 23

def initialize(max_size = 256, &block)
  @create_proc = block
  @cleanup_proc = nil
  @check_proc = nil

  @pool = Queue.new
  @max_size = max_size
end

Instance Attribute Details

#check_procObject

Returns the value of attribute check_proc.



21
22
23
# File 'lib/aerospike/utils/pool.rb', line 21

def check_proc
  @check_proc
end

#cleanup_procObject

Returns the value of attribute cleanup_proc.



21
22
23
# File 'lib/aerospike/utils/pool.rb', line 21

def cleanup_proc
  @cleanup_proc
end

#create_procObject

Returns the value of attribute create_proc.



21
22
23
# File 'lib/aerospike/utils/pool.rb', line 21

def create_proc
  @create_proc
end

#max_sizeObject

Returns the value of attribute max_size.



21
22
23
# File 'lib/aerospike/utils/pool.rb', line 21

def max_size
  @max_size
end

Instance Method Details

#empty?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/aerospike/utils/pool.rb', line 55

def empty?
  @pool.empty?
end

#inspectObject



64
65
66
# File 'lib/aerospike/utils/pool.rb', line 64

def inspect
  "#<Aerospike::Pool: size=#{size}>"
end

#lengthObject Also known as: size



59
60
61
# File 'lib/aerospike/utils/pool.rb', line 59

def length
  @pool.length
end

#offer(obj) ⇒ Object Also known as: <<



32
33
34
35
36
37
38
# File 'lib/aerospike/utils/pool.rb', line 32

def offer(obj)
  if @pool.length < @max_size
    @pool << obj
  else
    cleanup(obj)
  end
end

#poll(create_new = true) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/aerospike/utils/pool.rb', line 41

def poll(create_new=true)
  non_block = true
  begin
    obj = @pool.pop(non_block)
    if !check(obj)
      cleanup(obj)
      obj = nil
    end
  end until obj
  obj
rescue ThreadError
  create if create_new
end