class LogStash::Filters::FetchStrategy::File::ExactRegex

Public Class Methods

new(dictionary, rw_lock) click to toggle source
# File lib/logstash/filters/fetch_strategy/file.rb, line 28
def initialize(dictionary, rw_lock)
  @keys_regex = Hash.new()
  @dictionary = dictionary
  @read_lock = rw_lock.readLock
end

Public Instance Methods

dictionary_updated() click to toggle source
# File lib/logstash/filters/fetch_strategy/file.rb, line 34
def dictionary_updated
  @keys_regex.clear
  # rebuilding the regex map is time expensive
  # 100 000 keys takes 0.5 seconds on a high spec Macbook Pro
  # at least we are not doing it for every event like before
  @dictionary.keys.each{|k| @keys_regex[k] = Regexp.new(k)}
end
fetch(source, results) click to toggle source
# File lib/logstash/filters/fetch_strategy/file.rb, line 42
def fetch(source, results)
  @read_lock.lock
  begin
    key = @dictionary.keys.detect{|k| source.match(@keys_regex[k])}
    if key.nil?
      results[0] = false
    else
      results[1] = LogStash::Util.deep_clone(@dictionary[key])
    end
  ensure
    @read_lock.unlock
  end
end