Changeset 15634 for lang

Show
Ignore:
Timestamp:
07/10/08 18:25:21 (6 years ago)
Author:
daisuke
Message:

Allow clients to configure KeyedMutex?

Files:
1 modified

Legend:

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

    r15633 r15634  
    3131; 
    3232 
     33class_type 'KeyedMutex'; 
     34 
     35coerce 'KeyedMutex' 
     36    => from 'HashRef' 
     37        => via { 
     38            my $h = $_; 
     39            KeyedMutex->new($h->{args}); 
     40        } 
     41; 
     42 
    3343has 'memcached' => ( 
    3444    is       => 'rw', 
     
    4050has 'mutex' => ( 
    4151    is => 'rw', 
    42     isa => 'Maybe[KeyedMutex]', 
     52    isa => 'KeyedMutex', 
     53    coerce => 1, 
    4354); 
    4455 
     
    4859    my $self = shift; 
    4960 
    50     my $mutex = eval { KeyedMutex->new }; 
    51     if ($mutex) { 
    52         $self->mutex($mutex); 
    53     } else { 
    54         warn $@; 
     61    # if no keyedmutex was provided explicitly, we attempt to create one 
     62    # however, if the creation of this object fails, well, we can go 
     63    # without it in degraded mode 
     64    if ( ! $self->mutex ) { 
     65        my $mutex = eval {KeyedMutex->new }; 
     66        if ($mutex) { 
     67            $self->mutex($mutex); 
     68        } else { 
     69            warn $@; 
     70        } 
    5571    } 
    5672} 
     
    100116Data::Valve::BucketStore::Memcached - Memcached Backend 
    101117 
     118=head1 DESCRIPTION 
     119 
     120Data::Valve::BucketStore::Memcached uses Memcached as its storage backend, 
     121and allows multiple processes to work together. 
     122 
     123This module also provides locking mechanism by means of KeyedMutex. 
     124You should specify one at construction time: 
     125 
     126  Data::Valve->new( 
     127    bucket_store => { 
     128      module => "Memcached", 
     129      args   => { 
     130        mutex => { 
     131          args => { 
     132            sock => "host:port" # <-- here 
     133          } 
     134        } 
     135      } 
     136    } 
     137  ); 
     138 
     139This allows all coordinating processes to share the same mutex, and you will 
     140get "correct" throttling information 
     141 
    102142=head1 METHODS 
    103143