Class: Carnivore::Source::CarnFile
- Inherits:
-
Carnivore::Source
- Object
- Carnivore::Source
- Carnivore::Source::CarnFile
- Defined in:
- lib/carnivore-files/carn_file.rb
Overview
Carnivore source for consumption from files
Instance Attribute Summary collapse
-
#fetcher ⇒ Symbol
readonly
Registry name of fetcher.
-
#path ⇒ String
readonly
Path to file.
Instance Method Summary collapse
-
#connect ⇒ Object
Start the line fetcher.
- #fetcher_destroyer ⇒ Object
-
#fetcher_failure(object, reason) ⇒ Object
Restart file collector if unexpectedly failed.
-
#receive(*args) ⇒ Array<Hash>
Return messages.
-
#setup(*_) ⇒ Object
Setup source.
-
#transmit(payload, *args) ⇒ Object
Send payload.
Instance Attribute Details
#fetcher ⇒ Symbol (readonly)
Returns registry name of fetcher.
11 12 13 |
# File 'lib/carnivore-files/carn_file.rb', line 11 def fetcher @fetcher end |
#path ⇒ String (readonly)
Returns path to file.
9 10 11 |
# File 'lib/carnivore-files/carn_file.rb', line 9 def path @path end |
Instance Method Details
#connect ⇒ Object
Start the line fetcher
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/carnivore-files/carn_file.rb', line 30 def connect @fetcher_name = "log_fetcher_#{name}".to_sym case args[:foundation].to_sym when :poll @fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args) else @fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args) end self.link fetcher fetcher.async.start_fetcher end |
#fetcher_destroyer ⇒ Object
53 54 55 56 57 |
# File 'lib/carnivore-files/carn_file.rb', line 53 def fetcher_destroyer if(fetcher && fetcher.alive?) fetcher.terminate end end |
#fetcher_failure(object, reason) ⇒ Object
Restart file collector if unexpectedly failed
46 47 48 49 50 51 |
# File 'lib/carnivore-files/carn_file.rb', line 46 def fetcher_failure(object, reason) if(reason && object == fetcher) error "File message collector unexpectedly failed: #{reason} (restarting)" connect end end |
#receive(*args) ⇒ Array<Hash>
Return messages
60 61 62 |
# File 'lib/carnivore-files/carn_file.rb', line 60 def receive(*args) (Celluloid::Future.new{ fetcher..pop }.value) end |
#setup(*_) ⇒ Object
Setup source
22 23 24 25 26 27 |
# File 'lib/carnivore-files/carn_file.rb', line 22 def setup(*_) @path = ::File.(args[:path]) unless(args[:foundation]) args[:foundation] = RUBY_PLATFORM == 'java' ? :poll : :penguin end end |
#transmit(payload, *args) ⇒ Object
Send payload
67 68 69 |
# File 'lib/carnivore-files/carn_file.rb', line 67 def transmit(payload, *args) fetcher.write_line(payload) end |