YUKI Hiroshi
null+****@clear*****
Fri Mar 20 16:08:36 JST 2015
YUKI Hiroshi 2015-03-20 16:08:36 +0900 (Fri, 20 Mar 2015) New Revision: c83c7a675556897dc735a2bfac28c2dc3668da03 https://github.com/droonga/droonga-engine/commit/c83c7a675556897dc735a2bfac28c2dc3668da03 Message: Extract codes to handle on_change Added files: lib/droonga/changable.rb Modified files: lib/droonga/cluster.rb lib/droonga/engine_node.rb lib/droonga/file_observer.rb Added: lib/droonga/changable.rb (+25 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/changable.rb 2015-03-20 16:08:36 +0900 (f2ab934) @@ -0,0 +1,25 @@ +# Copyright (C) 2015 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +module Droonga + module Changable + attr_writer :on_change + + private + def on_change + @on_change.call if @on_change + end + end +end Modified: lib/droonga/cluster.rb (+4 -8) =================================================================== --- lib/droonga/cluster.rb 2015-03-20 15:52:36 +0900 (bfc7708) +++ lib/droonga/cluster.rb 2015-03-20 16:08:36 +0900 (e6183a5) @@ -1,4 +1,4 @@ -# Copyright (C) 2014 Droonga Project +# Copyright (C) 2014-2015 Droonga Project # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -14,6 +14,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA require "droonga/loggable" +require "droonga/changable" require "droonga/path" require "droonga/file_observer" require "droonga/engine_node" @@ -22,19 +23,18 @@ require "droonga/node_metadata" module Droonga class Cluster include Loggable + include Changable class NoCatalogLoaded < StandardError end attr_accessor :catalog - attr_writer :on_change def initialize(loop, params) @loop = loop @catalog = params[:catalog] @state = nil - @on_change = nil @node_metadata = params[:metadata] reload @@ -81,7 +81,7 @@ module Droonga logger.info("cluster state not changed") else logger.info("cluster state changed") - engine_nodes.each(&:on_change) + engine_nodes.each(&:resume) on_change end end @@ -124,10 +124,6 @@ module Droonga end.collect(&:name) end - def on_change - @on_change.call if @on_change - end - private def clear_cache @engine_nodes = nil Modified: lib/droonga/engine_node.rb (+1 -1) =================================================================== --- lib/droonga/engine_node.rb 2015-03-20 15:52:36 +0900 (f2e2cc7) +++ lib/droonga/engine_node.rb 2015-03-20 16:08:36 +0900 (5212f21) @@ -89,7 +89,7 @@ module Droonga } end - def on_change + def resume @sender.resume end Modified: lib/droonga/file_observer.rb (+4 -5) =================================================================== --- lib/droonga/file_observer.rb 2015-03-20 15:52:36 +0900 (b6f8fe7) +++ lib/droonga/file_observer.rb 2015-03-20 16:08:36 +0900 (63e75e2) @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- # -# Copyright (C) 2014 Droonga Project +# Copyright (C) 2014-2015 Droonga Project # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public @@ -19,15 +19,15 @@ require "coolio" require "droonga/path" require "droonga/loggable" +require "droonga/changable" module Droonga class FileObserver include Loggable + include Changable CHECK_INTERVAL = 1 - attr_accessor :on_change - def initialize(loop, path) @loop = loop @path = path @@ -36,7 +36,6 @@ module Droonga else @mtime = nil end - @on_change = nil end def start @@ -44,7 +43,7 @@ module Droonga on_timer = lambda do if updated? @mtime =****@path***** - @on_change.call if @on_change + on_change end end @watcher.on_timer do -------------- next part -------------- HTML����������������������������...Download