Class: Push0r::Queue
- Inherits:
-
Object
- Object
- Push0r::Queue
- Defined in:
- lib/push0r/Queue.rb
Overview
A Queue is used to register services to be used to transmit PushMessages. Single PushMessages are then put into the queue and a call to the #flush method transmits all enqueued messages using the registered services. In a sense, Queue is the class that ties all the other Push0r components together.
Instance Method Summary collapse
-
#add(message) ⇒ Boolean
Adds a PushMessage to the queue.
-
#flush ⇒ FlushResult
Flushes the queue by transmitting the enqueued messages using the registered services.
-
#initialize ⇒ Queue
constructor
A new instance of Queue.
-
#register_service(service) ⇒ void
Registers a Service with the Queue.
Constructor Details
#initialize ⇒ Queue
Returns a new instance of Queue.
24 25 26 27 |
# File 'lib/push0r/Queue.rb', line 24 def initialize @services = [] @queued_messages = {} end |
Instance Method Details
#add(message) ⇒ Boolean
Adds a PushMessage to the queue
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/push0r/Queue.rb', line 44 def add() @services.each do |service| if service.can_send?() if @queued_messages[service].nil? @queued_messages[service] = [] end @queued_messages[service] << return true end end return false end |
#flush ⇒ FlushResult
Flushes the queue by transmitting the enqueued messages using the registered services
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/push0r/Queue.rb', line 59 def flush = [] = [] @queued_messages.each do |service, | service.init_push .each do || service.send() end (failed, new_token) = service.end_push += failed += new_token end @queued_messages = {} return FlushResult.new(, ) end |
#register_service(service) ⇒ void
Every service can only be registered once with the same queue
This method returns an undefined value.
Registers a Service with the Queue
34 35 36 37 38 |
# File 'lib/push0r/Queue.rb', line 34 def register_service(service) unless @services.include?(service) @services << service end end |