[Groonga-commit] long-long-float/droonga-engine at 316c80f [master] Define CatalogFetcher utility

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Aug 27 18:39:06 JST 2014


YUKI Hiroshi	2014-08-27 18:39:06 +0900 (Wed, 27 Aug 2014)

  New Revision: 316c80fb3f59290dbafa8423cfd446ce4744b087
  https://github.com/long-long-float/droonga-engine/commit/316c80fb3f59290dbafa8423cfd446ce4744b087

  Message:
    Define CatalogFetcher utility

  Added files:
    lib/droonga/catalog_fetcher.rb
  Modified files:
    lib/droonga/command/serf_event_handler.rb

  Added: lib/droonga/catalog_fetcher.rb (+59 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/catalog_fetcher.rb    2014-08-27 18:39:06 +0900 (d53697e)
@@ -0,0 +1,59 @@
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "time"
+
+require "droonga/catalog_generator"
+require "droonga/client"
+
+module Droonga
+  class CatalogFetcher
+    class << self
+      def fetch(client_options)
+        new(client_options).fetch
+      end
+    end
+
+    def initialize(client_options)
+      @client_options = default_options.merge(client_options)
+    end
+
+    def fetch
+      catalog = nil
+      Droonga::Client.open(@client_options) do |client|
+        request = client.request(:dataset => @client_options[:dataset],
+                                 :type    => "catalog.fetch") do |responce|
+          catalog = responce["body"]
+        end
+        request.wait
+      end
+      catalog
+    end
+
+    private
+    def default_options
+      default_options = {
+        :dataset       => CatalogGenerator::DEFAULT_DATASET,
+        :host          => "127.0.0.1",
+        :port          => CatalogGenerator::DEFAULT_PORT,
+        :tag           => CatalogGenerator::DEFAULT_TAG,
+        :protocol      => :droonga,
+        :timeout       => 1,
+        :receiver_host => "127.0.0.1",
+        :receiver_port => 0,
+      }
+    end
+  end
+end

  Modified: lib/droonga/command/serf_event_handler.rb (+6 -29)
===================================================================
--- lib/droonga/command/serf_event_handler.rb    2014-08-27 18:29:52 +0900 (124be4a)
+++ lib/droonga/command/serf_event_handler.rb    2014-08-27 18:39:06 +0900 (6d42b19)
@@ -18,9 +18,9 @@ require "json"
 require "droonga/path"
 require "droonga/serf"
 require "droonga/catalog_generator"
+require "droonga/catalog_fetcher"
 require "droonga/data_absorber"
 require "droonga/safe_file_writer"
-require "droonga/client"
 
 module Droonga
   module Command
@@ -147,11 +147,11 @@ module Droonga
         source_host  = source_node.split(":").first
         joining_host = joining_node.split(":").first
 
-        catalog = fetch_catalog(:dataset       => source_node_dataset,
-                                :host          => source_host,
-                                :port          => source_node_port,
-                                :tag           => tag,
-                                :receiver_host => joining_host)
+        catalog = CatalogFetcher.fetch(:dataset       => source_node_dataset,
+                                       :host          => source_host,
+                                       :port          => source_node_port,
+                                       :tag           => tag,
+                                       :receiver_host => joining_host)
         File.write(Path.catalog, JSON.generate(catalog))
 
         generator = create_current_catalog_generator(catalog)
@@ -197,29 +197,6 @@ module Droonga
         end
       end
 
-      def fetch_catalog(client_options={})
-        catalog = nil
-        default_options = {
-          :dataset       => CatalogGenerator::DEFAULT_DATASET,
-          :host          => "127.0.0.1",
-          :port          => CatalogGenerator::DEFAULT_PORT,
-          :tag           => CatalogGenerator::DEFAULT_TAG,
-          :protocol      => :droonga,
-          :timeout       => 1,
-          :receiver_host => "127.0.0.1",
-          :receiver_port => 0,
-        }
-        client_options = default_options.merge(client_options)
-        Droonga::Client.open(client_options) do |client|
-          request = client.request(:dataset => client_options[:dataset],
-                                   :type    => "catalog.fetch") do |responce|
-            catalog = responce["body"]
-          end
-          request.wait
-        end
-        catalog
-      end
-
       def set_replicas
         dataset = @payload["dataset"]
         return unless dataset
-------------- next part --------------
HTML����������������������������...
Télécharger 



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