Class: Rapns::Daemon::DeliveryHandler

Inherits:
Object
  • Object
show all
Includes:
DatabaseReconnectable
Defined in:
lib/rapns/daemon/delivery_handler.rb

Constant Summary collapse

STOP =
0x666
SELECT_TIMEOUT =
0.5
ERROR_TUPLE_BYTES =
6
APN_ERRORS =
{
  1 => "Processing error",
  2 => "Missing device token",
  3 => "Missing topic",
  4 => "Missing payload",
  5 => "Missing token size",
  6 => "Missing topic size",
  7 => "Missing payload size",
  8 => "Invalid token",
  255 => "None (unknown error)"
}
MAX_RETRIES =
4

Constants included from DatabaseReconnectable

Rapns::Daemon::DatabaseReconnectable::ADAPTER_ERRORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from DatabaseReconnectable

#check_database_is_connected, #database_connection_lost, #reconnect_database, #sleep_to_avoid_thrashing, #with_database_reconnect_and_retry

Constructor Details

#initialize(i) ⇒ DeliveryHandler

Returns a new instance of DeliveryHandler.



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

def initialize(i)
  @name = "DeliveryHandler #{i}"
  host = Rapns::Daemon.configuration.push.host
  port = Rapns::Daemon.configuration.push.port
  @connection = Connection.new(@name, host, port)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



23
24
25
# File 'lib/rapns/daemon/delivery_handler.rb', line 23

def name
  @name
end

Instance Method Details

#startObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/rapns/daemon/delivery_handler.rb', line 32

def start
  @connection.connect

  Thread.new do
    loop do
      break if @stop
      handle_next_notification
    end
  end
end

#stopObject



43
44
45
46
# File 'lib/rapns/daemon/delivery_handler.rb', line 43

def stop
  @stop = true
  Rapns::Daemon.delivery_queue.push(STOP)
end