class Carnivore::Source::CarnFile
Carnivore
source for consumption from files
Attributes
fetcher[R]
@return [Symbol] registry name of fetcher
message_queue[R]
@return [Queue] queue to hold messages
path[R]
@return [String] path to file
Public Instance Methods
connect()
click to toggle source
Start the line fetcher
# File lib/carnivore-files/carn_file.rb, line 29 def connect case args[:foundation].to_sym when :poll @fetcher = Carnivore::Files::Util::Fetcher::Poll.new(args.merge(:queue => message_queue)) else @fetcher = Carnivore::Files::Util::Fetcher::Penguin.new(args.merge(:queue => message_queue)) end fetcher.async.start_fetcher end
receive(*_)
click to toggle source
@return [Array<Hash>] return messages
# File lib/carnivore-files/carn_file.rb, line 40 def receive(*_) defer{ message_queue.pop } end
setup(*_)
click to toggle source
Setup source
@param args [Hash] @option args [String] :path path to file @option args [Symbol] :foundation underlying file interaction library
# File lib/carnivore-files/carn_file.rb, line 20 def setup(*_) @path = ::File.expand_path(args[:path]) @message_queue = Queue.new unless(args[:foundation]) args[:foundation] = RUBY_PLATFORM == 'java' ? :poll : :penguin end end
transmit(payload, *args)
click to toggle source
Send payload
@param payload [Object] payload to transmit
# File lib/carnivore-files/carn_file.rb, line 47 def transmit(payload, *args) fetcher.write_line(payload) end
Protected Instance Methods
format_message(m)
click to toggle source
Format message into customized Hash
@param m [Object] payload @return [Hash]
# File lib/carnivore-files/carn_file.rb, line 57 def format_message(m) Smash.new(:path => path, :content => m) end