Changeset 15788 for lang/perl/Data-Valve

Show
Ignore:
Timestamp:
07/14/08 15:49:12 (5 years ago)
Author:
daisuke
Message:

refactor where the lock mechanism is

Location:
lang/perl/Data-Valve/trunk/lib/Data/Valve/BucketStore
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Data-Valve/trunk/lib/Data/Valve/BucketStore/Memcached.pm

    r15787 r15788  
    3232    coerce   => 1, 
    3333    required => 1, 
     34    default  => sub { 
     35        Class::MOP::load_class('Cache::Memcached'); 
     36        Cache::Memcached->new({ 
     37            servers => [ '127.0.0.1:11211' ] 
     38        }); 
     39    } 
    3440); 
    3541 
  • lang/perl/Data-Valve/trunk/lib/Data/Valve/BucketStore/Object.pm

    r15787 r15788  
    2929    my $key = $args{key}; 
    3030 
    31     my $mutex = $self->mutex; 
    32  
    3331    my $rv; 
    3432    my $done = 0; 
    3533    my $store = $self->store; 
    3634    while ( ! $done) { 
    37         my $lock = $mutex ? $mutex->lock($key, 1) : 1; 
     35        my $lock = $self->lock($key); 
    3836        next unless $lock; 
    3937 
  • lang/perl/Data-Valve/trunk/lib/Data/Valve/BucketStore/WithKeyedMutex.pm

    r15787 r15788  
    2828    my $self = shift; 
    2929 
    30  
    3130    # if no keyedmutex was provided explicitly, we attempt to create one 
    3231    # however, if the creation of this object fails, well, we can go 
     
    4241} 
    4342 
     43sub lock { 
     44    my ($self, $key) = @_; 
     45 
     46    my $mutex = $self->mutex; 
     47    return 1 unless $mutex; 
     48    my $rv = eval { $mutex->lock($key, 1) }; 
     49    # if in case an error has been reported, we should ditch the mutex, 
     50    # cause it will keep giving errors (or worse yet, crash) 
     51    if ($@) { 
     52        $self->mutex(undef); 
     53    } 
     54    return $rv; 
     55} 
     56 
    44571;