Class: LogStash::Outputs::Application_insights::Block
- Inherits:
-
Object
- Object
- LogStash::Outputs::Application_insights::Block
- Defined in:
- lib/logstash/outputs/application_insights/block.rb
Constant Summary collapse
- @@Block_number =
0
- @@semaphore =
Mutex.new
Instance Attribute Summary collapse
-
#block_numbers ⇒ Object
readonly
Returns the value of attribute block_numbers.
-
#buffer ⇒ Object
readonly
Returns the value of attribute buffer.
-
#bytes ⇒ Object
readonly
Returns the value of attribute bytes.
-
#bytesize ⇒ Object
readonly
Returns the value of attribute bytesize.
-
#done_time ⇒ Object
readonly
Returns the value of attribute done_time.
-
#events_count ⇒ Object
readonly
Returns the value of attribute events_count.
-
#oldest_event_time ⇒ Object
readonly
Returns the value of attribute oldest_event_time.
Class Method Summary collapse
Instance Method Summary collapse
- #<<(data) ⇒ Object
-
#concat(other) ⇒ Object
concatenate two blocks into one.
- #dispose ⇒ Object
-
#initialize(event_separator) ⇒ Block
constructor
A new instance of Block.
- #is_full? ⇒ Boolean
- #seal ⇒ Object
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_numbers ⇒ Object (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 |
#buffer ⇒ Object (readonly)
Returns the value of attribute buffer.
26 27 28 |
# File 'lib/logstash/outputs/application_insights/block.rb', line 26 def buffer @buffer end |
#bytes ⇒ Object (readonly)
Returns the value of attribute bytes.
25 26 27 |
# File 'lib/logstash/outputs/application_insights/block.rb', line 25 def bytes @bytes end |
#bytesize ⇒ Object (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_time ⇒ Object (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_count ⇒ Object (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_time ⇒ Object (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_number ⇒ Object
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 |
#dispose ⇒ Object
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
103 104 105 |
# File 'lib/logstash/outputs/application_insights/block.rb', line 103 def is_full? @bytesize >= BLOB_BLOCK_MAX_BYTESIZE end |
#seal ⇒ Object
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 |