Class: LogStash::Outputs::Application_insights::Sub_channel

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/application_insights/sub_channel.rb

Constant Summary collapse

REPORT_BYTESIZE =
250 * 1024

Instance Method Summary collapse

Constructor Details

#initialize(event_separator) ⇒ Sub_channel

Returns a new instance of Sub_channel.



27
28
29
30
31
32
# File 'lib/logstash/outputs/application_insights/sub_channel.rb', line 27

def initialize ( event_separator )
  @semaphore = Mutex.new
  @event_separator = event_separator
  @event_separator_bytesize = @event_separator.bytesize
  reset!
end

Instance Method Details

#<<(serialized_event) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/logstash/outputs/application_insights/sub_channel.rb', line 42

def << serialized_event
  @semaphore.synchronize {
    begin
      @block_list << ( @block = Block.new( @event_separator ) ) unless @block
      @block << serialized_event
      @block = nil if @block.is_full?

      @bytesize += ( serialized_event.bytesize + @event_separator_bytesize )
      unreported_bytesize = @bytesize - @reported_bytesize
      if unreported_bytesize > REPORT_BYTESIZE
        State.instance.inc_upload_bytesize( unreported_bytesize )
        @reported_bytesize = @bytesize
      end
    rescue BlockOverflowError
      @block = nil
      retry
    rescue BlockTooSmallError
      @@logger.error { "failed to receive event - " + "event too big" }
    end
  }
end

#get_block_list!Object



64
65
66
67
68
69
70
71
72
# File 'lib/logstash/outputs/application_insights/sub_channel.rb', line 64

def get_block_list!
  @semaphore.synchronize {
    unreported_bytesize = @bytesize - @reported_bytesize
    State.instance.inc_upload_bytesize( unreported_bytesize ) if unreported_bytesize > 0
    block_list = @block_list
    reset!
    block_list
  }
end

#reset!Object



34
35
36
37
38
39
# File 'lib/logstash/outputs/application_insights/sub_channel.rb', line 34

def reset!
  @bytesize = 0
  @reported_bytesize = 0
  @block_list = [  ]
  @block = nil
end