Class: AzureApplicationInsights::Channel::SynchronousQueue

Inherits:
QueueBase
  • Object
show all
Defined in:
lib/azure_application_insights/channel/synchronous_queue.rb

Overview

A synchronous queue for use in conjunction with the SynchronousSender. The queue will call AzureApplicationInsights::Channel::SenderBase#send when it reaches QueueBase#max_queue_length, or when the consumer calls #flush.

Examples:

require 'azure_application_insights'
require 'thread'
queue = AzureApplicationInsights::Channel::SynchronousQueue.new nil
queue.max_queue_length = 1
queue.push 1

Instance Attribute Summary

Attributes inherited from QueueBase

#max_queue_length, #sender

Instance Method Summary collapse

Methods inherited from QueueBase

#empty?, #pop, #push

Constructor Details

#initialize(sender) ⇒ SynchronousQueue

Initializes a new instance of the class.

Parameters:

  • sender (SenderBase)

    the sender object that will be used in conjunction with this queue.



19
20
21
# File 'lib/azure_application_insights/channel/synchronous_queue.rb', line 19

def initialize(sender)
  super sender
end

Instance Method Details

#flushObject

Flushes the current queue by by calling QueueBase#sender‘s AzureApplicationInsights::Channel::SenderBase#send method.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/azure_application_insights/channel/synchronous_queue.rb', line 25

def flush
  local_sender = @sender
  return unless local_sender

  while true
    # get at most send_buffer_size items and send them
    data = []
    while data.length < local_sender.send_buffer_size
      item = pop()
      break if not item
      data.push item
    end

    break if data.length == 0

    local_sender.send(data)
  end
end