Class: Fluent::Plugin::GroongaInput::HTTPInput::Handler
- Inherits:
-
Object
- Object
- Fluent::Plugin::GroongaInput::HTTPInput::Handler
- Defined in:
- lib/fluent/plugin/in_groonga.rb
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(input, connection, repeater) ⇒ Handler
constructor
A new instance of Handler.
- #on_read(data) ⇒ Object
- #on_response_complete(response) ⇒ Object
- #write_back(data) ⇒ Object
Constructor Details
#initialize(input, connection, repeater) ⇒ Handler
Returns a new instance of Handler.
189 190 191 192 193 194 195 |
# File 'lib/fluent/plugin/in_groonga.rb', line 189 def initialize(input, connection, repeater) @input = input @connection = connection @repeater = repeater @request_handler = RequestHandler.new(@input, @repeater) @response_handler = ResponseHandler.new(self, @input) end |
Instance Method Details
#close ⇒ Object
239 240 241 |
# File 'lib/fluent/plugin/in_groonga.rb', line 239 def close @connection.close end |
#on_read(data) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/fluent/plugin/in_groonga.rb', line 197 def on_read(data) begin @request_handler << data rescue HTTP::Parser::Error, URI::InvalidURIError @input.log.error("[input][groonga][request][error] " + "failed to parse HTTP request:", :error => "#{$!.class}: #{$!}") @input.log.error_backtrace reply_error_response("400 Bad Request") rescue @input.log.error("[input][groonga][request][error] " + "failed to handle HTTP request:", :error => "#{$!.class}: #{$!}") @input.log.error_backtrace reply_error_response("500 Internal Server Error") end end |
#on_response_complete(response) ⇒ Object
229 230 231 232 233 234 235 236 237 |
# File 'lib/fluent/plugin/in_groonga.rb', line 229 def on_response_complete(response) if need_emit?(response) @input.emit(@request_handler.command, @request_handler.params) end @connection.on(:write_complete) do @repeater.close end end |
#write_back(data) ⇒ Object
215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/fluent/plugin/in_groonga.rb', line 215 def write_back(data) begin @response_handler << data rescue @input.log.error("[input][groonga][response][error] " + "failed to handle HTTP response from Groonga:", :error => "#{$!.class}: #{$!}") @input.log.error_backtrace reply_error_response("500 Internal Server Error") return end @connection.write(data) end |