Class: Fluent::StreamInput::Handler
- Inherits:
-
Coolio::Socket
- Object
- Coolio::Socket
- Fluent::StreamInput::Handler
- Defined in:
- lib/fluent/plugin/in_stream.rb
Instance Method Summary collapse
-
#initialize(io, on_message) ⇒ Handler
constructor
A new instance of Handler.
- #on_close ⇒ Object
- #on_connect ⇒ Object
- #on_read(data) ⇒ Object
- #on_read_json(data) ⇒ Object
- #on_read_msgpack(data) ⇒ Object
Constructor Details
#initialize(io, on_message) ⇒ Handler
Returns a new instance of Handler.
106 107 108 109 110 111 112 113 114 |
# File 'lib/fluent/plugin/in_stream.rb', line 106 def initialize(io, ) super(io) if io.is_a?(TCPSocket) opt = [1, @timeout.to_i].pack('I!I!') # { int l_onoff; int l_linger; } io.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, opt) end $log.trace { "accepted fluent socket object_id=#{self.object_id}" } @on_message = end |
Instance Method Details
#on_close ⇒ Object
144 145 146 |
# File 'lib/fluent/plugin/in_stream.rb', line 144 def on_close $log.trace { "closed fluent socket object_id=#{self.object_id}" } end |
#on_connect ⇒ Object
116 117 |
# File 'lib/fluent/plugin/in_stream.rb', line 116 def on_connect end |
#on_read(data) ⇒ Object
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fluent/plugin/in_stream.rb', line 119 def on_read(data) first = data[0] if first == '{' || first == '[' m = method(:on_read_json) @y = Yajl::Parser.new @y.on_parse_complete = @on_message else m = method(:on_read_msgpack) @u = MessagePack::Unpacker.new end (class<<self;self;end).module_eval do define_method(:on_read, m) end m.call(data) end |
#on_read_json(data) ⇒ Object
136 137 138 |
# File 'lib/fluent/plugin/in_stream.rb', line 136 def on_read_json(data) @y << data end |
#on_read_msgpack(data) ⇒ Object
140 141 142 |
# File 'lib/fluent/plugin/in_stream.rb', line 140 def on_read_msgpack(data) @u.feed_each(data, &@on_message) end |