Kouhei Sutou
null+****@clear*****
Fri Dec 20 16:59:29 JST 2013
Kouhei Sutou 2013-12-20 16:59:29 +0900 (Fri, 20 Dec 2013) New Revision: d7d8696376b3e4ddfbfd28e75807524d1c44415d https://github.com/droonga/fluent-plugin-droonga/commit/d7d8696376b3e4ddfbfd28e75807524d1c44415d Message: output adapter: change output message instead of emitting body It breaks API compatibility. Copied files: lib/droonga/output_message.rb (from lib/droonga/plugin/output_adapter/groonga.rb) Modified files: lib/droonga/dispatcher.rb lib/droonga/output_adapter.rb lib/droonga/output_adapter_plugin.rb lib/droonga/plugin/output_adapter/groonga.rb Modified: lib/droonga/dispatcher.rb (+11 -9) =================================================================== --- lib/droonga/dispatcher.rb 2013-12-20 16:47:42 +0900 (3ebad45) +++ lib/droonga/dispatcher.rb 2013-12-20 16:59:29 +0900 (bc50c45) @@ -93,10 +93,10 @@ module Droonga synchronous = destination["synchronous"] end if receiver - @forwarder.forward(envelope.merge("body" => body), - "type" => command, - "to" => receiver, - "arguments" => arguments) + forward(envelope.merge("body" => body), + "type" => command, + "to" => receiver, + "arguments" => arguments) else if command == "dispatcher" handle(body, arguments) @@ -107,12 +107,14 @@ module Droonga $log.trace("#{log_tag}: post: done") end + def forward(message, destination) + @forwarder.forward(message, destination) + end + def reply(body) - @output_adapter.adapt(body) - if @envelope["via"].empty? - @forwarder.forward(@envelope.merge("body" => body), - @envelope["replyTo"]) - end + adapted_message = @output_adapter.adapt(@envelope.merge("body" => body)) + @forwarder.forward(adapted_message, + adapted_message["replyTo"]) end def handle_internal_message(message) Modified: lib/droonga/output_adapter.rb (+7 -2) =================================================================== --- lib/droonga/output_adapter.rb 2013-12-20 16:47:42 +0900 (6882b41) +++ lib/droonga/output_adapter.rb 2013-12-20 16:59:29 +0900 (0b79df0) @@ -17,6 +17,7 @@ require "droonga/pluggable" require "droonga/output_adapter_plugin" +require "droonga/output_message" module Droonga class OutputAdapter @@ -27,13 +28,17 @@ module Droonga load_plugins(options[:plugins] || []) end - def adapt(body) + def adapt(message) + adapted_message = message @dispatcher.envelope["via"].reverse_each do |command| @plugins.each do |plugin| next unless plugin.processable?(command) - process(command, body) + output_message = OutputMessage.new(adapted_message) + process(command, output_message) + adapted_message = output_message.adapted_message end end + adapted_message end private Modified: lib/droonga/output_adapter_plugin.rb (+2 -16) =================================================================== --- lib/droonga/output_adapter_plugin.rb 2013-12-20 16:47:42 +0900 (da0db5c) +++ lib/droonga/output_adapter_plugin.rb 2013-12-20 16:59:29 +0900 (28ac627) @@ -26,22 +26,8 @@ module Droonga @dispatcher = dispatcher end - def post(body, destination=nil) - @dispatcher.post(body, destination) - end - - def emit(value, name=nil) - if name - @output_values[name] = value - else - @output_values = value - end - end - - def process(command, message) - @output_values = {} - super(command, message) - post(@output_values) unless @output_values.empty? + def forward(message, destination) + @dispatcher.forward(message, destination) end end end Copied: lib/droonga/output_message.rb (+17 -10) 62% =================================================================== --- lib/droonga/plugin/output_adapter/groonga.rb 2013-12-20 16:47:42 +0900 (95d14fb) +++ lib/droonga/output_message.rb 2013-12-20 16:59:29 +0900 (12dd516) @@ -13,18 +13,25 @@ # 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/output_adapter_plugin" - module Droonga - class GroongaOutputAdapter < Droonga::OutputAdapterPlugin - repository.register("groonga", self) + class OutputMessage + def initialize(raw_message) + @raw_message = raw_message + end + + def adapted_message + # TODO: We can create adapted message non-destructively. + # If it is not performance issue, it is better that we don't + # change message destructively. Consider about it later. + @raw_message + end - command :select_response - def select_response(search_response) - command = Select.new - emit(command.convert(search_response)) + def body + @raw_message["body"] + end + + def body=(body) + @raw_message["body"] = body end end end - -require "droonga/plugin/output_adapter/groonga/select" Modified: lib/droonga/plugin/output_adapter/groonga.rb (+2 -2) =================================================================== --- lib/droonga/plugin/output_adapter/groonga.rb 2013-12-20 16:47:42 +0900 (95d14fb) +++ lib/droonga/plugin/output_adapter/groonga.rb 2013-12-20 16:59:29 +0900 (3354780) @@ -20,9 +20,9 @@ module Droonga repository.register("groonga", self) command :select_response - def select_response(search_response) + def select_response(output_message) command = Select.new - emit(command.convert(search_response)) + output_message.body = command.convert(output_message.body) end end end -------------- next part -------------- HTML����������������������������...下載