AnyEvent::ConnPool
Simple connections pool designed for asynchronous connections
Returns new pool object
AnyEvent::ConnPool->new( constructor => sub { return generate_connection(); }, check => { cb => sub { my $connection = shift; ... if ($connection->conn()->ping()) { return 1; } return 0; }, interval => 10, }, size => 5, init => 1, );
constructor => subroutine, which generates connection for pool.
check => pingers, allows to specify methods and interval for connection state validation. check->{cb} => callback, used for ping connection. You should implement this logic by yourself. If you need reconnect, you can just call
$connection->reconnect();
check->{interval} => interval for the callback.
size => how many connections should be created on pool initialization.
init => initialize connections on pool construction.
Initializes pool.
Adds connection to the pool.
Returns AnyEvent::ConnPool::Unit object from the pool.
my $unit = $pool->get(); my $connection = $unit->conn();
AnyEvent::ConnPool::Unit
Connection unit. Just wrapper around user-specified connection. Required for transactions support.
Returns connection from unit object.
Locks current connection. After that connection shouldn't be used in balancing mechanism and never will be returned from pool. To unlock connection you should use unlock method.
$connection->lock();
Unlocks connection and returns it to the balancing scheme.
$connection->unlock();
Returns true if connection is locked.
if ($connection->locked()) { ... }
To install AnyEvent::ConnPool, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::ConnPool
CPAN shell
perl -MCPAN -e shell install AnyEvent::ConnPool
For more information on module installation, please visit the detailed CPAN module installation guide.