YUKI Hiroshi
null+****@clear*****
Mon Apr 6 19:24:53 JST 2015
YUKI Hiroshi 2015-04-06 19:24:53 +0900 (Mon, 06 Apr 2015) New Revision: 55b1c192fd7dce62fe38ba9b2f1f671dee44c5d4 https://github.com/droonga/droonga-engine/commit/55b1c192fd7dce62fe38ba9b2f1f671dee44c5d4 Message: Close sender automatically if there is no new output for the target while 60sec. Modified files: lib/droonga/forwarder.rb Modified: lib/droonga/forwarder.rb (+33 -1) =================================================================== --- lib/droonga/forwarder.rb 2015-04-06 18:06:46 +0900 (e3525df) +++ lib/droonga/forwarder.rb 2015-04-06 19:24:53 +0900 (1901ebe) @@ -26,10 +26,15 @@ module Droonga class AlreadyShutdown < StandardError end + DEFAULT_AUTO_CLOSE_TIMEOUT_SECONDS = 60 + def initialize(loop, options={}) @loop = loop @senders = {} + @auto_close_timers = {} @shutting_down = false + @auto_close_timeout_seconds = options[:auto_close_timeout_seconds] || + DEFAULT_AUTO_CLOSE_TIMEOUT_SECONDS end def start @@ -43,6 +48,9 @@ module Droonga @senders.each_value do |sender| sender.shutdown end + @auto_close_timers.each_value do |timer| + timer.detach + end logger.trace("shutdown: done") end @@ -80,6 +88,7 @@ module Droonga :params => params) return end + set_auto_close_timer(host, port, params) override_message = { "type" => command, } @@ -93,11 +102,15 @@ module Droonga logger.trace("output: done") end - def find_sender(host, port, params) + def resolve_destination(host, port, params) connection_id = extract_connection_id(params) destination = "#{host}:#{port}" destination << "?#{connection_id}" if connection_id + destination + end + def find_sender(host, port, params) + destination = resolve_destination(host, port, params) @senders[destination] ||= create_sender(host, port) end @@ -117,6 +130,25 @@ module Droonga sender end + def set_auto_close_timer(host, port, params) + destination = resolve_destination(host, port, params) + + previous_timer = @auto_close_timers[destination] + previous_timer.detach if previous_timer + + timer = Coolio::TimerWatcher.new(@auto_close_timeout_seconds) do + timer.detach + @auto_close_timers.delete(destination) + sender = @senders[destination] + if sender + sender.shutdown + @senders.delete(destination) + end + end + @loop.attach(timer) + @auto_close_timers[destination] = timer + end + def log_tag "[#{Process.ppid}] forwarder" end -------------- next part -------------- HTML����������������������������... Download