Class: LogStash::Outputs::Application_insights::Block

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

Constant Summary collapse

@@Block_number =
0
@@semaphore =
Mutex.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event_separator) ⇒ Block

Returns a new instance of Block.



45
46
47
48
49
50
51
52
# File 'lib/logstash/outputs/application_insights/block.rb', line 45

def initialize ( event_separator )
  @buffer = [  ]
  @bytesize = 0
  @events_count = 0
  @event_separator = event_separator
  @event_separator_bytesize = @event_separator.bytesize
  @block_numbers = nil
end

Instance Attribute Details

#block_numbersObject (readonly)

Returns the value of attribute block_numbers.



29
30
31
# File 'lib/logstash/outputs/application_insights/block.rb', line 29

def block_numbers
  @block_numbers
end

#bufferObject (readonly)

Returns the value of attribute buffer.



26
27
28
# File 'lib/logstash/outputs/application_insights/block.rb', line 26

def buffer
  @buffer
end

#bytesObject (readonly)

Returns the value of attribute bytes.



25
26
27
# File 'lib/logstash/outputs/application_insights/block.rb', line 25

def bytes
  @bytes
end

#bytesizeObject (readonly)

Returns the value of attribute bytesize.



27
28
29
# File 'lib/logstash/outputs/application_insights/block.rb', line 27

def bytesize
  @bytesize
end

#done_timeObject (readonly)

Returns the value of attribute done_time.



30
31
32
# File 'lib/logstash/outputs/application_insights/block.rb', line 30

def done_time
  @done_time
end

#events_countObject (readonly)

Returns the value of attribute events_count.



28
29
30
# File 'lib/logstash/outputs/application_insights/block.rb', line 28

def events_count
  @events_count
end

#oldest_event_timeObject (readonly)

Returns the value of attribute oldest_event_time.



31
32
33
# File 'lib/logstash/outputs/application_insights/block.rb', line 31

def oldest_event_time
  @oldest_event_time
end

Class Method Details

.generate_block_numberObject



39
40
41
# File 'lib/logstash/outputs/application_insights/block.rb', line 39

def self.generate_block_number
  @@semaphore.synchronize { @@Block_number = ( @@Block_number + 1 ) % 1000000 }
end

Instance Method Details

#<<(data) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/logstash/outputs/application_insights/block.rb', line 70

def << (data)
  @bytesize += data.bytesize + @event_separator_bytesize

  # if first data, it will accept even it overflows
  if is_overflowed? && @events_count > 0
    @bytesize -= data.bytesize + @event_separator_bytesize
    raise BlockTooSmallError if is_empty?
    raise BlockOverflowError
  end

  @oldest_event_time ||= Time.now.utc
  @events_count += 1
  @buffer << data
end

#concat(other) ⇒ Object

concatenate two blocks into one



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/logstash/outputs/application_insights/block.rb', line 55

def concat ( other )
  if @bytesize + other.bytesize <= BLOB_BLOCK_MAX_BYTESIZE
    if @block_numbers
      @block_numbers.concat( other.block_numbers ) if @block_numbers
      @bytes += other.bytes
      @done_time = other.done_time if other.done_time > @done_time
    else
      @buffer.concat( other.buffer )
    end
    @events_count += other.events_count
    @oldest_event_time = other.oldest_event_time if other.oldest_event_time < @oldest_event_time
    @bytesize += other.bytesize
  end
end

#disposeObject



85
86
87
88
89
90
91
92
93
# File 'lib/logstash/outputs/application_insights/block.rb', line 85

def dispose
  @bytes = nil
  @buffer = nil
  @bytesize = nil
  @events_count = nil
  @done_time = nil
  @oldest_event_time = nil
  @block_numbers = nil
end

#is_full?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/logstash/outputs/application_insights/block.rb', line 103

def is_full?
  @bytesize >= BLOB_BLOCK_MAX_BYTESIZE
end

#sealObject



95
96
97
98
99
100
101
# File 'lib/logstash/outputs/application_insights/block.rb', line 95

def seal
  @block_numbers = [ Block.generate_block_number ]
  @done_time = Time.now.utc
  @buffer << "" # required to add eol after last event
  @bytes = @buffer.join( @event_separator )
  @buffer = nil # release the memory of the array
end