Class: Push::Daemon::App
- Inherits:
-
Object
- Object
- Push::Daemon::App
- Defined in:
- lib/push/daemon/app.rb
Class Attribute Summary collapse
-
.apps ⇒ Object
readonly
Returns the value of attribute apps.
Instance Attribute Summary collapse
-
#configs ⇒ Object
Returns the value of attribute configs.
-
#database_connections ⇒ Object
readonly
Returns the value of attribute database_connections.
Class Method Summary collapse
- .database_connections ⇒ Object
- .deliver(notification) ⇒ Object
- .load ⇒ Object
- .ready ⇒ Object
- .start ⇒ Object
- .stop ⇒ Object
Instance Method Summary collapse
- #deliver(notification) ⇒ Object
-
#initialize(name) ⇒ App
constructor
A new instance of App.
- #ready? ⇒ Boolean
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(name) ⇒ App
Returns a new instance of App.
46 47 48 49 50 51 52 53 |
# File 'lib/push/daemon/app.rb', line 46 def initialize(name) @name = name @configs = [] @handlers = [] @providers = [] @queue = DeliveryQueue.new @database_connections = 0 end |
Class Attribute Details
.apps ⇒ Object (readonly)
Returns the value of attribute apps.
5 6 7 |
# File 'lib/push/daemon/app.rb', line 5 def apps @apps end |
Instance Attribute Details
#configs ⇒ Object
Returns the value of attribute configs.
55 56 57 |
# File 'lib/push/daemon/app.rb', line 55 def configs @configs end |
#database_connections ⇒ Object (readonly)
Returns the value of attribute database_connections.
56 57 58 |
# File 'lib/push/daemon/app.rb', line 56 def database_connections @database_connections end |
Class Method Details
.database_connections ⇒ Object
42 43 44 |
# File 'lib/push/daemon/app.rb', line 42 def self.database_connections @apps.empty? ? 0 : @apps.values.collect{|x| x.database_connections }.inject(:+) end |
.deliver(notification) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/push/daemon/app.rb', line 26 def self.deliver(notification) if app = @apps[notification.app] app.deliver(notification) else Rapns::Daemon.logger.error("No such app '#{notification.app}' for notification #{notification.id}.") end end |
.load ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/push/daemon/app.rb', line 10 def self.load configurations = Push::Configuration.enabled configurations.each do |config| if @apps[config.app] == nil @apps[config.app] = App.new(config.app) end @apps[config.app].configs << config end end |
.ready ⇒ Object
20 21 22 23 24 |
# File 'lib/push/daemon/app.rb', line 20 def self.ready ready = [] @apps.each { |app, runner| ready << app if runner.ready? } ready end |
.start ⇒ Object
34 35 36 |
# File 'lib/push/daemon/app.rb', line 34 def self.start @apps.values.map(&:start) end |
.stop ⇒ Object
38 39 40 |
# File 'lib/push/daemon/app.rb', line 38 def self.stop @apps.values.map(&:stop) end |
Instance Method Details
#deliver(notification) ⇒ Object
58 59 60 |
# File 'lib/push/daemon/app.rb', line 58 def deliver(notification) @queue.push(notification) end |
#ready? ⇒ Boolean
80 81 82 |
# File 'lib/push/daemon/app.rb', line 80 def ready? @queue.notifications_processed? end |
#start ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/push/daemon/app.rb', line 62 def start @connection_pool = ConnectionPool.new @configs.each do |config| provider = load_provider(config.name, config.properties.merge({:connections => config.connections, :name => config.app})) @providers << provider @database_connections += provider.totalconnections @connection_pool.populate(provider) end @connection_pool.size.times do |i| @handlers << start_handler(i) end end |
#stop ⇒ Object
75 76 77 78 |
# File 'lib/push/daemon/app.rb', line 75 def stop @handlers.map(&:stop) @providers.map(&:stop) end |