YUKI Hiroshi
null+****@clear*****
Thu Oct 31 12:30:33 JST 2013
YUKI Hiroshi 2013-10-31 12:30:33 +0900 (Thu, 31 Oct 2013) New Revision: 36a6fac3675d4f8fa66e6254be895265a7940e70 https://github.com/droonga/fluent-plugin-droonga/commit/36a6fac3675d4f8fa66e6254be895265a7940e70 Message: Extract Droonga::Sweeper from Droonga::Watcher Added files: lib/droonga/sweeper.rb Modified files: lib/droonga/watcher.rb Added: lib/droonga/sweeper.rb (+42 -0) 100644 =================================================================== --- /dev/null +++ lib/droonga/sweeper.rb 2013-10-31 12:30:33 +0900 (e7ff1df) @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# +# Copyright (C) 2013 droonga project +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License version 2.1 as published by the Free Software Foundation. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +module Droonga + class Sweeper + GARBAGE_COLLECTION_INTERVAL_SECONDS = 20 * 60 # 20 min + SUBSCRIBER_LIFETIME_SECONDS = 10 * 60 # 10 min + + def initialize(context) + @context = context + end + + def activate_periodical_sleep(options={}) + interval = options[:interval] || GARBAGE_COLLECTION_INTERVAL_SECONDS + @sweeper_thread = Thread.new do + while true + sweep_expired_subscribers + sleep(interval) + end + end + end + + def sweep_expired_subscribers + boundary = Time.now - SUBSCRIBER_LIFETIME_SECONDS + # implement me! + end + end +end Modified: lib/droonga/watcher.rb (+0 -18) =================================================================== --- lib/droonga/watcher.rb 2013-10-31 12:28:10 +0900 (211d449) +++ lib/droonga/watcher.rb 2013-10-31 12:30:33 +0900 (a462c25) @@ -18,12 +18,9 @@ module Droonga class Watcher EXACT_MATCH = false - GARBAGE_COLLECTION_INTERVAL_SECONDS = 20 * 60 # 20 min - SUBSCRIBER_LIFETIME_SECONDS = 10 * 60 # 10 min def initialize(context) @context = context - activate_garbage_collection end def subscribe(request) @@ -173,20 +170,5 @@ module Droonga yield(route, subscribers) end end - - def activate_garbage_collection(options={}) - interval = options[:interval] || GARBAGE_COLLECTION_INTERVAL_SECONDS - @gc_thread = Thread.new do - while true - clear_expired_subscribers - sleep(interval) - end - end - end - - def clear_expired_subscribers - # implement me! - boundary = Time.now - SUBSCRIBER_LIFETIME_SECONDS - end end end -------------- next part -------------- HTML����������������������������...Download