[Groonga-commit] droonga/fluent-plugin-droonga at bc26748 [master] Extract common plugin code

Back to archive index

Kouhei Sutou null+****@clear*****
Sun Nov 24 18:36:34 JST 2013


Kouhei Sutou	2013-11-24 18:36:34 +0900 (Sun, 24 Nov 2013)

  New Revision: bc26748ecb7ea834851e5e5471744de0055230fb
  https://github.com/droonga/fluent-plugin-droonga/commit/bc26748ecb7ea834851e5e5471744de0055230fb

  Message:
    Extract common plugin code

  Copied files:
    lib/droonga/plugin.rb
      (from lib/droonga/handler_plugin.rb)
  Modified files:
    lib/droonga/distributor_plugin.rb
    lib/droonga/handler.rb
    lib/droonga/handler_plugin.rb
    lib/droonga/processor.rb

  Modified: lib/droonga/distributor_plugin.rb (+4 -15)
===================================================================
--- lib/droonga/distributor_plugin.rb    2013-11-24 18:26:20 +0900 (db67cbc)
+++ lib/droonga/distributor_plugin.rb    2013-11-24 18:36:34 +0900 (66e44c5)
@@ -15,13 +15,14 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-require "droonga/plugin_registerable"
+require "droonga/plugin"
 
 module Droonga
-  class DistributorPlugin
+  class DistributorPlugin < Plugin
     extend PluginRegisterable
 
     def initialize(distributor)
+      super()
       @distributor = distributor
     end
 
@@ -30,21 +31,9 @@ module Droonga
       @distributor.post(message)
     end
 
-    def shutdown
-    end
-
-    def processable?(command)
-      self.class.processable?(command)
-    end
-
     def process(envelope, *arguments)
       command = envelope["type"]
-      __send__(self.class.method_name(command), envelope, *arguments)
-    rescue => exception
-      Logger.error("error while processing #{command}",
-                   envelope: envelope,
-                   arguments: arguments,
-                   exception: exception)
+      super(command, envelope, *arguments)
     end
 
     def scatter_all(envelope, key)

  Modified: lib/droonga/handler.rb (+16 -16)
===================================================================
--- lib/droonga/handler.rb    2013-11-24 18:26:20 +0900 (9ad8c26)
+++ lib/droonga/handler.rb    2013-11-24 18:36:34 +0900 (b7315fe)
@@ -72,11 +72,11 @@ module Droonga
         $log.trace("#{log_tag}: execute_one: abort: no message")
         return
       end
-      handle(message)
+      process(message)
       $log.trace("#{log_tag}: execute_one: done")
     end
 
-    def handlable?(command)
+    def processable?(command)
       not find_plugin(command).nil?
     end
 
@@ -84,30 +84,30 @@ module Droonga
       find_plugin(command).prefer_synchronous?(command)
     end
 
-    def handle(message)
-      $log.trace("#{log_tag}: handle: start")
+    def process(message)
+      $log.trace("#{log_tag}: process: start")
       body, command, arguments = parse_message(message)
       plugin = find_plugin(command)
       if plugin.nil?
-        $log.trace("#{log_tag}: handle: done: no plugin: <#{command}>")
+        $log.trace("#{log_tag}: process: done: no plugin: <#{command}>")
         return
       end
 
       unless try_handle_as_internal_message(plugin, command, body, arguments)
         @task = {}
         @output_values = {}
