Yoji Shidara
null+****@clear*****
Thu Jan 23 19:06:13 JST 2014
Yoji Shidara 2014-01-23 19:06:13 +0900 (Thu, 23 Jan 2014) New Revision: 484853d29e51c302f01a6f1601fc429163369f8a https://github.com/droonga/fluent-plugin-droonga/commit/484853d29e51c302f01a6f1601fc429163369f8a Message: Reload catalog when updated Added files: lib/droonga/catalog_observer.rb Modified files: lib/droonga/catalog.rb lib/droonga/dispatcher.rb Modified: lib/droonga/catalog.rb (+1 -19) =================================================================== --- lib/droonga/catalog.rb 2014-01-23 18:22:22 +0900 (066d162) +++ lib/droonga/catalog.rb 2014-01-23 19:06:13 +0900 (8d1e859) @@ -19,24 +19,6 @@ require "droonga/catalog_loader" module Droonga class << self - def catalog - @catalog ||= Catalog.load - end - end - - module Catalog - DEFAULT_PATH = "catalog.json" - - class << self - def load - loader = CatalogLoader.new(path) - loader.load - end - - def path - path = ENV["DROONGA_CATALOG"] || DEFAULT_PATH - File.expand_path(path) - end - end + attr_accessor :catalog end end Added: lib/droonga/catalog_observer.rb (+57 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/catalog_observer.rb 2014-01-23 19:06:13 +0900 (019fc0d) @@ -0,0 +1,57 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2014 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 + +module Droonga + class CatalogObserver + DEFAULT_CATALOG_PATH = "catalog.json" + CHECK_INTERVAL = 1 + + def initialize(loop) + @catalog_path = catalog_path + load_catalog + + watcher = Cool.io::TimerWatcher.new(CHECK_INTERVAL, true) + observer = self + watcher.on_timer do + observer.ensure_latest_catalog_loaded + end + loop.attach(watcher) + end + + def ensure_latest_catalog_loaded + if catalog_updated? + load_catalog + end + end + + def catalog_path + path = ENV["DROONGA_CATALOG"] || DEFAULT_CATALOG_PATH + File.expand_path(path) + end + + def catalog_updated? + File.mtime(catalog_path) > @catalog_mtime + end + + def load_catalog + loader = CatalogLoader.new(@catalog_path) + Droonga.catalog = loader.load + @catalog_mtime = File.mtime(@catalog_path) + $log.info "catalog loaded", path: @catalog_path, mtime: @catalog_mtime + end + end +end Modified: lib/droonga/dispatcher.rb (+3 -1) =================================================================== --- lib/droonga/dispatcher.rb 2014-01-23 18:22:22 +0900 (17907c3) +++ lib/droonga/dispatcher.rb 2014-01-23 19:06:13 +0900 (1b36884) @@ -27,6 +27,7 @@ require "droonga/farm" require "droonga/session" require "droonga/replier" require "droonga/message_processing_error" +require "droonga/catalog_observer" module Droonga class Dispatcher @@ -48,6 +49,8 @@ module Droonga def initialize(options) @options = options @name = @options[:name] + @loop = EventLoop.new + @catalog_observer = CatalogObserver.new(@loop) @sessions = {} @current_id = 0 @local = Regexp.new("^#{@name}") @@ -55,7 +58,6 @@ module Droonga InputAdapter.new(self, :plugins => Droonga.catalog.option("plugins")) @output_adapter = OutputAdapter.new(self, :plugins => Droonga.catalog.option("plugins")) - @loop = EventLoop.new @farm = Farm.new(name, @loop, :dispatcher => self) @forwarder = Forwarder.new(@loop) @replier = Replier.new(@forwarder) -------------- next part -------------- HTML����������������������������...Download