Class: LogStash::Outputs::OSS::FileManager

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/outputs/oss/file_manager.rb

Defined Under Namespace

Classes: FileGeneratorInitializer

Constant Summary collapse

STALE_FILES_CHECK_INTERVAL_IN_SECONDS =
15 * 60

Instance Method Summary collapse

Constructor Details

#initialize(logger, encoding, temporary_directory) ⇒ FileManager

Returns a new instance of FileManager.



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/logstash/outputs/oss/file_manager.rb', line 18

def initialize(logger, encoding, temporary_directory)
  @logger = logger
  @encoding = encoding

  @temporary_directory = temporary_directory
  # map of generators
  # since `prefix` support string interpolation, so we will write many files at the same time
  @prefixed_generators = ConcurrentHashMap.new

  @file_generator_initialize = FileGeneratorInitializer.new(encoding, temporary_directory)

  start_stale_files_check
end

Instance Method Details

#closeObject



69
70
71
# File 'lib/logstash/outputs/oss/file_manager.rb', line 69

def close
  @stale_check.shutdown
end

#get_file_generator(prefix) ⇒ Object



32
33
34
# File 'lib/logstash/outputs/oss/file_manager.rb', line 32

def get_file_generator(prefix)
  @prefixed_generators.computeIfAbsent(prefix, @file_generator_initialize).with_lock {|generator| yield generator}
end

#prefixesObject



36
37
38
# File 'lib/logstash/outputs/oss/file_manager.rb', line 36

def prefixes
  @prefixed_generators.keySet
end