NAME

POE::Component::ResourcePool::Resource::Collection - A collection of valeus to be shared (e.g. handles).

SYNOPSIS

use POE::Component::ResourcePool::Resource::Collection;

my $collection = POE::Component::ResourcePool::Resource::Collection->new(
	values => [ $handle1, $handle2, $handle3 ],
);

# ...

my $pool = POE::Component::ResourcePool->new(
	resources => {
		handles => $collection,
	},
);

$pool->request(
	params => {
		handles => $how_many,
	},
	...
);

DESCRIPTION

This resource allows the sharing of values from a collection in a round the robin fashion.

It is useful for e.g. limiting the number of database handles to a certain bound, but unlike the semaphore will pool the actual values instead of just counting.

The parameter to the request can be a number denoting how many values are required, with 1 being the default.

Unlike the semaphore resource could_allocate is not strict, and will always return true even if the count is bigger than the initial value list's size. This is to facilitate editing of the value collection array yourself.

If you modify the values attribute be sure to call notify_all_pools in order to check for potentially affected requests.

Note that you cannot reliably remove values from the values array because currently allocated values are not found in the list, but will be added later.

Subclassing this class with additional value tracking semantics should help alleviate any issues due to this.

METHODS

try_allocating

If there are enough values in values to satisfy the count (defaults to 1) then these items are return.

Otherwise allocation will fail.

finalize_allocation

Splices the allocated values out of the values array.

free_allocation

Pushes the allocated values to the end of the values array.

ATTRIBUTES

values

An array reference of values to be allocated.

Duplicate values are treated as separate values, and will not be checked for (this is a feature).