-        $log.trace("#{log_tag}: handle: plugin: handle: start",
+        $log.trace("#{log_tag}: process: plugin: process: start",
                    :hander => plugin.class)
-        plugin.handle(command, body, *arguments)
-        $log.trace("#{log_tag}: handle: plugin: handle: done",
+        plugin.process(command, body, *arguments)
+        $log.trace("#{log_tag}: process: plugin: process: done",
                    :hander => plugin.class)
         unless @output_values.empty?
-          $log.trace("#{log_tag}: handle: output: start")
+          $log.trace("#{log_tag}: process: output: start")
           post(@output_values)
-          $log.trace("#{log_tag}: handle: output: done")
+          $log.trace("#{log_tag}: process: output: done")
         end
       end
-      $log.trace("#{log_tag}: handle: done: <#{command}>",
+      $log.trace("#{log_tag}: process: done: <#{command}>",
                  :plugin => plugin.class)
     end
 
@@ -161,9 +161,9 @@ module Droonga
             synchronous = plugin.prefer_synchronous?(command)
           end
           if route || @pool_size.zero? || synchronous
-            $log.trace("#{log_tag}: post_or_push: handle: start")
-            plugin.handle(command, body, *arguments)
-            $log.trace("#{log_tag}: post_or_push: handle: done")
+            $log.trace("#{log_tag}: post_or_push: process: start")
+            plugin.process(command, body, *arguments)
+            $log.trace("#{log_tag}: post_or_push: process: done")
           else
             unless message
               envelope["body"] = body
@@ -263,7 +263,7 @@ module Droonga
 
     def find_plugin(command)
       @plugins.find do |plugin|
-        plugin.handlable?(command)
+        plugin.processable?(command)
       end
     end
 
@@ -312,7 +312,7 @@ module Droonga
       @input_name = request["name"]
       @descendants = request["descendants"]
 
-      plugin.handle(command, @body, *arguments)
+      plugin.process(command, @body, *arguments)
       output_xxx if @descendants
       true
     end

  Modified: lib/droonga/handler_plugin.rb (+3 -18)
===================================================================
--- lib/droonga/handler_plugin.rb    2013-11-24 18:26:20 +0900 (072461b)
+++ lib/droonga/handler_plugin.rb    2013-11-24 18:36:34 +0900 (91bdfd8)
@@ -15,13 +15,14 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-require "droonga/plugin_registerable"
+require "droonga/plugin"
 
 module Droonga
-  class HandlerPlugin
+  class HandlerPlugin < Plugin
     extend PluginRegisterable
 
     def initialize(handler)
+      super()
       @handler = handler
       @context =****@handl*****
     end
@@ -30,22 +31,6 @@ module Droonga
       @handler.envelope
     end
 
-    def shutdown
-    end
-
-    def handlable?(command)
-      self.class.processable?(command)
-    end
-
-    def handle(command, request, *arguments)
-      __send__(self.class.method_name(command), request, *arguments)
-    rescue => exception
-      Logger.error("error while handling #{command}",
-                   request: request,
-                   arguments: arguments,
-                   exception: exception)
-    end
-
     def emit(value, name=nil)
       @handler.emit(value, name)
     end

  Copied: lib/droonga/plugin.rb (+7 -25) 61%
===================================================================
--- lib/droonga/handler_plugin.rb    2013-11-24 18:26:20 +0900 (072461b)
+++ lib/droonga/plugin.rb    2013-11-24 18:36:34 +0900 (8c07145)
@@ -18,44 +18,26 @@
 require "droonga/plugin_registerable"
 
 module Droonga
-  class HandlerPlugin
-    extend PluginRegisterable
-
-    def initialize(handler)
-      @handler = handler
-      @context =****@handl*****
+  class Plugin
+    def initialize
     end
 
-    def envelope
-      @handler.envelope
+    def start
     end
 
     def shutdown
     end
 
-    def handlable?(command)
+    def processable?(command)
       self.class.processable?(command)
     end
 
-    def handle(command, request, *arguments)
-      __send__(self.class.method_name(command), request, *arguments)
+    def process(command, *arguments)
+      __send__(self.class.method_name(command), *arguments)
     rescue => exception
-      Logger.error("error while handling #{command}",
-                   request: request,
+      Logger.error("error while processing #{command}",
                    arguments: arguments,
                    exception: exception)
     end
-
-    def emit(value, name=nil)
-      @handler.emit(value, name)
-    end
-
-    def post(body, destination=nil)
-      @handler.post(body, destination)
-    end
-
-    def prefer_synchronous?(command)
-      false
-    end
   end
 end

  Modified: lib/droonga/processor.rb (+2 -2)
===================================================================
--- lib/droonga/processor.rb    2013-11-24 18:26:20 +0900 (01275e5)
+++ lib/droonga/processor.rb    2013-11-24 18:36:34 +0900 (207d9d9)
@@ -45,14 +45,14 @@ module Droonga
       $log.trace("proessor: process: start")
       reply_to = envelope["replyTo"]
       command = envelope["type"]
-      if****@handl*****?(command)
+      if****@handl*****?(command)
         $log.trace("proessor: process: handlable: #{command}")
         if synchronous.nil?
           synchronous =****@handl*****_synchronous?(command)
         end
         message = ["", Time.now.to_f, envelope]
         if @n_workers.zero? or synchronous
-          @handler.handle(message)
+          @handler.process(message)
         else
           @job_queue.push_message(message)
         end
-------------- next part --------------
HTML����������������������������...
Download 



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