Class: EM::APNS::ConnectionPool
- Inherits:
-
Object
- Object
- EM::APNS::ConnectionPool
- Defined in:
- lib/em-apns/connection_pool.rb
Overview
simple connection pool using EM queue, default size 4
Instance Attribute Summary collapse
-
#queue ⇒ Object
readonly
Returns the value of attribute queue.
Instance Method Summary collapse
- #add_connection ⇒ Object
-
#initialize ⇒ ConnectionPool
constructor
A new instance of ConnectionPool.
- #queue_worker_loop ⇒ Object
Constructor Details
#initialize ⇒ ConnectionPool
Returns a new instance of ConnectionPool.
7 8 9 10 11 12 |
# File 'lib/em-apns/connection_pool.rb', line 7 def initialize @pool_size = EM::APNS.pool || 4 @connections = [] @queue = EM::Queue.new @pool_size.times { add_connection } end |
Instance Attribute Details
#queue ⇒ Object (readonly)
Returns the value of attribute queue.
5 6 7 |
# File 'lib/em-apns/connection_pool.rb', line 5 def queue @queue end |
Instance Method Details
#add_connection ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/em-apns/connection_pool.rb', line 23 def add_connection connection = EM.connect(EM::APNS.host, 2195, Connection) connection.on_unbind do |conn| @connections.delete(conn) EM.next_tick{ add_connection } end @connections << connection queue_worker_loop.call connection end |
#queue_worker_loop ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/em-apns/connection_pool.rb', line 14 def queue_worker_loop proc{ |connection| @queue.pop do |notification| connection.send_data(notification) EM.next_tick { queue_worker_loop.call connection } end } end |