Class: Fluent::Plugin::GroongaInput::HTTPInput::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/in_groonga.rb

Instance Method Summary collapse

Constructor Details

#initialize(input, connection, repeater) ⇒ Handler

Returns a new instance of Handler.



202
203
204
205
206
207
208
# File 'lib/fluent/plugin/in_groonga.rb', line 202

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

#closeObject



252
253
254
# File 'lib/fluent/plugin/in_groonga.rb', line 252

def close
  @connection.close
end

#on_read(data) ⇒ Object



210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/fluent/plugin/in_groonga.rb', line 210

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



242
243
244
245
246
247
248
249
250
# File 'lib/fluent/plugin/in_groonga.rb', line 242

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



228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'lib/fluent/plugin/in_groonga.rb', line 228

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