[Groonga-commit] droonga/droonga-engine at 052fb3e [master] Separate methods to send or reserve

Back to archive index

YUKI Hiroshi null+****@clear*****
Fri Jun 27 15:55:11 JST 2014


YUKI Hiroshi	2014-06-27 15:55:11 +0900 (Fri, 27 Jun 2014)

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

  Message:
    Separate methods to send or reserve

  Modified files:
    lib/droonga/fluent_message_sender.rb
    lib/droonga/forwarder.rb

  Modified: lib/droonga/fluent_message_sender.rb (+17 -9)
===================================================================
--- lib/droonga/fluent_message_sender.rb    2014-06-27 15:05:00 +0900 (0807e9e)
+++ lib/droonga/fluent_message_sender.rb    2014-06-27 15:55:11 +0900 (88cd141)
@@ -47,20 +47,23 @@ module Droonga
       logger.trace("shutdown: done")
     end
 
-    def send(tag, data, options={})
+    def send(tag, data)
       logger.trace("send: start")
-      fluent_message = [tag, Time.now.to_i, data]
-      packed_fluent_message = MessagePackPacker.pack(fluent_message)
+      packed_fluent_message = create_packed_fluent_message(tag, data)
       connect unless connected?
-      if options[:reserve]
-        @socket.reserve_write(packed_fluent_message)
-        logger.trace("send: reserved")
-      else
-        @socket.write(packed_fluent_message)
-        logger.trace("send: done")
+      @socket.write(packed_fluent_message)
+      logger.trace("send: done")
       end
     end
 
+    def reserve_send(tag, data)
+      logger.trace("reserve_send: start")
+      packed_fluent_message = create_packed_fluent_message(tag, data)
+      connect unless connected?
+      @socket.reserve_write(packed_fluent_message)
+      logger.trace("reserve_send: done")
+    end
+
     def resume
       connect
       @socket.resume
@@ -113,6 +116,11 @@ module Droonga
       @socket.close unles****@socke*****?
     end
 
+    def create_packed_fluent_message(tag, data)
+      fluent_message = [tag, Time.now.to_i, data]
+      MessagePackPacker.pack(fluent_message)
+    end
+
     def log_tag
       "[#{Process.ppid}][#{Process.pid}] fluent-message-sender"
     end

  Modified: lib/droonga/forwarder.rb (+8 -3)
===================================================================
--- lib/droonga/forwarder.rb    2014-06-27 15:05:00 +0900 (4b707e3)
+++ lib/droonga/forwarder.rb    2014-06-27 15:55:11 +0900 (63afac5)
@@ -47,7 +47,8 @@ module Droonga
       command = destination["type"]
       receiver = destination["to"]
       arguments = destination["arguments"]
-      output(receiver, message, command, arguments)
+      reserve = destination["reserve"]
+      output(receiver, message, command, arguments, :reserve => reserve)
       logger.trace("forward: done")
     end
 
@@ -72,7 +73,7 @@ module Droonga
     end
 
     private
-    def output(receiver, message, command, arguments)
+    def output(receiver, message, command, arguments, options={})
       logger.trace("output: start")
       if not receiver.is_a?(String) or not command.is_a?(String))
         logger.trace("output: abort: invalid argument",
@@ -103,7 +104,11 @@ module Droonga
       output_tag = "#{tag}.message"
       log_info = "<#{receiver}>:<#{output_tag}>"
       logger.trace("output: post: start: #{log_info}")
-      sender.send(output_tag, message)
+      if options[:reserve]
+        sender.reserve_send(output_tag, message)
+      else
+        sender.send(output_tag, message)
+      end
       logger.trace("output: post: done: #{log_info}")
       logger.trace("output: done")
     end
-------------- next part --------------
HTML����������������������������...
Télécharger 



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