[Groonga-commit] droonga/droonga-client-ruby at e068c7e [master] Dispose clients automatically

Back to archive index

YUKI Hiroshi null+****@clear*****
Wed Apr 29 13:25:52 JST 2015


YUKI Hiroshi	2015-04-29 13:25:52 +0900 (Wed, 29 Apr 2015)

  New Revision: e068c7e2b78cc2549526db4ac842ed3f95889015
  https://github.com/droonga/droonga-client-ruby/commit/e068c7e2b78cc2549526db4ac842ed3f95889015

  Message:
    Dispose clients automatically

  Modified files:
    bin/droonga-groonga
    bin/droonga-system-status
    lib/droonga/command/base.rb

  Modified: bin/droonga-groonga (+1 -1)
===================================================================
--- bin/droonga-groonga    2015-04-29 13:22:54 +0900 (28da8dc)
+++ bin/droonga-groonga    2015-04-29 13:25:52 +0900 (df4dd44)
@@ -48,7 +48,7 @@ module Droonga
           "body" => build_params(ARGV),
         }
 
-        response = client.request(groonga_message)
+        response = request(groonga_message)
         raise NoResponse.new unless response
         body = response["body"]
 

  Modified: bin/droonga-system-status (+2 -2)
===================================================================
--- bin/droonga-system-status    2015-04-29 13:22:54 +0900 (c259d4f)
+++ bin/droonga-system-status    2015-04-29 13:25:52 +0900 (ef216c5)
@@ -29,8 +29,8 @@ module Droonga
                     :default => false)
         end
 
-        response = client.request("dataset" => @options[:dataset],
-                                  "type"    => "system.status")
+        response = request("dataset" => @options[:dataset],
+                           "type"    => "system.status")
         raise NoResponse.new unless response
         body = response["body"]
 

  Modified: lib/droonga/command/base.rb (+19 -2)
===================================================================
--- lib/droonga/command/base.rb    2015-04-29 13:22:54 +0900 (88f1cf9)
+++ lib/droonga/command/base.rb    2015-04-29 13:25:52 +0900 (7881a55)
@@ -63,7 +63,21 @@ module Droonga
         raise MissingRequiredParameter.new
       end
 
-      def client
+      def request(message)
+        resposne = nil
+        open do |client|
+          response = client.request(message)
+        end
+        response
+      end
+
+      def send(message)
+        open do |client|
+          client.send(message)
+        end
+      end
+
+      def open(&block)
         options = {
           :host          => @options[:host],
           :port          => @options[:port],
@@ -72,8 +86,11 @@ module Droonga
           :receiver_host => @options["receiver-host"],
           :receiver_port => 0,
           :default_timeout => @options[:timeout],
+          :default_target_role => @options[:target_role],
         }
-        @client ||= Droonga::Client.new(options)
+        Droonga::Client.open(options) do |client|
+          yield(client)
+        end
       end
     end
   end
-------------- next part --------------
HTML����������������������������...
Descargar 



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