Class: Push::Daemon::App

Inherits:
Object
  • Object
show all
Defined in:
lib/push/daemon/app.rb

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

.appsObject (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

#configsObject

Returns the value of attribute configs.



55
56
57
# File 'lib/push/daemon/app.rb', line 55

def configs
  @configs
end

#database_connectionsObject (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_connectionsObject



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

.loadObject



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

.readyObject



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

.startObject



34
35
36
# File 'lib/push/daemon/app.rb', line 34

def self.start
  @apps.values.map(&:start)
end

.stopObject



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

Returns:

  • (Boolean)


80
81
82
# File 'lib/push/daemon/app.rb', line 80

def ready?
  @queue.notifications_processed?
end

#startObject



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

#stopObject



75
76
77
78
# File 'lib/push/daemon/app.rb', line 75

def stop
  @handlers.map(&:stop)
  @providers.map(&:stop)
end