Class: Fluent::ForwardInput
- Defined in:
- lib/fluent/plugin/in_forward.rb
Defined Under Namespace
Classes: Handler, HeartbeatRequestHandler
Constant Summary
Constants included from Configurable
Configurable::CONFIG_TYPE_REGISTRY
Instance Attribute Summary
Attributes inherited from Input
Attributes included from PluginLoggerMixin
Instance Method Summary collapse
- #configure(conf) ⇒ Object
-
#initialize ⇒ ForwardInput
constructor
A new instance of ForwardInput.
- #listen ⇒ Object
-
#run ⇒ Object
config_param :path, :string, :default => DEFAULT_SOCKET_PATH def listen if File.exist?(@path) File.unlink(@path) end FileUtils.mkdir_p File.dirname(@path) log.debug “listening fluent socket on #@path” Coolio::UNIXServer.new(@path, Handler, method(:on_message)) end.
- #shutdown ⇒ Object
- #start ⇒ Object
Methods included from PluginLoggerMixin
Methods included from PluginId
Methods included from Configurable
#config, included, lookup_type, register_type
Constructor Details
#initialize ⇒ ForwardInput
Returns a new instance of ForwardInput.
28 29 30 31 |
# File 'lib/fluent/plugin/in_forward.rb', line 28 def initialize super require 'fluent/plugin/socket_util' end |
Instance Method Details
#configure(conf) ⇒ Object
53 54 55 |
# File 'lib/fluent/plugin/in_forward.rb', line 53 def configure(conf) super end |
#listen ⇒ Object
89 90 91 92 93 94 |
# File 'lib/fluent/plugin/in_forward.rb', line 89 def listen log.info "listening fluent socket on #{@bind}:#{@port}" s = Coolio::TCPServer.new(@bind, @port, Handler, @linger_timeout, log, method(:on_message)) s.listen(@backlog) unless @backlog.nil? s end |
#run ⇒ Object
config_param :path, :string, :default => DEFAULT_SOCKET_PATH def listen
if File.exist?(@path)
File.unlink(@path)
end
FileUtils.mkdir_p File.dirname(@path)
log.debug "listening fluent socket on #{@path}"
Coolio::UNIXServer.new(@path, Handler, method(:on_message))
end
106 107 108 109 110 111 |
# File 'lib/fluent/plugin/in_forward.rb', line 106 def run @loop.run(@blocking_timeout) rescue => e log.error "unexpected error", error: e, error_class: e.class log.error_backtrace end |
#shutdown ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fluent/plugin/in_forward.rb', line 72 def shutdown # In test cases it occasionally appeared that when detaching a watcher, another watcher is also detached. # In the case in the iteration of watchers, a watcher that has been already detached is intended to be detached # and therfore RuntimeError occurs saying that it is not attached to a loop. # It occures only when testing for sending responses to ForwardOutput. # Sending responses needs to write the socket that is previously used only to read # and a handler has 2 watchers that is used to read and to write. # This problem occurs possibly because those watchers are thought to be related to each other # and when detaching one of them the other is also detached for some reasons. # As a workaround, check if watchers are attached before detaching them. @loop.watchers.each {|w| w.detach if w.attached? } @loop.stop @usock.close @thread.join @lsock.close end |
#start ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/fluent/plugin/in_forward.rb', line 57 def start @loop = Coolio::Loop.new @lsock = listen @loop.attach(@lsock) @usock = SocketUtil.create_udp_socket(@bind) @usock.bind(@bind, @port) @usock.fcntl(Fcntl::F_SETFL, Fcntl::O_NONBLOCK) @hbr = HeartbeatRequestHandler.new(@usock, method(:on_heartbeat_request)) @loop.attach(@hbr) @thread = Thread.new(&method(:run)) end |