Class: Aerospike::Pool
- Inherits:
-
Object
- Object
- Aerospike::Pool
- Defined in:
- lib/aerospike/utils/pool.rb
Overview
:nodoc:
Direct Known Subclasses
Instance Attribute Summary collapse
-
#check_proc ⇒ Object
Returns the value of attribute check_proc.
-
#cleanup_proc ⇒ Object
Returns the value of attribute cleanup_proc.
-
#create_proc ⇒ Object
Returns the value of attribute create_proc.
-
#max_size ⇒ Object
Returns the value of attribute max_size.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(max_size = 256, &block) ⇒ Pool
constructor
A new instance of Pool.
- #inspect ⇒ Object
- #length ⇒ Object (also: #size)
- #offer(obj) ⇒ Object (also: #<<)
- #poll(create_new = true) ⇒ Object
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_proc ⇒ Object
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_proc ⇒ Object
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_proc ⇒ Object
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_size ⇒ Object
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
55 56 57 |
# File 'lib/aerospike/utils/pool.rb', line 55 def empty? @pool.empty? end |
#inspect ⇒ Object
64 65 66 |
# File 'lib/aerospike/utils/pool.rb', line 64 def inspect "#<Aerospike::Pool: size=#{size}>" end |
#length ⇒ Object 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 |