AnyEvent-ConnPool

 view release on metacpan or  search on metacpan

lib/AnyEvent/ConnPool.pm  view on Meta::CPAN

288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
if (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

339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# 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

435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
use strict;
 
sub new {
    my ($class, $object, %opts) = @_;
 
    my ($index, $constructor) = ($opts{index}, $opts{constructor});
 
    my $unit = {
        _conn           =>  $object,
        _locked         =>  0,
        _index          =>  $index,
        _constructor    =>  $constructor,
    };
 
    bless $unit, $class;
    return $unit;
}
 
 
=item B<conn>

lib/AnyEvent/ConnPool.pm  view on Meta::CPAN

469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
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();
 
=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 )