Class: Pod4::ConnectionPool::Pool
- Inherits:
-
Object
- Object
- Pod4::ConnectionPool::Pool
- Defined in:
- lib/pod4/connection_pool.rb
Instance Method Summary collapse
- #<<(cl) ⇒ Object
- #_dump ⇒ Object
- #drop ⇒ Object
- #get_current ⇒ Object
- #get_free ⇒ Object
-
#initialize ⇒ Pool
constructor
A new instance of Pool.
- #release ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ Pool
Returns a new instance of Pool.
17 18 19 20 |
# File 'lib/pod4/connection_pool.rb', line 17 def initialize @items = [] @mutex = Mutex.new end |
Instance Method Details
#<<(cl) ⇒ Object
22 23 24 25 26 |
# File 'lib/pod4/connection_pool.rb', line 22 def <<(cl) @mutex.synchronize do @items << PoolItem.new(cl, Thread.current.object_id) end end |
#_dump ⇒ Object
53 54 55 56 57 |
# File 'lib/pod4/connection_pool.rb', line 53 def _dump @mutex.synchronize do @items end end |
#drop ⇒ Object
45 46 47 |
# File 'lib/pod4/connection_pool.rb', line 45 def drop @items.delete_if{|x| x.thread_id == Thread.current.object_id } end |
#get_current ⇒ Object
28 29 30 |
# File 'lib/pod4/connection_pool.rb', line 28 def get_current @items.find{|x| x.thread_id == Thread.current.object_id } end |
#get_free ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/pod4/connection_pool.rb', line 32 def get_free @mutex.synchronize do pi = @items.find{|x| x.thread_id.nil? } pi.thread_id = Thread.current.object_id if pi pi end end |
#release ⇒ Object
40 41 42 43 |
# File 'lib/pod4/connection_pool.rb', line 40 def release pi = get_current pi.thread_id = nil if pi end |
#size ⇒ Object
49 50 51 |
# File 'lib/pod4/connection_pool.rb', line 49 def size @items.size end |