[Groonga-commit] groonga/fluent-plugin-droonga:738d815 [master] Make handlers to be initialized with a worker

Back to archive index

Daijiro MORI null+****@clear*****
Wed Apr 17 21:23:36 JST 2013


Daijiro MORI	2013-04-17 21:23:36 +0900 (Wed, 17 Apr 2013)

  New Revision: 738d815a55e08a264be7605f3986ac0915a7d894
  https://github.com/groonga/fluent-plugin-droonga/commit/738d815a55e08a264be7605f3986ac0915a7d894

  Message:
    Make handlers to be initialized with a worker

  Modified files:
    lib/droonga/handler.rb
    lib/droonga/worker.rb
    test/plugin/test_handler_search.rb
    test/test_handler.rb

  Modified: lib/droonga/handler.rb (+3 -2)
===================================================================
--- lib/droonga/handler.rb    2013-04-17 20:06:20 +0900 (046bdc5)
+++ lib/droonga/handler.rb    2013-04-17 21:23:36 +0900 (76edd59)
@@ -47,8 +47,9 @@ module Droonga
       end
     end
 
-    def initialize(context)
-      @context = context
+    def initialize(worker)
+      @worker = worker
+      @context =****@worke*****
     end
 
     def shutdown

  Modified: lib/droonga/worker.rb (+7 -4)
===================================================================
--- lib/droonga/worker.rb    2013-04-17 20:06:20 +0900 (a873ee9)
+++ lib/droonga/worker.rb    2013-04-17 21:23:36 +0900 (2b655da)
@@ -25,6 +25,8 @@ require "droonga/plugin"
 
 module Droonga
   class Worker
+    attr_reader :context, :envelope
+
     def initialize(options={})
       @pool = []
       @handlers = []
@@ -65,15 +67,16 @@ module Droonga
 
     def add_handler(name)
       plugin = HandlerPlugin.new(name)
-      @handlers << plugin.instantiate(@context)
+      @handlers << plugin.instantiate(self)
     end
 
     def process_message(envelope)
+      @envelope = envelope
       command = envelope["type"]
       handler = find_handler(command)
       return unless handler
       result = handler.handle(command, envelope["body"])
-      output = get_output(envelope)
+      output = get_output
       if output
         response = {
           inReplyTo: envelope["id"],
@@ -158,8 +161,8 @@ module Droonga
       end
     end
 
-    def get_output(event)
-      receiver = event["replyTo"]
+    def get_output
+      receiver = @envelope["replyTo"]
       return nil unless receiver
       unless receiver =~ /\A(.*):(\d+)\/(.*?)(\?.+)?\z/
         raise "format: hostname:port/tag(?params)"

  Modified: test/plugin/test_handler_search.rb (+9 -1)
===================================================================
--- test/plugin/test_handler_search.rb    2013-04-17 20:06:20 +0900 (e38b5b3)
+++ test/plugin/test_handler_search.rb    2013-04-17 21:23:36 +0900 (6e9d89c)
@@ -15,6 +15,14 @@
 
 require "droonga/plugin/handler_search"
 
+class Worker
+  attr_reader :context
+
+  def initialize()
+    @context = Groonga::Context.default
+  end
+end
+
 class SearchHandlerTest < Test::Unit::TestCase
   def setup
     setup_database
@@ -38,7 +46,7 @@ class SearchHandlerTest < Test::Unit::TestCase
   end
 
   def setup_handler
-    @handler = Droonga::SearchHandler.new(Groonga::Context.default)
+    @handler = Droonga::SearchHandler.new(Worker.new)
   end
 
   def teardown_handler

  Modified: test/test_handler.rb (+7 -1)
===================================================================
--- test/test_handler.rb    2013-04-17 20:06:20 +0900 (bd51cbd)
+++ test/test_handler.rb    2013-04-17 21:23:36 +0900 (631958a)
@@ -31,8 +31,14 @@ class HandlerTest < Test::Unit::TestCase
       end
     end
 
+    class Worker
+      def context
+        nil
+      end
+    end
+
     def setup
-      context = Object.new
+      context = Worker.new
       @search_handler = SearchHandler.new(context)
     end
 
-------------- next part --------------
HTML����������������������������...
Download 



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