[Groonga-commit] droonga/droonga-engine at 4f8a380 [master] Use Listen to observe changes of live nodes list

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri May 9 14:43:37 JST 2014


YUKI Hiroshi	2014-05-09 14:43:37 +0900 (Fri, 09 May 2014)

  New Revision: 4f8a3800a914f6bf82569e6b602079dc506d2815
  https://github.com/droonga/droonga-engine/commit/4f8a3800a914f6bf82569e6b602079dc506d2815

  Message:
    Use Listen to observe changes of live nodes list

  Modified files:
    droonga-engine.gemspec
    lib/droonga/live_nodes_list_observer.rb

  Modified: droonga-engine.gemspec (+1 -0)
===================================================================
--- droonga-engine.gemspec    2014-05-09 14:23:50 +0900 (5c0d9ab)
+++ droonga-engine.gemspec    2014-05-09 14:43:37 +0900 (696f094)
@@ -41,6 +41,7 @@ Gem::Specification.new do |gem|
   gem.add_dependency "cool.io"
   gem.add_dependency "serverengine"
   gem.add_dependency "droonga-message-pack-packer"
+  gem.add_dependency "listen", "~> 2.7"
   gem.add_development_dependency "rake"
   gem.add_development_dependency "bundler"
   gem.add_development_dependency "droonga-client"

  Modified: lib/droonga/live_nodes_list_observer.rb (+15 -0)
===================================================================
--- lib/droonga/live_nodes_list_observer.rb    2014-05-09 14:23:50 +0900 (bb89732)
+++ lib/droonga/live_nodes_list_observer.rb    2014-05-09 14:43:37 +0900 (ac292c9)
@@ -13,6 +13,7 @@
 # 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 "listen"
 require "droonga/loggable"
 require "droonga/live_nodes_list_loader"
 
@@ -22,10 +23,20 @@ module Droonga
 
     attr_accessor :on_update
 
+    def initialize
+      @listener = Listen.to(directory_path) do |modified, added, removed|
+        if added == file_path or modified == file_path
+          load_list!
+        end
+      end
+    end
+
     def start
+      @listener.start
     end
 
     def stop
+      @listener.stop
     end
 
     DEFAULT_LIST_PATH = "live-nodes.json"
@@ -39,6 +50,10 @@ module Droonga
       File.expand_path(path, base_path)
     end
 
+    def directory_path
+      File.dirname(file_path)
+    end
+
     def load_list!
       loader = LiveNodesListLoader.new(file_path)
       live_nodes = loader.load
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index