YUKI Hiroshi
null+****@clear*****
Wed Apr 15 18:12:17 JST 2015
YUKI Hiroshi 2015-04-15 18:12:17 +0900 (Wed, 15 Apr 2015) New Revision: 332369a5b754f6bde9ec4de7af9cb2043ca70779 https://github.com/droonga/droonga-client-ruby/commit/332369a5b754f6bde9ec4de7af9cb2043ca70779 Message: Add ability to detect nil message error Modified files: lib/droonga/client/connection/droonga-protocol/coolio.rb lib/droonga/client/connection/droonga-protocol/thread.rb Modified: lib/droonga/client/connection/droonga-protocol/coolio.rb (+24 -0) =================================================================== --- lib/droonga/client/connection/droonga-protocol/coolio.rb 2015-04-15 17:10:02 +0900 (132087b) +++ lib/droonga/client/connection/droonga-protocol/coolio.rb 2015-04-15 18:12:17 +0900 (8ff9dee) @@ -21,6 +21,11 @@ module Droonga module Connection class DroongaProtocol class Coolio + attr_writer :on_error + + class NilMessage < StandardError + end + class Request def initialize(receiver, id, loop) @receiver = receiver @@ -103,6 +108,7 @@ module Droonga class Receiver < ::Coolio::TCPServer attr_accessor :max_messages + attr_writer :on_error def initialize(*args) super(*args) do |engine| @@ -159,7 +165,14 @@ module Droonga n_messages = 0 on_read = lambda do |data| unpacker.feed_each(data) do |fluent_message| + unless fluent_message + on_error(NilMessage.new("unpacker.feed_each")) + end tag, time, droonga_message = fluent_message + unless droonga_message + on_error(NilMessage.new("unpacker.feed_each", + :fluent_message => fluent_message.inspect)) + end id = droonga_message["inReplyTo"] request = @requests[id] n_messages += 1 @@ -184,6 +197,10 @@ module Droonga on_close.call end end + + def on_error(error) + @on_error.call(error) if @on_error + end end def initialize(host, port, tag, options={}) @@ -200,6 +217,9 @@ module Droonga @receiver_host = @options[:receiver_host] || Socket.gethostname @receiver_port = @options[:receiver_port] || 0 @receiver = Receiver.new(@receiver_host, @receiver_port) + @receiver.on_error = lambda do |error| + on_error(error) + end @receiver.attach(@loop) end @@ -284,6 +304,10 @@ module Droonga @sender.close @receiver.close end + + def on_error(error) + @on_error.call(error) if @on_error + end end end end Modified: lib/droonga/client/connection/droonga-protocol/thread.rb (+10 -0) =================================================================== --- lib/droonga/client/connection/droonga-protocol/thread.rb 2015-04-15 17:10:02 +0900 (e927187) +++ lib/droonga/client/connection/droonga-protocol/thread.rb 2015-04-15 18:12:17 +0900 (1bf0576) @@ -25,6 +25,11 @@ module Droonga class Thread DEFAULT_TIMEOUT_SECONDS = 10 + attr_writer :on_error + + class NilMessage < StandardError + end + class Request def initialize(thread) @thread = thread @@ -153,6 +158,7 @@ module Droonga } begin receiver.receive(receive_options) do |response| + on_error(NilMessage.new("receiver.receive")) yield(response) end ensure @@ -160,6 +166,10 @@ module Droonga end end + def on_error(error) + @on_error.call(error) if @on_error + end + class Receiver def initialize(options={}) host = options[:host] || Socket.gethostname -------------- next part -------------- HTML����������������������������...Download