| 1 | package DBIO::Async::Pool; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Generic async connection pool for DBIO drivers | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 44 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 44 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 44 | our $VERSION = '0.900007'; | |||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 44 | ▶ | use base 'DBIO::Storage::PoolBase'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 44 | ▶ | use Carp 'croak'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 44 | ▶ | use Scalar::Util (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 44 | ▶ | use DBIO::Async::Future; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 44 | ▶ | use namespace::clean; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 313 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 313 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 20 | 313 | ▶ | croak('storage required') unless $args{storage}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | # Handed on to core: it reads the pool's limits (acquire_timeout, max_waiters, | ||||||||||||||||||||||||||||
| 23 | # reset_timeout) off the storage, and keeps the reference weak. | ||||||||||||||||||||||||||||
| 24 | 313 | return $class->SUPER::new(%args); | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 383 | ▶ | sub _connection_ready_future { | ||||||||||||||||||||||||||
|
Subroutine
_connection_ready_future: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | 383 | my ($self, $conn) = @_; | |||||||||||||||||||||||||||
| 30 | 383 | return $self->_await_conn_ready($conn); | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 383 | ▶ | sub _await_conn_ready { | ||||||||||||||||||||||||||
|
Subroutine
_await_conn_ready: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 35 | 383 | my ($self, $conn) = @_; | |||||||||||||||||||||||||||
| 36 | # No `use Future` in this file on purpose: DBIO::Storage::PoolBase::new | ||||||||||||||||||||||||||||
| 37 | # require()s whatever future_class names, so the CONFIGURED class -- not just | ||||||||||||||||||||||||||||
| 38 | # the default -- is loaded before any instance method can run. | ||||||||||||||||||||||||||||
| 39 | 383 | ▶ | return $self->future_class->done($conn) unless $self->{storage}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 382 | return $self->{storage}->_await_conn_ready($conn); | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 60 | ▶ | sub _idle_connection_alive { | ||||||||||||||||||||||||||
|
Subroutine
_idle_connection_alive: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 45 | 60 | my ($self, $conn) = @_; | |||||||||||||||||||||||||||
| 46 | 60 | ▶ | return 1 unless $self->{storage}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 58 | return $self->{storage}->_idle_connection_alive($conn); | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 29 | ▶ | sub _new_waiter { | ||||||||||||||||||||||||||
|
Subroutine
_new_waiter: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 52 | 29 | my ($self) = @_; | |||||||||||||||||||||||||||
| 53 | 29 | return DBIO::Async::Future->new->mark_pool_wait($self); | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 315 | ▶ | sub _create_connection { | ||||||||||||||||||||||||||
|
Subroutine
_create_connection: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||
| 58 | 315 | my ($self, $conninfo) = @_; | |||||||||||||||||||||||||||
| 59 | 315 | ▶ | croak 'Storage reference lost; cannot create connection' unless $self->{storage}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 315 | return $self->{storage}->_create_pool_connection($conninfo); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 269 | ▶ | sub _shutdown_connection { | ||||||||||||||||||||||||||
|
Subroutine
_shutdown_connection: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 65 | 269 | my ($self, $conn) = @_; | |||||||||||||||||||||||||||
| 66 | 269 | ▶ | return unless $self->{storage}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 268 | $self->{storage}->_abandon_flights_on($conn); | |||||||||||||||||||||||||||
| 68 | 268 | $self->{storage}->_shutdown_pool_connection($conn); | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 69 | ▶ | sub _retire_connection { | ||||||||||||||||||||||||||
|
Subroutine
_retire_connection: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 73 | 69 | my ($self, $conn) = @_; | |||||||||||||||||||||||||||
| 74 | 69 | $self->SUPER::_retire_connection($conn); | |||||||||||||||||||||||||||
| 75 | # The pool's own flag: during shutdown the pool fails its callers with its | ||||||||||||||||||||||||||||
| 76 | # own reason and cancels the chain on the readiness Future itself. | ||||||||||||||||||||||||||||
| 77 | 69 | ▶ | $self->{storage}->_ready_end($conn) if $self->{storage} && !$self->{_shutdown}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"storage"} and not $self->{"_shutdown"}
MC/DC50%1/2
$self->{"storage"} and not $self->{"_shutdown"}
$self->{"storage"}
not $self->{"_shutdown"}
Truth table66%2/3
A and not(B)
A= $self->{"storage"}B= not $self->{"_shutdown"}
| |||||||||||||||||||||||||||||
| 78 | 69 | return; | |||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 44 | 1; | |||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | __END__ | ||||||||||||||||||||||||||||