Class: LogStash::Filters::FetchStrategy::File::ExactRegex

Inherits:
Object
  • Object
show all
Defined in:
lib/logstash/filters/fetch_strategy/file.rb

Instance Method Summary collapse

Constructor Details

#initialize(dictionary, rw_lock) ⇒ ExactRegex

Returns a new instance of ExactRegex.



28
29
30
31
32
# 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

Instance Method Details

#dictionary_updatedObject



34
35
36
37
38
39
40
# 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) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# 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