[Groonga-commit] droonga/droonga-client-ruby at ab350f3 [master] Support max_messages option for sibscription with Cool.io

Back to archive index

YUKI Hiroshi null+****@clear*****
Tue Apr 14 20:57:51 JST 2015


YUKI Hiroshi	2015-04-14 20:57:51 +0900 (Tue, 14 Apr 2015)

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

  Message:
    Support max_messages option for sibscription with Cool.io

  Modified files:
    lib/droonga/client/connection/droonga-protocol/coolio.rb

  Modified: lib/droonga/client/connection/droonga-protocol/coolio.rb (+12 -1)
===================================================================
--- lib/droonga/client/connection/droonga-protocol/coolio.rb    2015-04-14 20:49:05 +0900 (e67c905)
+++ lib/droonga/client/connection/droonga-protocol/coolio.rb    2015-04-14 20:57:51 +0900 (82bf37b)
@@ -102,6 +102,8 @@ module Droonga
           end
 
           class Receiver < ::Coolio::TCPServer
+            attr_accessor :max_messages
+
             def initialize(*args)
               super(*args) do |engine|
                 @engines << engine
@@ -109,6 +111,7 @@ module Droonga
               end
               @requests = {}
               @engines = []
+              @max_messages = nil
             end
 
             def close
@@ -153,14 +156,21 @@ module Droonga
             private
             def handle_engine(engine)
               unpacker = MessagePack::Unpacker.new
+              n_messages = 0
               on_read = lambda do |data|
                 unpacker.feed_each(data) do |fluent_message|
                   tag, time, droonga_message = fluent_message
                   id = droonga_message["inReplyTo"]
                   request = @requests[id]
-                  next if request.nil?
+                  n_messages += 1
+                  if request
                   request[:received] = true
                   request[:callback].call(droonga_message)
+                  end
+                  if @max_messages and
+                       n_messages >= @max_messages
+                    unregister(id)
+                  end
                 end
               end
               engine.on_read do |data|
@@ -231,6 +241,7 @@ module Droonga
             request_options = {
               :subscription_timeout => options[:subscription_timeout],
             }
+            @receiver.max_messages = options[:max_messages]
             request = InfiniteRequest.new(@loop, request_options)
             request.on_timeout = lambda do
               @receiver.unregister(id)
-------------- next part --------------
HTML����������������������������...
Download 



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