class Fluent::NamedPipeInput

Public Class Methods

new() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_namedpipe.rb, line 9
def initialize
    super
    @path = nil
end

Public Instance Methods

configure(conf) click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_namedpipe.rb, line 19
def configure(conf)
    super

    if !File.exists?(@path)
        raise ConfigError,"File not found #{@path}"
    end

    if @tag.nil? 
        raise ConfigError,"tag is empty"
    end

    configure_parser(conf)
end
configure_parser(conf) click to toggle source
# File lib/fluent/plugin/in_namedpipe.rb, line 33
def configure_parser(conf)
    @parser = TextParser.new
    @parser.configure(conf)
end
configure_tag() click to toggle source

TODO: Not yet used

# File lib/fluent/plugin/in_namedpipe.rb, line 39
def configure_tag
    if @tag.index('*')
        @tag_prefix, @tag_suffix = @tag.split('*')
        @tag_suffix ||= ''
    else
        @tag_prefix = nil
        @tag_suffix = nil
    end

end
parse_line(line) click to toggle source
# File lib/fluent/plugin/in_namedpipe.rb, line 50
def parse_line(line)
    return @parser.parse(line)
end
run() click to toggle source
# File lib/fluent/plugin/in_namedpipe.rb, line 61
def run
    until @finished
        begin
            lines = @pipe.gets
            if lines.nil?
                sleep @receive_interval
                next
            end

            lines = lines.split("\n")
            lines.each { |line| 
                time, record = parse_line(line)
                if time && record
                    Engine.emit(@tag,time,record)
                else
                    log.warn "Pattern not match: #{line.inspect}"
                end
            }
        rescue
            log.error "unexpected error", :error=>$!.to_s
            log.error_backtrace
        end
    end
end
shutdown() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_namedpipe.rb, line 86
def shutdown
    super
    @finished = true
    @thread.join
    @pipe.close
end
start() click to toggle source
Calls superclass method
# File lib/fluent/plugin/in_namedpipe.rb, line 54
def start
    super
    @pipe = open(@path,"r")
    @finished = false
    @thread = Thread.new(&method(:run))
end