[Groonga-commit] droonga/droonga-engine at 2a9f6fa [master] Timeout sessions after 60sec.

Back to archive index

YUKI Hiroshi null+****@clear*****
Mon Apr 6 19:42:14 JST 2015


YUKI Hiroshi	2015-04-06 19:42:14 +0900 (Mon, 06 Apr 2015)

  New Revision: 2a9f6fa85bb75c32e4bc3b4d9a9ffcc608d4275f
  https://github.com/droonga/droonga-engine/commit/2a9f6fa85bb75c32e4bc3b4d9a9ffcc608d4275f

  Message:
    Timeout sessions after 60sec.

  Modified files:
    lib/droonga/engine_state.rb
    lib/droonga/session.rb

  Modified: lib/droonga/engine_state.rb (+5 -0)
===================================================================
--- lib/droonga/engine_state.rb    2015-04-06 19:41:53 +0900 (7c86c57)
+++ lib/droonga/engine_state.rb    2015-04-06 19:42:14 +0900 (b12aae8)
@@ -27,6 +27,8 @@ module Droonga
     include Loggable
     include Deferrable
 
+    DEFAULT_SESSION_TIMEOUT_SECONDS = 60
+
     attr_reader :loop
     attr_reader :name
     attr_reader :internal_name
@@ -125,6 +127,9 @@ module Droonga
     def register_session(id, session)
       @sessions[id] = session
       logger.trace("new session #{id} is registered. rest sessions=#{@sessions.size}")
+      session.set_timeout(@loop, DEFAULT_SESSION_TIMEOUT_SECONDS) do
+        unregister_session(id)
+      end
     end
 
     def unregister_session(id)

  Modified: lib/droonga/session.rb (+21 -1)
===================================================================
--- lib/droonga/session.rb    2015-04-06 19:41:53 +0900 (373a10c)
+++ lib/droonga/session.rb    2015-04-06 19:42:14 +0900 (8ff9b8f)
@@ -1,4 +1,4 @@
-# Copyright (C) 2013-2014 Droonga Project
+# Copyright (C) 2013-2015 Droonga Project
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Lesser General Public
@@ -13,6 +13,8 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 
+require "coolio"
+
 require "droonga/loggable"
 
 module Droonga
@@ -87,6 +89,20 @@ module Droonga
       end
     end
 
+    def set_timeout(loop, timeout_seconds, &on_timeout)
+      @timeout_timer = Coolio::TimerWatcher.new(timeout_seconds)
+      on_timer = lambda do
+        @timeout_timer.detach
+        @timeout_timer = nil
+        report_timeout_error
+        on_timeout.call
+      end
+      @timeout_timer.on_timer do
+        on_timer.call
+      end
+      loop.attach(@timeout_timer)
+    end
+
     private
     def send_to_descendantas(descendantas, result)
       descendantas.each do |name, routes|
@@ -101,6 +117,10 @@ module Droonga
       end
     end
 
+    def report_timeout_error
+      #TODO: implement me!
+    end
+
     def log_tag
       "session"
     end
-------------- next part --------------
HTML����������������������������...
Download 



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