Navigation Menu

Skip to content

Commit

Permalink
Timeout sessions after 60sec.
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 6, 2015
1 parent 53cce6c commit 2a9f6fa
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 5 additions & 0 deletions lib/droonga/engine_state.rb
Expand Up @@ -27,6 +27,8 @@ class EngineState
include Loggable
include Deferrable

DEFAULT_SESSION_TIMEOUT_SECONDS = 60

attr_reader :loop
attr_reader :name
attr_reader :internal_name
Expand Down Expand Up @@ -125,6 +127,9 @@ def find_session(id)
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)
Expand Down
22 changes: 21 additions & 1 deletion lib/droonga/session.rb
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -87,6 +89,20 @@ def receive(name, value)
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|
Expand All @@ -101,6 +117,10 @@ def send_to_descendantas(descendantas, result)
end
end

def report_timeout_error
#TODO: implement me!
end

def log_tag
"session"
end
Expand Down

0 comments on commit 2a9f6fa

Please sign in to comment.