Class: VCAP::UserPool
- Inherits:
-
Object
- Object
- VCAP::UserPool
- Defined in:
- lib/vcap/user_pools/user_pool.rb
Instance Attribute Summary collapse
-
#busy_users ⇒ Object
Returns the value of attribute busy_users.
-
#free_users ⇒ Object
Returns the value of attribute free_users.
Instance Method Summary collapse
- #alloc_user ⇒ Object
- #free_user(user) ⇒ Object
-
#initialize(name, logger = nil) ⇒ UserPool
constructor
A new instance of UserPool.
Constructor Details
#initialize(name, logger = nil) ⇒ UserPool
Returns a new instance of UserPool.
12 13 14 15 16 17 18 |
# File 'lib/vcap/user_pools/user_pool.rb', line 12 def initialize(name, logger = nil) @logger = logger || Logger.new(STDOUT) UserPoolUtil.init @free_users = UserPoolUtil.open_pool(name) @busy_users = Hash.new @logger.debug("Initialized user pool #{name} with #{@free_users.size} users.") end |
Instance Attribute Details
#busy_users ⇒ Object
Returns the value of attribute busy_users.
10 11 12 |
# File 'lib/vcap/user_pools/user_pool.rb', line 10 def busy_users @busy_users end |
#free_users ⇒ Object
Returns the value of attribute free_users.
9 10 11 |
# File 'lib/vcap/user_pools/user_pool.rb', line 9 def free_users @free_users end |
Instance Method Details
#alloc_user ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vcap/user_pools/user_pool.rb', line 20 def alloc_user user_name, user = @free_users.shift if user_name != nil @busy_users[user_name] = user else raise "out of users!!" end @logger.debug "alloc()'d user #{user_name}" user end |
#free_user(user) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/vcap/user_pools/user_pool.rb', line 31 def free_user(user) user_name = user[:user_name] if @busy_users.has_key?(user_name) VCAP::Subprocess.run("pkill -9 -u #{user_name}", 1) @busy_users.delete(user_name) @free_users[user_name] = user @logger.debug "free()'d user #{user_name}" else raise "invalid free user: #{user_name}" end end |