Class: APND::Daemon

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

Overview

The APND::Daemon maintains a persistent secure connection with Apple, (APND::Daemon::AppleConnection). Notifications are queued and periodically writen to the AppleConnection

Defined Under Namespace

Modules: Protocol Classes: AppleConnection, ServerConnection

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeDaemon

Create a connection to Apple and a new EM queue



25
26
27
28
29
30
31
# File 'lib/apnd/daemon.rb', line 25

def initialize
  @queue = EM::Queue.new
  @apple = APND::Daemon::AppleConnection.new
  @bind  = APND.settings.daemon.bind
  @port  = APND.settings.daemon.port
  @timer = APND.settings.daemon.timer
end

Class Method Details

.run!Object

Create a new Daemon and run it



17
18
19
20
# File 'lib/apnd/daemon.rb', line 17

def self.run!
  server = APND::Daemon.new
  server.run!
end

Instance Method Details

#run!Object

Run the daemon



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/apnd/daemon.rb', line 36

def run!
  EventMachine::run do
    APND.logger "Starting APND Daemon v#{APND::Version} on #{@bind}:#{@port}"
    EventMachine::start_server(@bind, @port, APND::Daemon::ServerConnection) do |server|
      server.queue = @queue
    end

    EventMachine::PeriodicTimer.new(@timer) do
      process_notifications!
    end
  end
end