Kouhei Sutou
null+****@clear*****
Mon Nov 25 13:34:05 JST 2013
Kouhei Sutou 2013-11-25 13:34:05 +0900 (Mon, 25 Nov 2013) New Revision: 984b42c17476ffb9faf6c595c27f7d89d23ed6be https://github.com/droonga/fluent-plugin-droonga/commit/984b42c17476ffb9faf6c595c27f7d89d23ed6be Message: Introduce InputMessage that represents input message Here is a work flow: * Dispatcher recives envelope * Dispatcher wraps envelope by InputMessage * Adapter processes envelope via InputMessage * Dispatcher passes processed envelope to distributor * Distributor distribute processed envelope Copied files: lib/droonga/input_message.rb (from lib/droonga/plugin/adapter/groonga.rb) Modified files: lib/droonga/dispatcher.rb lib/droonga/plugin/adapter/groonga.rb Modified: lib/droonga/dispatcher.rb (+22 -8) =================================================================== --- lib/droonga/dispatcher.rb 2013-11-25 13:07:20 +0900 (1dea0f7) +++ lib/droonga/dispatcher.rb 2013-11-25 13:34:05 +0900 (0e7280e) @@ -21,6 +21,7 @@ require "droonga/distributor" require "droonga/catalog" require "droonga/collector" require "droonga/farm" +require "droonga/input_message" module Droonga class Dispatcher @@ -50,16 +51,13 @@ module Droonga @farm.shutdown end - def add_route(route) - envelope["via"].push(route) - end - def handle_envelope(envelope) @envelope = envelope - post(envelope["body"], - "type" => envelope["type"], - "arguments" => envelope["arguments"], - "synchronous" => envelope["synchronous"]) + if envelope["type"] == "dispatcher" + handle(envelope["body"], envelope["arguments"]) + else + process_input_message(envelope) + end end def post(body, destination=nil) @@ -179,6 +177,22 @@ module Droonga route.is_a?(String) || route.is_a?(Hash) end + def apply_adapters(envelope) + input_message = InputMessage.new(envelope) + loop do + command = input_message.command + break unles****@adapt*****?(command) + @adapter.process(command, input_message) + new_command = input_message.command + break if command == new_command + end + end + + def process_input_message(envelope) + apply_adapters(envelope) + @distributor.distribute(envelope) + end + def log_tag "[#{Process.ppid}][#{Process.pid}] dispatcher" end Copied: lib/droonga/input_message.rb (+22 -16) 58% =================================================================== --- lib/droonga/plugin/adapter/groonga.rb 2013-11-25 13:07:20 +0900 (da7761a) +++ lib/droonga/input_message.rb 2013-11-25 13:34:05 +0900 (ae79b21) @@ -1,3 +1,5 @@ +# -*- coding: utf-8 -*- +# # Copyright (C) 2013 Droonga Project # # This library is free software; you can redistribute it and/or @@ -13,26 +15,30 @@ # 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/adapter_plugin" - module Droonga - class GroongaAdapter < Droonga::AdapterPlugin - repository.register("select", self) + class InputMessage + def initialize(envelope) + @envelope = envelope + end + + def add_route(route) + @envelope["via"].push(route) + end - command :select - def select(select_request) - command = Select.new - search_request = command.convert_request(select_request) - add_route("select_response") - post(search_request, "search") + def body + @envelope["body"] end - command :select_response - def select_response(search_response) - command = Select.new - emit(command.convert_response(search_response)) + def body=(body) + @envelope["body"] = body + end + + def command + @envelope["type"] + end + + def command=(command) + @envelope["type"] = command end end end - -require "droonga/plugin/adapter/groonga/select" Modified: lib/droonga/plugin/adapter/groonga.rb (+5 -3) =================================================================== --- lib/droonga/plugin/adapter/groonga.rb 2013-11-25 13:07:20 +0900 (da7761a) +++ lib/droonga/plugin/adapter/groonga.rb 2013-11-25 13:34:05 +0900 (8ac7708) @@ -20,11 +20,13 @@ module Droonga repository.register("select", self) command :select - def select(select_request) + def select(input_message) command = Select.new + select_request = input_message.body search_request = command.convert_request(select_request) - add_route("select_response") - post(search_request, "search") + input_message.add_route("select_response") + input_message.command = "search" + input_message.body = search_request end command :select_response -------------- next part -------------- HTML����������������������������...Download