Kouhei Sutou
null+****@clear*****
Tue Jun 24 15:51:07 JST 2014
Kouhei Sutou 2014-06-24 15:51:07 +0900 (Tue, 24 Jun 2014) New Revision: 60272042e7af834c8b174c7a2c9ad84ab54f56f6 https://github.com/droonga/droonga-engine/commit/60272042e7af834c8b174c7a2c9ad84ab54f56f6 Message: Remove listen gem dependency Because listen gem is implemented based on celluloid gem and thread. It is poor compatibility with Droonga. Droonga uses another event loop system, cool.io. Removed files: lib/droonga/live_nodes_list_observer.rb Modified files: droonga-engine.gemspec lib/droonga/command/droonga_engine.rb lib/droonga/command/serf_event_handler.rb lib/droonga/engine.rb lib/droonga/path.rb Renamed files: lib/droonga/file_observer.rb (from lib/droonga/catalog_observer.rb) Modified: droonga-engine.gemspec (+0 -1) =================================================================== --- droonga-engine.gemspec 2014-06-03 12:35:44 +0900 (54c055b) +++ droonga-engine.gemspec 2014-06-24 15:51:07 +0900 (2f833e7) @@ -41,7 +41,6 @@ Gem::Specification.new do |gem| gem.add_dependency "cool.io" gem.add_dependency "serverengine" gem.add_dependency "droonga-message-pack-packer", ">= 1.0.1" - gem.add_dependency "listen", "~> 2.7" gem.add_dependency "faraday" gem.add_dependency "faraday_middleware" gem.add_dependency "archive-zip" Modified: lib/droonga/command/droonga_engine.rb (+2 -2) =================================================================== --- lib/droonga/command/droonga_engine.rb 2014-06-03 12:35:44 +0900 (0b24223) +++ lib/droonga/command/droonga_engine.rb 2014-06-24 15:51:07 +0900 (8edaec4) @@ -23,7 +23,7 @@ require "sigdump" require "droonga/path" require "droonga/serf" -require "droonga/catalog_observer" +require "droonga/file_observer" require "droonga/service_control_protocol" require "droonga/line_buffer" @@ -324,7 +324,7 @@ module Droonga end def run_catalog_observer - catalog_observer = CatalogObserver.new(@loop) + catalog_observer = FileObserver.new(@loop, Path.catalog) catalog_observer.on_change = lambda do restart_graceful end Modified: lib/droonga/command/serf_event_handler.rb (+2 -2) =================================================================== --- lib/droonga/command/serf_event_handler.rb 2014-06-03 12:35:44 +0900 (b98fcb1) +++ lib/droonga/command/serf_event_handler.rb 2014-06-24 15:51:07 +0900 (27945c1) @@ -21,7 +21,7 @@ require "tempfile" require "droonga/path" require "droonga/serf" -require "droonga/live_nodes_list_observer" +require "droonga/file_observer" module Droonga module Command @@ -70,7 +70,7 @@ module Droonga end def output_live_nodes - list_path = LiveNodesListObserver.path + list_path = Path.live_nodes nodes = live_nodes file_contents = JSON.pretty_generate(nodes) # Don't output the file directly to prevent loading of incomplete file! Modified: lib/droonga/engine.rb (+15 -4) =================================================================== --- lib/droonga/engine.rb 2014-06-03 12:35:44 +0900 (089efec) +++ lib/droonga/engine.rb 2014-06-24 15:51:07 +0900 (670da24) @@ -22,7 +22,7 @@ require "droonga/loggable" require "droonga/engine_state" require "droonga/catalog_loader" require "droonga/dispatcher" -require "droonga/live_nodes_list_observer" +require "droonga/file_observer" module Droonga class Engine @@ -36,9 +36,9 @@ module Droonga @catalog = load_catalog @live_nodes =****@catal*****_nodes @dispatcher = create_dispatcher - @live_nodes_list_observer = LiveNodesListObserver.new - @live_nodes_list_observer.on_update = lambda do |live_nodes| - @live_nodes = live_nodes + @live_nodes_list_observer = FileObserver.new(loop, Path.live_nodes) + @live_nodes_list_observer.on_change = lambda do + @live_nodes = load_live_nodes @dispatcher.live_nodes = live_nodes if @dispatcher end end @@ -95,6 +95,16 @@ module Droonga catalog end + def load_live_nodes + path = Path.live_nodes + loader = LiveNodesListLoader.new(path) + live_nodes = loader.load + logger.info("live-nodes loaded", + :path => path, + :mtime => path.mtime) + live_nodes + end + def create_dispatcher dispatcher = Dispatcher.new(@state, @catalog) dispatcher.live_nodes = @live_nodes @@ -102,6 +112,7 @@ module Droonga end def output_last_processed_timestamp + FileUtils.mkdir_p(File.dirname(last_processed_timestamp_file)) File.open(last_processed_timestamp_file, "w") do |file| file.write(@last_processed_timestamp) end Renamed: lib/droonga/file_observer.rb (+10 -6) 85% =================================================================== --- lib/droonga/catalog_observer.rb 2014-06-03 12:35:44 +0900 (32a1d1b) +++ lib/droonga/file_observer.rb 2014-06-24 15:51:07 +0900 (2308038) @@ -21,17 +21,21 @@ require "droonga/path" require "droonga/loggable" module Droonga - class CatalogObserver + class FileObserver include Loggable CHECK_INTERVAL = 1 attr_accessor :on_change - def initialize(loop) + def initialize(loop, path) @loop = loop - @path = Path.catalog - @mtime =****@path***** + @path = path + if****@path*****? + @mtime =****@path***** + else + @mtime = nil + end @on_change = nil end @@ -55,11 +59,11 @@ module Droonga private def updated? - @path.mtime > @mtime + @path.exist? and****@path***** > @mtime end def log_tag - "catalog-observer" + "file-observer" end end end Deleted: lib/droonga/live_nodes_list_observer.rb (+0 -72) 100644 =================================================================== --- lib/droonga/live_nodes_list_observer.rb 2014-06-03 12:35:44 +0900 (0249390) +++ /dev/null @@ -1,72 +0,0 @@ -# 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 - -require "fileutils" -require "listen" - -require "droonga/path" -require "droonga/loggable" -require "droonga/live_nodes_list_loader" - -module Droonga - class LiveNodesListObserver - class << self - FILE_NAME = "live-nodes.json" - - def path - Path.state + FILE_NAME - end - end - - include Loggable - - attr_accessor :on_update - - def initialize - end - - def start - path = self.class.path - file_name = path.expand_path.to_s - directory = path.dirname.to_s - FileUtils.mkdir_p(directory) - @listener = Listen.to(directory) do |modified, added, removed| - if added.include?(file_name) or - modified.include?(file_name) - load_list! - end - end - @listener.start - end - - def stop - @listener.stop - end - - def load_list! - path = self.class.path - loader = LiveNodesListLoader.new(path) - live_nodes = loader.load - logger.info("loaded", :path => path.to_s, :live_nodes => live_nodes) - - on_update.call(live_nodes) if on_update - end - - private - def log_tag - "live-nodes-list-observer" - end - end -end Modified: lib/droonga/path.rb (+4 -0) =================================================================== --- lib/droonga/path.rb 2014-06-03 12:35:44 +0900 (46cb4c4) +++ lib/droonga/path.rb 2014-06-24 15:51:07 +0900 (7a81a3b) @@ -38,6 +38,10 @@ module Droonga base + "state" end + def live_nodes + state + "live-nodes.json" + end + def catalog base_file_name = ENV["DROONGA_CATALOG"] || "catalog.json" Pathname.new(base_file_name).expand_path(base) -------------- next part -------------- HTML����������������������������...Download