class LogStash::Outputs::Application_insights::Notification_recovery

Public Class Methods

instance() click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 101
def self.instance
  @@instance
end

Private Class Methods

new() click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 26
def initialize
  configuration = Config.current
  @resurrect_delay = configuration[:resurrect_delay]
  @queue = Queue.new

  @closing = nil
  @thread = nil
end

Public Instance Methods

close() click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 56
def close
  @closing = true
  # @thread.join
end
enqueue( tuple ) click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 52
def enqueue ( tuple )
  @queue << tuple
end
recover_later( tuple ) click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 40
def recover_later ( tuple )
  @notification_state_on = false
  if stopped?
    @state ||= State.instance
    @state.dec_pending_notifications
    @shutdown ||= Shutdown.instance
    @shutdown.display_msg("!!! notification won't recover in this session due to shutdown")
  else
    @queue << tuple
  end
end
start() click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 35
def start
  @test_notification = Test_notification.new
  @thread = recovery_thread
end

Private Instance Methods

recovery_thread() click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 67
def recovery_thread
  Thread.new do
    counter = Concurrent::AtomicFixnum.new(0)

    loop do
      tuple = @queue.pop
      Stud.stoppable_sleep(Float::INFINITY, 1) { ( state_on? || stopped? ) && 10 > counter.value }

      if stopped? && !state_on?
        recover_later( tuple )
      else
        counter.increment
        Thread.new( counter, tuple ) do |counter, tuple|
          Notification.new( tuple ).notify
          counter.decrement
        end
      end
      tuple = nil # release for GC
    end
  end
end
state_on?() click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 89
def state_on?
  return @notification_state_on if @notification_state_on
  @notification_state_on = @test_notification.test
  return @notification_state_on if @notification_state_on
  sleep( @resurrect_delay )
  @notification_state_on
end
stopped?() click to toggle source
# File lib/logstash/outputs/application_insights/notification_recovery.rb, line 63
def stopped?
  @closing
end