From 3e80aa8b62dd1b9e1d78e4c1c487f1ea5ee162cd Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 8 Dec 2011 17:34:25 -0800 Subject: pool: add @purge_threshold, @purge_keep accessors Instead of hard coding the thresholds, allow users to change accessors --- lib/mogilefs/pool.rb | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/mogilefs/pool.rb b/lib/mogilefs/pool.rb index 6033ada..1c220fd 100644 --- a/lib/mogilefs/pool.rb +++ b/lib/mogilefs/pool.rb @@ -3,6 +3,14 @@ require 'thread' class MogileFS::Pool + # Must be a positive Integer that is greater than :purge_keep + # Default: 5 + attr_accessor :purge_threshold + + # Must be a positive Integer that is smaller than :purge_threshold + # Default: 2 + attr_accessor :purge_keep + class BadObjectError < RuntimeError; end def initialize(klass, *args) @@ -10,6 +18,8 @@ class MogileFS::Pool @klass = klass @queue = Queue.new @objects = [] + @purge_threshold = 5 + @purge_keep = 2 end def get @@ -38,9 +48,9 @@ class MogileFS::Pool end def purge - return if @queue.length < 5 + return if @queue.length < @purge_threshold begin - until @queue.length <= 2 do + until @queue.length <= @purge_keep obj = @queue.pop true @objects.delete obj end -- cgit v1.2.3-24-ge0c7