YUKI Hiroshi
null+****@clear*****
Thu Feb 20 15:33:22 JST 2014
YUKI Hiroshi 2014-02-20 15:33:22 +0900 (Thu, 20 Feb 2014) New Revision: cc08502d05743b107654ff7feb800e943d2ca7d1 https://github.com/droonga/fluent-plugin-droonga/commit/cc08502d05743b107654ff7feb800e943d2ca7d1 Message: Detect conflicting handlers for a same command type Modified files: lib/droonga/handler_runner.rb Modified: lib/droonga/handler_runner.rb (+24 -0) =================================================================== --- lib/droonga/handler_runner.rb 2014-02-19 16:46:27 +0900 (3d6a72c) +++ lib/droonga/handler_runner.rb 2014-02-20 15:33:22 +0900 (6e80190) @@ -22,6 +22,14 @@ require "droonga/handler" module Droonga class HandlerRunner + class ConflictForSameCommand < Error + def initialize(types, dataset_name) + message = "Conflicting handlers for same command type are detected " + + "for the dataset \"#{dataset_name}\": #{types.inspect}" + super(message) + end + end + def initialize(loop, options={}) @loop = loop @options = options @@ -78,6 +86,7 @@ module Droonga $log.debug("#{self.class.name}: activating plugins for the dataset \"#{@dataset_name}\": " + "#{@options[:plugins].join(", ")}") @handler_classes = Handler.find_sub_classes(@options[:plugins] || []) + validate_uniqueness $log.debug("#{self.class.name}: activated:\n#{@handler_classes.join("\n")}") @forwarder = Forwarder.new(@loop) end @@ -88,6 +97,21 @@ module Droonga end end + def validate_uniqueness + types = {} + @handler_classes.each do |handler_class| + type = handler_class.message.type + types[type] ||= [] + types[type] << handler_class + end + types.each do |type, handler_classes| + types.delete(type) if handler_classes.size > 1 + end + if types.size > 0 + raise ConflictForSameCommand.new(types, @dataset_name) + end + end + def process_command(handler_class, command, raw_message) handler_message = HandlerMessage.new(raw_message) handler_message.validate -------------- next part -------------- HTML����������������������������...Download