Daijiro MORI
null+****@clear*****
Wed Sep 4 21:12:11 JST 2013
Daijiro MORI 2013-09-04 21:12:11 +0900 (Wed, 04 Sep 2013) New Revision: 13c4e69af21c686f884219d55354ead522628e8f https://github.com/droonga/fluent-plugin-droonga/commit/13c4e69af21c686f884219d55354ead522628e8f Message: Enable handlers to handle internal messages. Modified files: lib/droonga/handler.rb lib/droonga/plugin/handler_search.rb lib/droonga/proxy.rb Modified: lib/droonga/handler.rb (+57 -1) =================================================================== --- lib/droonga/handler.rb 2013-09-04 19:46:11 +0900 (750dec8) +++ lib/droonga/handler.rb 2013-09-04 21:12:11 +0900 (1df4a10) @@ -64,7 +64,7 @@ module Droonga self.class.handlable?(command) end - def handle(command, request, *arguments) + def invoke(command, request, *arguments) __send__(self.class.method_name(command), request, *arguments) rescue => exception Logger.error("error while handling #{command}", @@ -73,8 +73,64 @@ module Droonga exception: exception) end + def handle(command, request, *arguments) + unless try_handle_as_internal_message(command, request, arguments) + @task = {} + @output_values = {} + invoke(command, request, *arguments) + post(@output_values) unless @output_values.empty? + end + end + def prefer_synchronous?(command) return false end + + def emit(value, name = nil) + unless name + if @output_names + name = @output_names.first + else + @output_values = @task["values"] = value + return + end + end + @output_values[name] = value + end + + def try_handle_as_internal_message(command, request, arguments) + return false unless request.is_a? Hash + @task = request["task"] + return false unles****@task*****_a? Hash + @component = @task["component"] + return false unles****@compo*****_a? Hash + @output_values = @task["values"] + @body = @component["body"] + @output_names = @component["outputs"] + @id = request["id"] + @value = request["value"] + @input_name = request["name"] + @descendants = request["descendants"] + invoke(command, @body, *arguments) + output if @descendants + true + end + + def output + result = @task["values"] + post(result, @component["post"]) if @component["post"] + @descendants.each do |name, dests| + message = { + "id" => @id, + "input" => name, + "value" => result[name] + } + dests.each do |routes| + routes.each do |route| + post(message, "to"=>route, "type"=>"proxy") + end + end + end + end end end Modified: lib/droonga/plugin/handler_search.rb (+3 -2) =================================================================== --- lib/droonga/plugin/handler_search.rb 2013-09-04 19:46:11 +0900 (1b773d0) +++ lib/droonga/plugin/handler_search.rb 2013-09-04 21:12:11 +0900 (912b44b) @@ -25,8 +25,9 @@ module Droonga command :search def search(request) searcher = Droonga::Searcher.new(@context) - outputs = searcher.search(request["queries"]) - post(outputs) + searcher.search(request["queries"]).each do |output, value| + emit(value, output) + end end end end Modified: lib/droonga/proxy.rb (+1 -1) =================================================================== --- lib/droonga/proxy.rb 2013-09-04 19:46:11 +0900 (1dcd21d) +++ lib/droonga/proxy.rb 2013-09-04 21:12:11 +0900 (5c67f4f) @@ -345,7 +345,7 @@ module Droonga @output_values = @task["values"] @descendants = request["descendants"] @id = request["id"] - super(command, request["value"], *arguments) + invoke(command, request["value"], *arguments) output if @descendants end -------------- next part -------------- HTML����������������������������...Download