Class: LogStash::Outputs::Application_insights::Local_file

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(filename, is_gzip_file) ⇒ Local_file

Returns a new instance of Local_file.



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/logstash/outputs/application_insights/local_file.rb', line 33

def initialize ( filename, is_gzip_file )
  @file_name = filename
  @writer = write_file = File.new( @file_name, "wb" )
  @writer = Zlib::GzipWriter.new( write_file ) if is_gzip_file
  @read_file = nil
  @bytesize = 0
  @events_count = 0
  @first_block_number = nil
  @next_block_number = nil
  @next_event_count = nil
end

Instance Attribute Details

#bytesizeObject (readonly)

Returns the value of attribute bytesize.



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

def bytesize
  @bytesize
end

#events_countObject (readonly)

Returns the value of attribute events_count.



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

def events_count
  @events_count
end

#file_sizeObject (readonly)

Returns the value of attribute file_size.



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

def file_size
  @file_size
end

#oldest_event_timeObject (readonly)

Returns the value of attribute oldest_event_time.



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

def oldest_event_time
  @oldest_event_time
end

Instance Method Details

#<<(block) ⇒ Object



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

def << ( block )
  @bytesize += block.bytesize
  @events_count += block.events_count

  @writer.write( block.bytes )
  State.instance.dec_upload_bytesize( block.bytesize )

  @oldest_event_time = block.oldest_event_time if @oldest_event_time.nil? || block.oldest_event_time < @oldest_event_time
  @done_time = block.done_time if @done_time.nil? || block.done_time > @done_time
end

#close_readObject



50
51
52
53
# File 'lib/logstash/outputs/application_insights/local_file.rb', line 50

def close_read
  @read_file.close if @read_file
  @read_file = nil
end

#disposeObject



98
99
100
101
102
103
104
105
106
107
# File 'lib/logstash/outputs/application_insights/local_file.rb', line 98

def dispose
  @bytesize = nil
  @events_count = nil
  @done_time = nil
  @oldest_event_time = nil
  seal
  close_read
  File.delete( @file_name ) if @file_name
  @file_name = nil
end

#get_next_blockObject



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

def get_next_block
  block = Block.new
  block.bytes = @read_file.read(BLOB_BLOCK_MAX_BYTESIZE)
  return nil if block.bytes.nil? || 0 == block.bytes.length

  block.bytesize = block.bytes.length
  State.instance.inc_upload_bytesize( block.bytesize )

  block.done_time = @done_time
  block.oldest_event_time = @oldest_event_time
  block.block_numbers = [ @next_block_number ]
  block.events_count = @next_event_count

  @next_event_count = @events_per_block
  @next_block_number += 1

  block
end

#open_readObject



55
56
57
58
59
60
61
62
63
64
# File 'lib/logstash/outputs/application_insights/local_file.rb', line 55

def open_read
  @read_file = File.new( @file_name, "rb" ) # File.new( @file_name, File::RDWR )
  @file_size =  @read_file.size
  @blocks_num = ( @file_size + BLOB_BLOCK_MAX_BYTESIZE - 1 ) / BLOB_BLOCK_MAX_BYTESIZE
  @events_per_block = @events_count / @blocks_num

  @next_event_count = @events_per_block + ( @events_count % @blocks_num )
  @first_block_number ||= Block.generate_block_numbers( @blocks_num )
  @next_block_number = @first_block_number
end

#sealObject



45
46
47
48
# File 'lib/logstash/outputs/application_insights/local_file.rb', line 45

def seal
  @writer.close if @writer
  @writer = nil
end