Class: Rpush::Notifier
- Inherits:
-
Object
- Object
- Rpush::Notifier
- 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
-
#close ⇒ Object
close the udp socket.
-
#initialize(host, port) ⇒ Notifier
constructor
A new instance of Notifier.
-
#notify ⇒ Object
notify the daemon that there is a Notification to send.
- #socket ⇒ UDPSocket
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
#close ⇒ Object
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 |
#notify ⇒ Object
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 |
#socket ⇒ 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 |