[Groonga-commit] groonga/fluent-plugin-groonga [master] in: support GQTP input

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Nov 25 22:57:43 JST 2012


Kouhei Sutou	2012-11-25 22:57:43 +0900 (Sun, 25 Nov 2012)

  New Revision: 07a60a36724e7973ea0703e45e4f0a32da3b9d3e
  https://github.com/groonga/fluent-plugin-groonga/commit/07a60a36724e7973ea0703e45e4f0a32da3b9d3e

  Log:
    in: support GQTP input

  Modified files:
    fluent-plugin-groonga.gemspec
    lib/fluent/plugin/in_groonga.rb

  Modified: fluent-plugin-groonga.gemspec (+3 -0)
===================================================================
--- fluent-plugin-groonga.gemspec    2012-11-25 22:56:57 +0900 (21d6cc0)
+++ fluent-plugin-groonga.gemspec    2012-11-25 22:57:43 +0900 (ca4c316)
@@ -31,6 +31,9 @@ Gem::Specification.new do |spec|
   spec.require_paths = ["lib"]
 
   spec.add_runtime_dependency("fluentd")
+  spec.add_runtime_dependency("gqtp")
+  spec.add_runtime_dependency("groonga-command")
+
   spec.add_development_dependency("rake")
   spec.add_development_dependency("bundler")
   spec.add_development_dependency("test-unit")

  Modified: lib/fluent/plugin/in_groonga.rb (+51 -0)
===================================================================
--- lib/fluent/plugin/in_groonga.rb    2012-11-25 22:56:57 +0900 (8a6e953)
+++ lib/fluent/plugin/in_groonga.rb    2012-11-25 22:57:43 +0900 (52a928c)
@@ -20,6 +20,9 @@ require "webrick/httputils"
 
 require "http_parser"
 
+require "gqtp"
+require "groonga/command"
+
 module Fluent
   class GroongaInput < Input
     Plugin.register_input("groonga", self)
@@ -198,5 +201,53 @@ module Fluent
         end
       end
     end
+
+    class GQTPInput < BaseInput
+      private
+      def handler_class
+        Handler
+      end
+
+      class Handler < Coolio::Socket
+        def initialize(socket, input)
+          super(socket)
+          @input = input
+        end
+
+        def on_connect
+          @parser = Parser.new(@input)
+          @repeater =****@input*****_repeater(self)
+        end
+
+        def on_read(data)
+          @parser << data
+          @repeater.write(data)
+        end
+      end
+
+      class Parser < GQTP::Parser
+        def initialize(input)
+          super()
+          @input = input
+        end
+
+        def on_body(chunk)
+          @body << chunk
+        end
+
+        def on_complete
+          command_line, body =****@body*****(/\n/, 2)
+          return if command_line.nil?
+          command = Groonga::Command::Parser.parse(command_line.strip)
+          @input.emit(command.name, command.arguments, body)
+        end
+
+        private
+        def reset
+          super
+          @body = ""
+        end
+      end
+    end
   end
 end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index