Yoji Shidara
null+****@clear*****
Thu Feb 13 16:10:20 JST 2014
Yoji Shidara 2014-02-13 16:10:20 +0900 (Thu, 13 Feb 2014) New Revision: b541a10ca8caa8cd5fbe3cc409d6afb312c5e577 https://github.com/droonga/fluent-plugin-droonga/commit/b541a10ca8caa8cd5fbe3cc409d6afb312c5e577 Message: Load catalog via CatalogObserver Removed files: lib/droonga/catalog.rb Modified files: lib/droonga/catalog_observer.rb lib/fluent/plugin/out_droonga.rb Deleted: lib/droonga/catalog.rb (+0 -24) 100644 =================================================================== --- lib/droonga/catalog.rb 2014-02-13 15:29:05 +0900 (7fef29b) +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# -# Copyright (C) 2013-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 - -require "droonga/catalog_loader" - -module Droonga - class << self - attr_accessor :catalog - end -end Modified: lib/droonga/catalog_observer.rb (+23 -5) =================================================================== --- lib/droonga/catalog_observer.rb 2014-02-13 15:29:05 +0900 (019fc0d) +++ lib/droonga/catalog_observer.rb 2014-02-13 16:10:20 +0900 (0ba0a24) @@ -15,15 +15,33 @@ # 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/catalog_loader" + module Droonga class CatalogObserver DEFAULT_CATALOG_PATH = "catalog.json" CHECK_INTERVAL = 1 - def initialize(loop) + attr_reader :catalog + + def initialize @catalog_path = catalog_path - load_catalog + load_catalog! + end + + def start + @loop = Cool.io::Loop.new + @thread = Thread.new do + @loop.run + end + end + + def stop + @loop.stop + @thread.join + end + def attach(loop) watcher = Cool.io::TimerWatcher.new(CHECK_INTERVAL, true) observer = self watcher.on_timer do @@ -34,7 +52,7 @@ module Droonga def ensure_latest_catalog_loaded if catalog_updated? - load_catalog + load_catalog! end end @@ -47,9 +65,9 @@ module Droonga File.mtime(catalog_path) > @catalog_mtime end - def load_catalog + def load_catalog! loader = CatalogLoader.new(@catalog_path) - Droonga.catalog = loader.load + @catalog = loader.load @catalog_mtime = File.mtime(@catalog_path) $log.info "catalog loaded", path: @catalog_path, mtime: @catalog_mtime end Modified: lib/fluent/plugin/out_droonga.rb (+3 -6) =================================================================== --- lib/fluent/plugin/out_droonga.rb 2014-02-13 15:29:05 +0900 (348b104) +++ lib/fluent/plugin/out_droonga.rb 2014-02-13 16:10:20 +0900 (451d782) @@ -17,7 +17,7 @@ require "droonga/engine" require "droonga/plugin_loader" -require "droonga/catalog_loader" +require "droonga/catalog_observer" module Fluent class DroongaOutput < Output @@ -28,6 +28,8 @@ module Fluent def start super Droonga::PluginLoader.load_all + @catalog_observer = Droonga::CatalogObserver.new + catalog = @catalog_observer.catalog @engine = Droonga::Engine.new(catalog, :name => @name) @engine.start end @@ -45,11 +47,6 @@ module Fluent end private - def catalog - catalog_loader = Droonga::CatalogLoader.new("catalog.json") - catalog_loader.load - end - def process_event(tag, record) $log.trace("out_droonga: tag: <#{tag}>") @engine.process(parse_record(tag, record)) -------------- next part -------------- HTML����������������������������...Download