Class: Farce::Abstract::LeasePool Abstract
- Inherits:
-
Object
- Object
- Farce::Abstract::LeasePool
- Includes:
- Internal::Noncopyable, Internal::Inspect
- Defined in:
- lib/farce/abstract/lease_pool.rb
Overview
Shared checkout, return, ownership, and capacity behavior for resource pools.
Direct Known Subclasses
LeasePool, Local::LeasePool, Strict::LeasePool, Unshared::LeasePool
Instance Attribute Summary collapse
-
#max_size ⇒ Integer
readonly
The configured capacity.
Instance Method Summary collapse
-
#available_count ⇒ Integer
Resources ready for checkout.
-
#checked_out_count ⇒ Integer
Resources currently checked out.
-
#checkin(resource) ⇒ self
Return an explicitly checked-out resource, a replacement, or nil to delete its slot.
-
#checkout(timeout: nil) {|resource| ... } ⇒ BasicObject
Acquire a resource, waiting for availability or creation capacity.
-
#creating_count ⇒ Integer
Capacity reserved by in-progress factory calls.
-
#initialize(max_size:) { ... } ⇒ LeasePool
constructor
Construct an empty pool whose resources are created on demand.
-
#size ⇒ Integer
Managed resources, excluding in-progress factory calls.
-
#try_checkout {|resource| ... } ⇒ BasicObject?
Acquire an available resource or create one without waiting for capacity.
Methods included from Internal::Noncopyable
Constructor Details
#initialize(max_size:) { ... } ⇒ LeasePool
Construct an empty pool whose resources are created on demand.
17 18 19 20 21 22 23 |
# File 'lib/farce/abstract/lease_pool.rb', line 17 def initialize(max_size:, &factory) validate_configuration!(max_size, factory) @max_size = Integer(max_size) @factory = prepare_factory(factory) @pool = new_internal_pool(max_size) super() end |
Instance Attribute Details
#max_size ⇒ Integer (readonly)
Returns the configured capacity.
54 55 56 |
# File 'lib/farce/abstract/lease_pool.rb', line 54 def max_size @max_size end |
Instance Method Details
#available_count ⇒ Integer
Returns resources ready for checkout.
60 |
# File 'lib/farce/abstract/lease_pool.rb', line 60 def available_count = internal_pool.available_count |
#checked_out_count ⇒ Integer
Returns resources currently checked out.
63 |
# File 'lib/farce/abstract/lease_pool.rb', line 63 def checked_out_count = internal_pool.checked_out_count |
#checkin(resource) ⇒ self
Return an explicitly checked-out resource, a replacement, or nil to delete its slot.
48 49 50 51 |
# File 'lib/farce/abstract/lease_pool.rb', line 48 def checkin(resource) internal_pool.checkin(resource) self end |
#checkout(timeout: nil) {|resource| ... } ⇒ BasicObject
Acquire a resource, waiting for availability or creation capacity.
30 31 32 33 |
# File 'lib/farce/abstract/lease_pool.rb', line 30 def checkout(timeout: nil, &block) pool = internal_pool block ? pool.checkout(@factory, timeout:, &block) : pool.checkout(@factory, timeout:) end |
#creating_count ⇒ Integer
Returns capacity reserved by in-progress factory calls.
66 |
# File 'lib/farce/abstract/lease_pool.rb', line 66 def creating_count = internal_pool.creating_count |
#size ⇒ Integer
Returns managed resources, excluding in-progress factory calls.
57 |
# File 'lib/farce/abstract/lease_pool.rb', line 57 def size = internal_pool.size |
#try_checkout {|resource| ... } ⇒ BasicObject?
Acquire an available resource or create one without waiting for capacity.
38 39 40 41 |
# File 'lib/farce/abstract/lease_pool.rb', line 38 def try_checkout(&block) pool = internal_pool block ? pool.try_checkout(@factory, &block) : pool.try_checkout(@factory) end |