Class: ApplicationInsights::Channel::QueueBase
- Inherits:
-
Object
- Object
- ApplicationInsights::Channel::QueueBase
- Defined in:
- lib/application_insights/channel/queue_base.rb
Overview
The base class for all types of queues for use in conjunction with an implementation of SenderBase. The queue will notify the sender that it needs to pick up items when it reaches #max_queue_length, or when the consumer calls #flush.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#max_queue_length ⇒ Fixnum
The maximum number of items that will be held by the queue before the queue will call the #flush method.
-
#sender ⇒ SenderBase
The sender that is associated with this queue that this queue will use to send data to the service.
Instance Method Summary collapse
-
#empty? ⇒ Boolean
Indicates whether the queue is empty.
-
#flush ⇒ Object
Flushes the current queue by notifying the #sender.
-
#initialize(sender) ⇒ QueueBase
constructor
Initializes a new instance of the class.
-
#pop ⇒ Contracts::Envelope
Pops a single item from the queue and returns it.
-
#push(item) ⇒ Object
Adds the passed in item object to the queue and calls #flush if the size of the queue is larger than #max_queue_length.
Constructor Details
#initialize(sender) ⇒ QueueBase
Initializes a new instance of the class.
13 14 15 16 17 |
# File 'lib/application_insights/channel/queue_base.rb', line 13 def initialize(sender) @queue = Queue.new @max_queue_length = 500 self.sender = sender end |
Instance Attribute Details
#max_queue_length ⇒ Fixnum
The maximum number of items that will be held by the queue before the queue will call the #flush method.
22 23 24 |
# File 'lib/application_insights/channel/queue_base.rb', line 22 def max_queue_length @max_queue_length end |
#sender ⇒ SenderBase
The sender that is associated with this queue that this queue will use to send data to the service.
27 28 29 |
# File 'lib/application_insights/channel/queue_base.rb', line 27 def sender @sender end |
Instance Method Details
#empty? ⇒ Boolean
Indicates whether the queue is empty.
68 69 70 |
# File 'lib/application_insights/channel/queue_base.rb', line 68 def empty? @queue.empty? end |
#flush ⇒ Object
Flushes the current queue by notifying the #sender. This method needs to be overridden by a concrete implementations of the queue class.
63 64 |
# File 'lib/application_insights/channel/queue_base.rb', line 63 def flush end |
#pop ⇒ Contracts::Envelope
Pops a single item from the queue and returns it. If the queue is empty, this method will return nil.
55 56 57 58 59 |
# File 'lib/application_insights/channel/queue_base.rb', line 55 def pop return @queue.pop(true) rescue ThreadError return nil end |
#push(item) ⇒ Object
Adds the passed in item object to the queue and calls #flush if the size of the queue is larger than #max_queue_length. This method does nothing if the passed in item is nil.
43 44 45 46 47 48 49 |
# File 'lib/application_insights/channel/queue_base.rb', line 43 def push(item) return unless item @queue.push(item) flush if @queue.length >= @max_queue_length end |