[Groonga-commit] droonga/droonga-engine at d80185a [master] Extract main logic of data absorver to a class

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Jun 27 23:30:52 JST 2014


YUKI Hiroshi	2014-06-27 23:30:52 +0900 (Fri, 27 Jun 2014)

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

  Message:
    Extract main logic of data absorver to a class

  Added files:
    lib/droonga/data_absorber.rb
  Modified files:
    bin/droonga-engine-absorb-data

  Modified: bin/droonga-engine-absorb-data (+15 -35)
===================================================================
--- bin/droonga-engine-absorb-data    2014-06-27 23:04:09 +0900 (1649750)
+++ bin/droonga-engine-absorb-data    2014-06-27 23:30:52 +0900 (bf46fab)
@@ -21,90 +21,70 @@ require "open3"
 
 require "droonga/engine/version"
 
-options = OpenStruct.new
+options = {
+  :drndump => "drndump",
+  :client  => "droonga-request",
+}
 parser = OptionParser.new
 parser.version = Droonga::Engine::VERSION
 
-options.drndump = "drndump"
-drndump_options = []
-
-options.client = "droonga-request"
-client_options = []
-
 parser.separator("")
 parser.separator("Source:")
 parser.on("--source-host=HOST",
           "Host name of the source cluster to be connected.") do |host|
-  drndump_options += ["--host", host]
+  options[:source_host] = host
 end
 parser.on("--source-port=PORT", Integer,
           "Port number of the source cluster to be connected.") do |port|
-  drndump_options += ["--port", port.to_s]
+  options[:port] = port
 end
 
 parser.separator("")
 parser.separator("Destination:")
 parser.on("--destination-host=HOST",
           "Host name of this cluster to be connected.") do |host|
-  options.destination_host = host
+  options[:destination_host] = host
 end
 parser.on("--destination-port=PORT", Integer,
           "Port number of this cluster to be connected.") do |port|
-  client_options += ["--port", port.to_s]
+  options[:port] = port
 end
 
 parser.separator("")
 parser.separator("Data:")
 parser.on("--tag=TAG",
           "Tag name to be used to communicate with Droonga system.") do |tag|
-  drndump_options += ["--tag", tag]
-  client_options += ["--tag", tag]
+  options[:tag] = tag
 end
 parser.on("--dataset=DATASET",
           "Dataset to be absorbed.") do |dataset|
-  drndump_options += ["--dataset", dataset]
-  client_options += ["--tag", tag]
+  options[:dataset] = dataset
 end
 
 parser.separator("")
 parser.separator("Droonga protocol:")
 parser.on("--receiver-host=HOST",
           "Host name of this node to be received a response from clusters.") do |host|
-  options.destination_host = host
+  options[:destination_host] = host
 end
 parser.on("--receiver-port=PORT", Integer,
           "Port number of this node to be received a response from clusters.") do |port|
-  drndump_options += ["--receiver-port", port.to_s]
-  client_options += ["--receiver-port", port.to_s]
+  options[:receiver_port] = port
 end
 
 parser.separator("")
 parser.separator("Commands:")
 parser.on("--drndump=PATH",
           "Path to the drndump command.") do |path|
-  options.drndump = path
+  options[:drndump] = path
 end
 parser.on("--droonga-request=PATH",
           "Path to the droonga-request command.") do |path|
-  options.droonga_client = path
+  options[:client] = path
 end
 
 parser.parse!(ARGV)
 
-drndump_options += ["--receiver-host", options.destination_host]
-client_options += ["--host", options.destination_host]
-client_options += ["--receiver-host", options.destination_host]
-
-drndump_command_line = [options.drndump] + drndump_options
-client_command_line = [options.client] + client_options
-
-Open3.popen3(*drndump_command_line) do |dump_in, dump_out, dump_error, dump_thread|
-  Open3.popen3(*client_command_line) do |client_in, client_out, client_error, client_thread|
-    dump_out.each do |dump|
-      puts dump
-      client_in.puts(dump)
-    end
-  end
-end
+Droonga::DataAbsorber.absorb(options)
 
 exit 0

  Added: lib/droonga/data_absorber.rb (+54 -0) 100644
===================================================================
--- /dev/null
+++ lib/droonga/data_absorber.rb    2014-06-27 23:30:52 +0900 (7731b65)
@@ -0,0 +1,54 @@
+# 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 "open3"
+
+module Droonga
+  class DataAbsorber
+    class << self
+      def absorb(params)
+        drndump = params[:drndump] || "drndump"
+        drndump_options = []
+        drndump_options += ["--host", params[:source_host]] if params[:source_host]
+        drndump_options += ["--port", params[:port].to_s] if params[:port]
+        drndump_options += ["--tag", params[:tag]] if params[:tag]
+        drndump_options += ["--dataset", params[:dataset]] if params[:dataset]
+        drndump_options += ["--receiver-host", params[:destination_host]]
+        drndump_options += ["--receiver-port", params[:receiver_port].to_s] if params[:receiver_port]
+
+        client = params[:client] || "droonga-request"
+        client_options = []
+        client_options += ["--host", params[:destination_host]]
+        client_options += ["--port", params[:port].to_s] if params[:port]
+        client_options += ["--tag", params[:tag]] if params[:tag]
+        client_options += ["--dataset", params[:dataset]] if params[:dataset]
+        client_options += ["--receiver-host", params[:destination_host]]
+        client_options += ["--receiver-port", params[:receiver_port].to_s] if params[:receiver_port]
+
+        drndump_command_line = [drndump] + drndump_options
+        client_command_line = [client] + client_options
+
+        Open3.popen3(*drndump_command_line) do |dump_in, dump_out, dump_error, dump_thread|
+          Open3.popen3(*client_command_line) do |client_in, client_out, client_error, client_thread|
+            dump_out.each do |dump|
+              yield dump if block_given?
+              client_in.puts(dump)
+            end
+          end
+        end
+      end
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Télécharger 



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