Class: Rpush::Notifier

Inherits:
Object
  • Object
show all
Defined in:
lib/rpush/notifier.rb

Overview

This class notifies the sleeping Rpush Daemon that there are new Notifications to send, and to interrupt its sleep to send them immediately. The purpose of this is to allow much higher sleep times to reduce database polling activity.

Instance Method Summary collapse

Constructor Details

#initialize(host, port) ⇒ Notifier

Returns a new instance of Notifier.



8
9
10
# File 'lib/rpush/notifier.rb', line 8

def initialize(host, port)
  @host, @port = host, port
end

Instance Method Details

#closeObject

close the udp socket



27
28
29
30
31
32
# File 'lib/rpush/notifier.rb', line 27

def close
  if @socket
    @socket.close
    @socket = nil
  end
end

#notifyObject

notify the daemon that there is a Notification to send.



13
14
15
# File 'lib/rpush/notifier.rb', line 13

def notify
  socket.write('x')
end

#socketUDPSocket

Returns:

  • (UDPSocket)


18
19
20
21
22
23
24
# File 'lib/rpush/notifier.rb', line 18

def socket
  if @socket.nil?
    @socket = UDPSocket.new
    @socket.connect(@host, @port)
  end
  @socket
end