| 1 | # $Id$ | ||
| 2 | |||
| 3 | package Mvalve::Queue::Q4M; | ||
| 4 | 1 | ▶ | use Moose; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 0 | ▶ | use Queue::Q4M; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 6 | |||
| 7 | with 'Mvalve::Queue'; | ||
| 8 | |||
| 9 | has 'connect_info' => ( | ||
| 10 | is => 'rw', | ||
| 11 | isa => 'ArrayRef', | ||
| 12 | required => 1 | ||
| 13 | ); | ||
| 14 | |||
| 15 | has 'q4m' => ( | ||
| 16 | is => 'rw', | ||
| 17 | isa => 'Queue::Q4M', | ||
| 18 | handles => { | ||
| 19 | map { ("q_$_" => $_) } | ||
| 20 | qw( fetch_hashref ) | ||
| 21 | } | ||
| 22 | ); | ||
| 23 | |||
| 24 | __PACKAGE__->meta->make_immutable; | ||
| 25 | |||
| 26 | no Moose; | ||
| 27 | |||
| 28 | sub BUILD { | ||
| 29 | my $self = shift; | ||
| 30 | $self->q4m( | ||
| 31 | Queue::Q4M->connect( connect_info => $self->connect_info ) | ||
| 32 | ); | ||
| 33 | $self; | ||
| 34 | } | ||
| 35 | |||
| 36 | sub next { | ||
| 37 | my ($self, %args) = @_; | ||
| 38 | my $table_conds = $args{table_conds}; | ||
| 39 | if (! $table_conds) { | ||
| 40 | return (); | ||
| 41 | } | ||
| 42 | |||
| 43 | my @args = @$table_conds; | ||
| 44 | if ($args{timeout} > 0) { | ||
| 45 | push @args, $args{timeout}; | ||
| 46 | } | ||
| 47 | return $self->q4m->next(@args); | ||
| 48 | } | ||
| 49 | |||
| 50 | sub fetch { | ||
| 51 | my ($self, %args) = @_; | ||
| 52 | |||
| 53 | my $table = $args{table}; | ||
| 54 | my $args = $args{args}; | ||
| 55 | |||
| 56 | my $cols = $self->q_fetch_hashref( $table, $args ); | ||
| 57 | if (! $cols) { | ||
| 58 | return (); | ||
| 59 | } | ||
| 60 | |||
| 61 | return Mvalve::Message->deserialize( $cols->{message} ); | ||
| 62 | } | ||
| 63 | |||
| 64 | sub insert { | ||
| 65 | my ($self, %args) = @_; | ||
| 66 | $self->q4m->insert( $args{table}, $args{data} ); | ||
| 67 | } | ||
| 68 | |||
| 69 | sub clear { shift->q4m->clear(@_) } | ||
| 70 | |||
| 71 | |||
| 72 | 1; | ||
| 73 | |||
| 74 | __END__ | ||