root/lang/perl/Data-Valve/trunk/lib/Data/Valve/BucketStore/WithKeyedMutex.pm @ 15787

Revision 15787, 0.8 kB (checked in by daisuke, 5 years ago)

Refactor main non-memory throttling from memcached.pm

  • Property svn:keywords set to Id
Line 
1# $Id$
2
3package Data::Valve::BucketStore::WithKeyedMutex;
4use Moose::Role;
5use Moose::Util::TypeConstraints;
6
7use KeyedMutex;
8
9class_type 'KeyedMutex';
10
11coerce 'KeyedMutex'
12    => from 'HashRef'
13        => via {
14            my $h = $_;
15            KeyedMutex->new($h->{args});
16        }
17;
18
19has 'mutex' => (
20    is => 'rw',
21    isa => 'KeyedMutex',
22    coerce => 1,
23);
24
25no Moose;
26
27sub BUILD {
28    my $self = shift;
29
30
31    # if no keyedmutex was provided explicitly, we attempt to create one
32    # however, if the creation of this object fails, well, we can go
33    # without it in degraded mode
34    if ( ! $self->mutex ) {
35        my $mutex = eval {KeyedMutex->new };
36        if ($mutex) {
37            $self->mutex($mutex);
38        } else {
39            warn $@;
40        }
41    }
42}
43
441;
Note: See TracBrowser for help on using the browser.