Kouhei Sutou
null+****@clear*****
Sun Nov 24 22:44:48 JST 2013
Kouhei Sutou 2013-11-24 22:44:48 +0900 (Sun, 24 Nov 2013) New Revision: 5ed372485450258b6c08e60c9f9bbf7c2a2e4779 https://github.com/droonga/fluent-plugin-droonga/commit/5ed372485450258b6c08e60c9f9bbf7c2a2e4779 Message: Add AdapterPlugin Legacy plugin is removed!!! Copied files: lib/droonga/adapter_plugin.rb (from lib/droonga/adapter.rb) Removed files: lib/droonga/legacy_plugin.rb Modified files: lib/droonga/adapter.rb lib/droonga/dispatcher.rb lib/droonga/plugin/adapter/groonga.rb Modified: lib/droonga/adapter.rb (+44 -0) =================================================================== --- lib/droonga/adapter.rb 2013-11-24 22:37:12 +0900 (137ba55) +++ lib/droonga/adapter.rb 2013-11-24 22:44:48 +0900 (6f11ec8) @@ -15,7 +15,51 @@ # 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 Adapter + def initialize(executor, options={}) + @executor = executor + load_plugins(options[:adapters] || []) + end + + def shutdown + $log.trace("#{log_tag}: shutdown: start") + @plugins.each do |plugin| + plugins.shutdown + end + $log.trace("#{log_tag}: shutdown: done") + end + + def processable?(command) + not find_plugin(command).nil? + end + + def process(command, body) + plugin = find_plugin(command) + $log.trace("#{log_tag}: process: start: <#{command}>", + :plugin => plugin.class) + plugin.process(command, body) + $log.trace("#{log_tag}: process: done: <#{command}>", + :plugin => plugin.class) + end + + private + def load_plugins(names) + @plugins = names.collect do |name| + AdapterPlugin.repository.instantiate(name, @executor) + end + end + + def find_plugin(command) + @plugins.find do |plugin| + plugin.processable?(command) + end + end + + def log_tag + "adapter" + end end end Copied: lib/droonga/adapter_plugin.rb (+36 -1) 50% =================================================================== --- lib/droonga/adapter.rb 2013-11-24 22:37:12 +0900 (137ba55) +++ lib/droonga/adapter_plugin.rb 2013-11-24 22:44:48 +0900 (18e5301) @@ -15,7 +15,42 @@ # 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/plugin" + module Droonga - class Adapter + class AdapterPlugin < Plugin + extend PluginRegisterable + + def initialize(executor) + super() + @executor = executor + end + + def add_route(route) + @executor.add_route(route) + end + + def post(body, destination=nil) + @executor.post(body, destination) + 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 process(command, message) + @task = {} + @output_values = {} + super(command, message) + post(@output_values) unless @output_values.empty? + end end end Modified: lib/droonga/dispatcher.rb (+5 -25) =================================================================== --- lib/droonga/dispatcher.rb 2013-11-24 22:37:12 +0900 (11fc611) +++ lib/droonga/dispatcher.rb 2013-11-24 22:44:48 +0900 (70040dc) @@ -16,7 +16,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA require 'tsort' -require "droonga/legacy_plugin" require "droonga/adapter" require "droonga/catalog" require "droonga/collector" @@ -33,28 +32,21 @@ module Droonga @collectors = {} @current_id = 0 @local = Regexp.new("^#{@name}") - Droonga::PluginLoader.load_all - load_legacy_plugins(Droonga.catalog.option("plugins")||[]) + @adapter = Adapter.new(@worker, + :adapters => Droonga.catalog.option("plugins")) end def shutdown - @legacy_plugins.each do |legacy_plugin| - legacy_plugin.shutdown - end + @adapter.shutdown @farm.shutdown end def processable?(command) - not find_legacy_plugin(command).nil? + @adapter.processable?(command) end def process(command, body, *arguments) - legacy_plugin = find_legacy_plugin(command) - $log.trace("#{log_tag}: process: start: <#{command}>", - :plugin => legacy_plugin.class) - legacy_plugin.handle(command, body, *arguments) - $log.trace("#{log_tag}: process: done: <#{command}>", - :plugin => legacy_plugin.class) + @adapter.process(command, body) end def handle(message, arguments) @@ -132,18 +124,6 @@ module Droonga end private - def find_legacy_plugin(command) - @legacy_plugins.find do |plugin| - plugin.handlable?(command) - end - end - - def load_legacy_plugins(names) - @legacy_plugins = names.collect do |name| - LegacyPlugin.repository.instantiate(name, @worker) - end - end - def log_tag "[#{Process.ppid}][#{Process.pid}] dispatcher" end Deleted: lib/droonga/legacy_plugin.rb (+0 -146) 100644 =================================================================== --- lib/droonga/legacy_plugin.rb 2013-11-24 22:37:12 +0900 (99abe42) +++ /dev/null @@ -1,146 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2013 Droonga Project -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License version 2.1 as published by the Free Software Foundation. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# 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/handler_plugin" -require "droonga/command_mapper" -require "droonga/logger" - -module Droonga - class LegacyPlugin - @@repository = PluginRepository.new - - class << self - def inherited(sub_class) - super - sub_class.instance_variable_set(:@command_mapper, CommandMapper.new) - end - - def command(name_or_map) - @command_mapper.register(name_or_map) - end - - def method_name(command) - @command_mapper[command] - end - - def handlable?(command) - not method_name(command).nil? - end - - def repository - @@repository - end - end - - def initialize(worker) - @worker = worker - @context =****@worke***** - end - - def post(body, destination=nil) - @worker.post(body, destination) - end - - def envelope - @worker.envelope - end - - def add_route(route) - @worker.add_route(route) - end - - def shutdown - end - - def handlable?(command) - self.class.handlable?(command) - end - - def invoke(command, request, *arguments) - __send__(self.class.method_name(command), request, *arguments) - rescue => exception - Logger.error("error while handling #{command}", - request: request, - arguments: arguments, - 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"=>"dispatcher") - end - end - end - end - end -end Modified: lib/droonga/plugin/adapter/groonga.rb (+4 -6) =================================================================== --- lib/droonga/plugin/adapter/groonga.rb 2013-11-24 22:37:12 +0900 (ef96ac1) +++ lib/droonga/plugin/adapter/groonga.rb 2013-11-24 22:44:48 +0900 (da7761a) @@ -13,14 +13,12 @@ # 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 "groonga" - -require "droonga/legacy_plugin" +require "droonga/adapter_plugin" module Droonga - class GroongaAdapter < Droonga::LegacyPlugin - # TODO: AdapterPlugin or something should be defined to avoid conflicts. - Droonga::LegacyPlugin.repository.register("select", self) + class GroongaAdapter < Droonga::AdapterPlugin + repository.register("select", self) + command :select def select(select_request) command = Select.new -------------- next part -------------- HTML����������������������������... Download