Class: Aerospike::Pool
- Inherits:
-
Object
- Object
- Aerospike::Pool
- Defined in:
- lib/aerospike/utils/pool.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#cleanup_block ⇒ Object
Returns the value of attribute cleanup_block.
-
#create_block ⇒ Object
Returns the value of attribute create_block.
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.
25 26 27 28 29 30 31 |
# File 'lib/aerospike/utils/pool.rb', line 25 def initialize(max_size = 256, &block) @create_block = block @cleanup_block = nil @pool = Queue.new @max_size = max_size end |
Instance Attribute Details
#cleanup_block ⇒ Object
Returns the value of attribute cleanup_block.
23 24 25 |
# File 'lib/aerospike/utils/pool.rb', line 23 def cleanup_block @cleanup_block end |
#create_block ⇒ Object
Returns the value of attribute create_block.
23 24 25 |
# File 'lib/aerospike/utils/pool.rb', line 23 def create_block @create_block end |
Instance Method Details
#empty? ⇒ Boolean
49 50 51 |
# File 'lib/aerospike/utils/pool.rb', line 49 def empty? @pool.length == 0 end |
#inspect ⇒ Object
58 59 60 |
# File 'lib/aerospike/utils/pool.rb', line 58 def inspect "#<Aerospike::Pool: size=#{size}>" end |
#length ⇒ Object Also known as: size
53 54 55 |
# File 'lib/aerospike/utils/pool.rb', line 53 def length @pool.length end |
#offer(obj) ⇒ Object Also known as: <<
33 34 35 36 37 38 39 |
# File 'lib/aerospike/utils/pool.rb', line 33 def offer(obj) if @pool.length < @max_size @pool << obj elsif @cleanup_block @cleanup_block.call(obj) end end |
#poll(create_new = true) ⇒ Object
42 43 44 45 46 47 |
# File 'lib/aerospike/utils/pool.rb', line 42 def poll(create_new=true) non_block = true @pool.pop(non_block) rescue @create_block.call() if @create_block && create_new end |