MongoDBx::Class::ConnectionPool::Backup3pm
A simple connection pool with a backup connection
Usage
# create a MongoDBx::Class object normally:use MongoDBx::Class;my $dbx = MongoDBx::Class->new(namespace => 'MyApp::Model::DB');# instead of connection, create a poolmy $pool = $dbx->pool(max_conns => 200, type => 'backup'); # max_conns defaults to 100# or, if you need to pass attributes to MongoDB::Connection->new():my $pool = $dbx->pool(max_conns => 200, type => 'backup', params => {host => $host,username => $username,password => $password,});# get a connection from the pool on a per-request basismy $conn = $pool->get_conn;# ... do stuff with $conn and return it when done ...$pool->return_conn($conn);
Version
version 1.030002
Overview
MongoDBx::Class::ConnectionPool::Backup is an implementation of the MongoDBx::Class::ConnectionPool Moose role. In this implementation, the pool has a maximum number of connections. Whenever someone makes a request for a connection, an existing connection is taken out of the pool and returned (or created if none are available and the maximum has not been reached). When the requester is done with the connection, they are expected to return the connection to the pool. If a connection is not available for the requester (i.e. the maximum has been reached and all connections are used), a backup connection is returned. This backup connection can be shared by multiple requesters, but the pool's main connections cannot.
This pool is most appropriate for larger pools where you do not wish to share connections between clients, but want to ensure that on the rare occasions that all connections are used, requests will still be honored.
Consumes
MongoDBx::Class::ConnectionPool
Attributes
The following attributes are added:
backup_conn
The backup MongoDBx::Class::Connection object.
Methods
get_conn()
Returns a connection from the pool to a requester. If a connection is not available but the maximum has not been reached, a new connection is made, otherwise the backup connection is returned.
return_conn( $conn )
Returns a connection to the pool. If a client attempts to return the backup connection, nothing will happen (the backup connection is always saved).
Internal methods
Build()
Called by Moose after object initiation.
Support
You can find documentation for this module with the perldoc command.
perldoc MongoDBx::Class::ConnectionPool::Backup
You can also look for information at:
- •
-
RT: CPAN's request tracker
<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MongoDBx::Class>
- •
-
AnnoCPAN: Annotated CPAN documentation
<http://annocpan.org/dist/MongoDBx::Class>
- •
-
CPAN Ratings
<http://cpanratings.perl.org/d/MongoDBx::Class>
- •
-
Search CPAN
<http://search.cpan.org/dist/MongoDBx::Class/>
License and copyright
Copyright 2010-2014 Ido Perlmuter.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.