Class: Fluent::GroongaInput::HTTPInput::Handler
- Inherits:
-
Coolio::Socket
- Object
- Coolio::Socket
- Fluent::GroongaInput::HTTPInput::Handler
- Defined in:
- lib/fluent/plugin/in_groonga.rb
Instance Method Summary collapse
-
#initialize(socket, input) ⇒ Handler
constructor
A new instance of Handler.
- #on_connect ⇒ Object
- #on_read(data) ⇒ Object
- #on_response_complete(response) ⇒ Object
- #write_back(data) ⇒ Object
Constructor Details
#initialize(socket, input) ⇒ Handler
213 214 215 216 |
# File 'lib/fluent/plugin/in_groonga.rb', line 213 def initialize(socket, input) super(socket) @input = input end |
Instance Method Details
#on_connect ⇒ Object
218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/fluent/plugin/in_groonga.rb', line 218 def on_connect @repeater = @input.create_repeater(self) @repeater.on_connect_failed do $log.error("[input][groonga][connect][error] " + "failed to connect to Groonga:", :real_host => @input.real_host, :real_port => @input.real_port) close end @request_handler = RequestHandler.new(@input, @repeater) @response_handler = ResponseHandler.new(self) end |
#on_read(data) ⇒ Object
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 |
# File 'lib/fluent/plugin/in_groonga.rb', line 231 def on_read(data) begin @request_handler << data rescue HTTP::Parser::Error, URI::InvalidURIError $log.error("[input][groonga][request][error] " + "failed to parse HTTP request:", :error => "#{$!.class}: #{$!}") $log.error_backtrace reply_error_response("400 Bad Request") rescue $log.error("[input][groonga][request][error] " + "failed to handle HTTP request:", :error => "#{$!.class}: #{$!}") $log.error_backtrace reply_error_response("500 Internal Server Error") end end |
#on_response_complete(response) ⇒ Object
263 264 265 266 267 268 269 270 271 |
# File 'lib/fluent/plugin/in_groonga.rb', line 263 def on_response_complete(response) if need_emit?(response) @input.emit(@request_handler.command, @request_handler.params) end on_write_complete do @repeater.close end end |
#write_back(data) ⇒ Object
249 250 251 252 253 254 255 256 257 258 259 260 261 |
# File 'lib/fluent/plugin/in_groonga.rb', line 249 def write_back(data) begin @response_handler << data rescue $log.error("[input][groonga][response][error] " + "failed to handle HTTP response from Groonga:", :error => "#{$!.class}: #{$!}") $log.error_backtrace reply_error_response("500 Internal Server Error") return end write(data) end |