Daijiro MORI
null+****@clear*****
Fri Aug 16 22:13:28 JST 2013
Daijiro MORI 2013-08-16 22:13:28 +0900 (Fri, 16 Aug 2013) New Revision: 144fe76d72bfb82480c278d5dbbcc90d39990c23 https://github.com/droonga/fluent-plugin-droonga/commit/144fe76d72bfb82480c278d5dbbcc90d39990c23 Message: Add ProxyMessageHandler class. Modified files: lib/droonga/plugin/handler_proxy.rb lib/droonga/proxy.rb lib/droonga/worker.rb Modified: lib/droonga/plugin/handler_proxy.rb (+22 -10) =================================================================== --- lib/droonga/plugin/handler_proxy.rb 2013-08-15 23:48:20 +0900 (77a327a) +++ lib/droonga/plugin/handler_proxy.rb 2013-08-16 22:13:28 +0900 (cbf6f24) @@ -16,25 +16,37 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require "droonga/handler" -require "droonga/proxy" module Droonga class ProxyHandler < Droonga::Handler Droonga::HandlerPlugin.register("proxy", self) - def initialize(*arguments) - super - @proxy = Droonga::Proxy.new(@worker, @worker.name) + command :proxy_search + def proxy_search(request, *arguments) + task = request["task"] + task["value"] = "dummy" end - command :proxy - - def proxy(request, *arguments) - @proxy.handle(request, arguments) + command :proxy_gather + def proxy_gather(request, *arguments) + task = request["task"] + name = request["name"] + value = request["value"] + component = task["component"] + task["value"] ||= {} + task["value"][name] ||= [] + task["value"][name] << value end - def prefer_synchronous?(command) - return true + command :proxy_reduce + def proxy_reduce(request, *arguments) + task = request["task"] + name = request["name"] + value = request["value"] + component = task["component"] + task["value"] ||= {} + task["value"][name] ||= [] + task["value"][name] << value end end end Modified: lib/droonga/proxy.rb (+21 -11) =================================================================== --- lib/droonga/proxy.rb 2013-08-15 23:48:20 +0900 (99e102e) +++ lib/droonga/proxy.rb 2013-08-16 22:13:28 +0900 (3851ea5) @@ -16,6 +16,7 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require 'tsort' +require "droonga/handler" module Droonga class Proxy @@ -235,10 +236,10 @@ module Droonga def handle(name, value) tasks = @inputs[name] tasks.each do |task| + task["n_of_inputs"] += 1 if name component = task["component"] type = component["type"] - args = component["args"] - command = component["command"] + command = component["command"] || ("proxy_" + type) if command message = { "task"=>task, @@ -247,19 +248,12 @@ module Droonga } #todo: add_route and n_of_expects++ if it would run asynchronously @proxy.post(message, command) - else - task["value"] ||= {} - task["value"][name] ||= [] - task["value"][name] << value end - task["n_of_inputs"] += 1 if name return if task["n_of_inputs"] < component["n_of_expects"] #the task is done result = task["value"] - case type - when "send" - @proxy.post(result, args) - end + post = component["post"] + @proxy.post(result, post) if post component["descendants"].each do |name, indices| message = { "id" => @id, @@ -280,4 +274,20 @@ module Droonga end end end + class ProxyMessageHandler < Droonga::Handler + Droonga::HandlerPlugin.register("proxy_message", self) + def initialize(*arguments) + super + @proxy = Droonga::Proxy.new(@worker, @worker.name) + end + + command :proxy + def proxy(request, *arguments) + @proxy.handle(request, arguments) + end + + def prefer_synchronous?(command) + return true + end + end end Modified: lib/droonga/worker.rb (+3 -1) =================================================================== --- lib/droonga/worker.rb 2013-08-15 23:48:20 +0900 (3020f62) +++ lib/droonga/worker.rb 2013-08-16 22:13:28 +0900 (2f04d6f) @@ -23,6 +23,7 @@ require "droonga/job_queue" require "droonga/handler_plugin" require "droonga/plugin" require "droonga/catalog" +require "droonga/proxy" module Droonga class Worker @@ -36,7 +37,7 @@ module Droonga @database_name = options[:database] || "droonga/db" @queue_name = options[:queue_name] || "DroongaQueue" Droonga::JobQueue.ensure_schema(@database_name, @queue_name) - @handler_names = options[:handlers] || ["search"] + @handler_names = options[:handlers] || ["proxy"] load_handlers @pool_size = options[:pool_size] || 1 @pool = spawn @@ -254,6 +255,7 @@ module Droonga @handler_names.each do |handler_name| add_handler(handler_name) end + add_handler("proxy_message") end def find_handler(command) -------------- next part -------------- HTML����������������������������... Télécharger