AnyEvent-ConnPool
view release on metacpan or search on metacpan
lib/AnyEvent/ConnPool.pm view on Meta::CPAN
288289290291292293294295296297298299300301302303304305306307308309310311312313if
(
defined
$index
) {
return
$self
->{_payload}->[
$index
];
}
if
(
$self
->{
index
} + 1 >
$self
->{count}) {
$self
->{
index
} = 0;
}
my
$retval
=
$self
->{_payload}->[
$self
->{
index
}];
if
(
$retval
->locked()) {
$self
->{locked}->{
$self
->{
index
}} = 1;
$retval
=
$self
->get_free_connection(
$self
->{
index
});
}
else
{
delete
$self
->{locked}->{
$self
->{
index
}};
}
if
(
wantarray
) {
$self
->{
index
}++;
return
(
$index
,
$retval
);
}
else
{
$self
->{
index
}++;
return
$retval
;
}
lib/AnyEvent/ConnPool.pm view on Meta::CPAN
339340341342343344345346347348349350351352353354355356357# utility functions
sub
get_free_connection {
my
(
$self
,
$desired_index
) =
@_
;
my
$retval
=
undef
;
my
@balanced_array
=
$self
->balance_array(
$desired_index
);
for
my
$i
(
@balanced_array
) {
my
$conn
=
$self
->{_payload}->[
$i
];
unless
(
$conn
->locked) {
$retval
=
$conn
;
$self
->{
index
} =
$i
;
last
;
}
}
return
$retval
;
}
lib/AnyEvent/ConnPool.pm view on Meta::CPAN
435436437438439440441442443444445446447448449450451452453454455
lib/AnyEvent/ConnPool.pm view on Meta::CPAN
469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523Locks current connection. After that connection shouldn't be used in balancing mechanism and never will be
$connection
->
lock
();
=cut
sub lock {
my ($self) = @_;
$self->{_locked} = 1;
return 1;
}
=item B<unlock>
Unlocks connection and returns it to the balancing scheme.
$connection->unlock();
=cut
sub
unlock {
my
(
$self
) =
@_
;
delete
$self
->{_locked};
return
1;
}
=item B<locked>
Returns true if connection is locked.
if ($connection->locked()) {
...
}
=cut
sub
locked {
my
(
$self
) =
@_
;
return
$self
->{_locked};
}
sub
index
{
my
(
$self
) =
@_
;
return
$self
->{_index};
}
sub
reconnect {
( run in 0.239 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )