Class: ApplicationInsights::Channel::AsynchronousQueue

Inherits:
QueueBase
  • Object
show all
Defined in:
lib/application_insights/channel/asynchronous_queue.rb

Overview

An asynchronous queue for use in conjunction with the AsynchronousSender. The queue will notify the sender that it needs to pick up items when it reaches QueueBase#max_queue_length, or when the consumer calls #flush via the #flush_notification event.

Examples:

require 'application_insights'
require 'thread'
queue = ApplicationInsights::Channel::AsynchronousQueue.new nil
Thread.new do
  sleep 1
  queue.push 1
  queue.flush
end
queue.flush_notification.wait
queue.flush_notification.clear
result = queue.pop

Instance Attribute Summary collapse

Attributes inherited from QueueBase

#max_queue_length, #sender

Instance Method Summary collapse

Methods inherited from QueueBase

#empty?, #pop

Constructor Details

#initialize(sender) ⇒ AsynchronousQueue

Initializes a new instance of the class.

Parameters:



30
31
32
33
# File 'lib/application_insights/channel/asynchronous_queue.rb', line 30

def initialize(sender)
  @flush_notification = Event.new
  super sender
end

Instance Attribute Details

#flush_notificationEvent (readonly)

The flush notification Event that the QueueBase#sender will use to get notified that a flush is needed.

Returns:



38
39
40
# File 'lib/application_insights/channel/asynchronous_queue.rb', line 38

def flush_notification
  @flush_notification
end

Instance Method Details

#flushObject

Flushes the current queue by notifying the QueueBase#sender via the #flush_notification event.



52
53
54
55
# File 'lib/application_insights/channel/asynchronous_queue.rb', line 52

def flush
  @flush_notification.set
  @sender.start if @sender
end

#push(item) ⇒ Object

Adds the passed in item object to the queue and notifies the QueueBase#sender to start an asynchronous send operation by calling ApplicationInsights::Channel::AsynchronousSender#start.

Parameters:



45
46
47
48
# File 'lib/application_insights/channel/asynchronous_queue.rb', line 45

def push(item)
  super item
  @sender.start if @sender
end