diff options
author | Eric Wong <normalperson@yhbt.net> | 2011-12-08 17:34:25 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2011-12-08 17:57:39 -0800 |
commit | 3e80aa8b62dd1b9e1d78e4c1c487f1ea5ee162cd (patch) | |
tree | 02915d80e5a3d03de50d77a9866829e2c307816b | |
parent | f62e34251c1101b0fcdddea35dfa3f73c416a3ba (diff) | |
download | mogilefs-client-3e80aa8b62dd1b9e1d78e4c1c487f1ea5ee162cd.tar.gz |
Instead of hard coding the thresholds, allow users to change accessors
-rw-r--r-- | lib/mogilefs/pool.rb | 14 |
1 files 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 |