Kouhei Sutou
null+****@clear*****
Mon Nov 25 17:47:06 JST 2013
Kouhei Sutou 2013-11-25 17:47:06 +0900 (Mon, 25 Nov 2013) New Revision: d29ee5593264701fe1e3a276dd80eaf3978c8406 https://github.com/droonga/fluent-plugin-droonga/commit/d29ee5593264701fe1e3a276dd80eaf3978c8406 Message: Use non-destructive API for applying input adapters The API seems that it doesn't change destructively but it changes destructively for now. See added comment about TODO. Modified files: lib/droonga/dispatcher.rb lib/droonga/input_message.rb Modified: lib/droonga/dispatcher.rb (+7 -4) =================================================================== --- lib/droonga/dispatcher.rb 2013-11-25 17:26:37 +0900 (c5bbb3a) +++ lib/droonga/dispatcher.rb 2013-11-25 17:47:06 +0900 (a8821f6) @@ -181,20 +181,23 @@ module Droonga route.is_a?(String) || route.is_a?(Hash) end - def apply_adapters(envelope) - input_message = InputMessage.new(envelope) + def apply_input_adapters(envelope) + adapted_envelope = envelope loop do + input_message = InputMessage.new(adapted_envelope) command = input_message.command break unles****@adapt*****?(command) @adapter.process(command, input_message) new_command = input_message.command + adapted_envelope = input_message.adapted_envelope break if command == new_command end + adapted_envelope end def process_input_message(envelope) - apply_adapters(envelope) - @distributor.distribute(envelope) + adapted_envelope = apply_input_adapters(envelope) + @distributor.distribute(adapted_envelope) end def log_tag Modified: lib/droonga/input_message.rb (+7 -0) =================================================================== --- lib/droonga/input_message.rb 2013-11-25 17:26:37 +0900 (ae79b21) +++ lib/droonga/input_message.rb 2013-11-25 17:47:06 +0900 (cd6acfc) @@ -21,6 +21,13 @@ module Droonga @envelope = envelope end + def adapted_envelope + # TODO: We can create adapted envelope non-destructively. + # If it is not performance issue, it is better that we don't + # change envelope destructively. Consider about it later. + @envelope + end + def add_route(route) @envelope["via"].push(route) end -------------- next part -------------- HTML����������������������������...Download