Class: Push::Daemon::ConnectionPool
- Inherits:
-
Object
- Object
- Push::Daemon::ConnectionPool
- Defined in:
- lib/push/daemon/connection_pool.rb
Instance Method Summary collapse
- #checkin(connection) ⇒ Object
- #checkout(notification_type) ⇒ Object
-
#initialize ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
- #populate(provider) ⇒ Object
- #size ⇒ Object
Constructor Details
#initialize ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
4 5 6 |
# File 'lib/push/daemon/connection_pool.rb', line 4 def initialize() @connections = Hash.new end |
Instance Method Details
#checkin(connection) ⇒ Object
17 18 19 |
# File 'lib/push/daemon/connection_pool.rb', line 17 def checkin(connection) @connections[connection.class.to_s].push(connection) end |
#checkout(notification_type) ⇒ Object
21 22 23 |
# File 'lib/push/daemon/connection_pool.rb', line 21 def checkout(notification_type) @connections[notification_type.to_s].pop end |
#populate(provider) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/push/daemon/connection_pool.rb', line 8 def populate(provider) @connections[provider.connectiontype.to_s] = Queue.new provider.pushconnections.times do |i| c = provider.connectiontype.new(provider, i+1) c.connect checkin(c) end end |
#size ⇒ Object
25 26 27 |
# File 'lib/push/daemon/connection_pool.rb', line 25 def size @connections.values.collect{|x| x.length }.inject(:+) end |