Daijiro MORI
null+****@clear*****
Sun Jun 23 11:52:25 JST 2013
Daijiro MORI 2013-06-23 11:52:25 +0900 (Sun, 23 Jun 2013) New Revision: 4319e34bc706a32e4e4f54acb3295928dc98a55c https://github.com/groonga/fluent-plugin-droonga/commit/4319e34bc706a32e4e4f54acb3295928dc98a55c Message: Add 'handler_forward' plugin. Added files: lib/droonga/plugin/handler_forward.rb Added: lib/droonga/plugin/handler_forward.rb (+69 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/plugin/handler_forward.rb 2013-06-23 11:52:25 +0900 (3e51a49) @@ -0,0 +1,69 @@ +# -*- 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" + +module Droonga + class MergeHandler < Droonga::Handler + Droonga::HandlerPlugin.register("forward", self) + + CONFIG_FILE_PATH = 'config.json' + + def handlable?(command) + true + end + + def handle(command, request, *arguments) + destination = get_destination + post(request, + "to" => destination, "type" => command, "arguments" => arguments) + rescue => exception + if $log + $log.error "error while handling #{command}", + request: request, + arguments: arguments, + exception: exception + $log.error_backtrace + end + end + + def get_destination + loop do + refresh_config + if @config && @config["forward"] + path =****@conte***** + destination = @config["forward"][path] + return destination unless destination.nil? || destination.empty? + sleep 5 + end + end + end + + def refresh_config + unless File.exists?(CONFIG_FILE_PATH) + @config = nil + return + end + mtime = File.mtime(CONFIG_FILE_PATH) + return if @config_mtime == mtime + open(CONFIG_FILE_PATH) do |file| + @config = JSON.parse(file.read) + end + @config_mtime = mtime + end + end +end -------------- next part -------------- HTML����������������������������...Download