This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "Tarantool -- an efficient key/value data store".

The branch perl-iproto-async has been updated
       via  ea0c26ce0de81b8679f10dddd5bc0fadcd68c821 (commit)
      from  dcd96041dd75581e666390a55c769d29a556f579 (commit)

Summary of changes:
 mod/silverbox/client/perl/lib/MR/IProto.pm         |   16 ++++--
 mod/silverbox/client/perl/lib/MR/IProto/Message.pm |   60 --------------------
 mod/silverbox/client/perl/lib/MR/IProto/Request.pm |   33 +++++++++--
 .../client/perl/lib/MR/IProto/Response.pm          |   40 +++++++++++++-
 4 files changed, 77 insertions(+), 72 deletions(-)

commit ea0c26ce0de81b8679f10dddd5bc0fadcd68c821
Author: Aleksey Mashanov <[email protected]>
Date:   Fri Dec 10 15:34:05 2010 +0300

    Retry functionality for hash-api and some optimization of object-api

diff --git a/mod/silverbox/client/perl/lib/MR/IProto.pm 
b/mod/silverbox/client/perl/lib/MR/IProto.pm
index c6db967..4a4d267 100644
--- a/mod/silverbox/client/perl/lib/MR/IProto.pm
+++ b/mod/silverbox/client/perl/lib/MR/IProto.pm
@@ -507,11 +507,12 @@ sub _send_now {
     my $args;
     # MR::IProto::Message OO-API
     if( ref $message ne 'HASH' ) {
-        my $response_class = $self->_reply_class->{$message->msg};
-        die sprintf "Cannot find response class for message code %d\n", 
$message->msg unless $response_class;
+        my $msg = $message->msg;
+        my $response_class = $self->_reply_class->{$msg};
+        die sprintf "Cannot find response class for message code %d\n", $msg 
unless $response_class;
         $args = {
             request        => $message,
-            msg            => $message->msg,
+            msg            => $msg,
             key            => $message->key,
             body           => $message->data,
             response_class => $response_class,
@@ -578,7 +579,9 @@ sub _server_callback {
     eval {
         if ($error) {
             $self->_debug("send: failed") if $self->debug >= 2;
-            my $retry = defined $args->{request} ? $args->{request}->retry() : 
$args->{retry};
+            my $retry = defined $args->{request} ? $args->{request}->retry()
+                : ref $args->{retry} eq 'CODE' ? $args->{retry}->()
+                : $args->{retry};
             if( $retry && $$try++ < $self->max_request_retries ) {
                 $self->_send_retry($sync, $args, $$handler, $$try);
             }
@@ -603,6 +606,9 @@ sub _server_callback {
                 if( defined $args->{request} && $data->retry && $$try++ < 
$self->max_request_retries ) {
                     $self->_send_retry($sync, $args, $$handler, $$try);
                 }
+                elsif( defined $args->{is_retry} && $args->{is_retry}->($data) 
&& $$try++ < $self->max_request_retries ) {
+                    $self->_send_retry($sync, $args, $$handler, $$try);
+                }
                 else {
                     undef $$handler;
                     $self->_finish_and_start() unless $sync;
@@ -624,7 +630,7 @@ sub _server_callback {
 
 sub _report_error {
     my ($self, $request, $callback, $error, $sync) = @_;
-    my $errobj = $request
+    my $errobj = defined $request && ref $request ne 'HASH'
         ? MR::IProto::Error->new(
             request => $request,
             error   => $error,
diff --git a/mod/silverbox/client/perl/lib/MR/IProto/Message.pm 
b/mod/silverbox/client/perl/lib/MR/IProto/Message.pm
index 8fb2663..2282378 100644
--- a/mod/silverbox/client/perl/lib/MR/IProto/Message.pm
+++ b/mod/silverbox/client/perl/lib/MR/IProto/Message.pm
@@ -25,70 +25,10 @@ Binary representation of message data.
 has data => (
     is  => 'ro',
     isa => 'Value',
-    lazy_build => 1,
 );
 
 =back
 
-=head1 PROTECTED METHODS
-
-=over
-
-=item BUILDARGS( %args | \%args | $data )
-
-If C<$data> is passed as argument then it unpacked and object is
-created based on information contained in it.
-
-See L<Mouse::Manual::Construction/BUILDARGS> for more information.
-
-=cut
-
-around BUILDARGS => sub {
-    my $orig = shift;
-    my $class = shift;
-    my $args = @_ == 1 ? $_[0] : { @_ };
-    if( exists $args->{data} ) {
-        my $parsed_args = $class->_parse_data($args->{data});
-        my $tail = delete $parsed_args->{data};
-        warn "Not all data was parsed" if defined $tail && length $tail;
-        @$args{ keys %$parsed_args } = values %$parsed_args;
-        return $class->$orig($args);
-    }
-    else {
-        return $class->$orig(@_);
-    }
-};
-
-=item key_attr
-
-Class method which must return name of key attribute.
-
-=item _build_data
-
-You B<must> implement this method in you subclass to pack your object.
-Returns packed data.
-
-=cut
-
-sub _build_data {
-    my ($self) = @_;
-    return '';
-}
-
-=item _parse_data( $data )
-
-You B<must> implement this method in you subclass to unpack your object.
-Returns hashref of attributes which will be passed to constructor.
-
-=cut
-
-sub _parse_data {
-    my ($class, $data) = @_;
-    return { data => $data };
-}
-
-=back
-
 =head1 SEE ALSO
 
 L<MR::IProto>.
diff --git a/mod/silverbox/client/perl/lib/MR/IProto/Request.pm 
b/mod/silverbox/client/perl/lib/MR/IProto/Request.pm
index f81227c..5c86e58 100644
--- a/mod/silverbox/client/perl/lib/MR/IProto/Request.pm
+++ b/mod/silverbox/client/perl/lib/MR/IProto/Request.pm
@@ -13,6 +13,10 @@ Base class for all request messages.
 use Mouse;
 extends 'MR::IProto::Message';
 
+has '+data' => (
+    lazy_build => 1,
+);
+
 =head1 PUBLIC METHODS
 
 =over
@@ -20,15 +24,12 @@ extends 'MR::IProto::Message';
 =item key
 
 Returns key value.
-You must implement L</key_attr> method in your subclass to use this feature.
+You must reimplement this method in your subclass to use this feature.
 
 =cut
 
 sub key {
-    my ($self) = @_;
-    return undef unless $self->can('key_attr');
-    my $method = $self->key_attr;
-    return $self->$method();
+    return undef;
 }
 
 =item retry
@@ -38,12 +39,32 @@ If request retry is allowed.
 =cut
 
 sub retry {
-    my ($self) = @_;
     return 0;
 }
 
 =back
 
+=head1 PROTECTED METHODS
+
+=over
+
+=item key_attr
+
+Class method which must return name of key attribute.
+
+=item _build_data
+
+You B<must> implement this method in you subclass to pack your object.
+Returns packed data.
+
+=cut
+
+sub _build_data {
+    return '';
+}
+
+=back
+
 =cut
 
 no Mouse;
diff --git a/mod/silverbox/client/perl/lib/MR/IProto/Response.pm 
b/mod/silverbox/client/perl/lib/MR/IProto/Response.pm
index eca33f8..4908853 100644
--- a/mod/silverbox/client/perl/lib/MR/IProto/Response.pm
+++ b/mod/silverbox/client/perl/lib/MR/IProto/Response.pm
@@ -42,12 +42,50 @@ Is request retry must be done.
 =cut
 
 sub retry {
-    my ($self) = @_;
     return 0;
 }
 
 =back
 
+=head1 PROTECTED METHODS
+
+=over
+
+=item BUILDARGS( %args | \%args | $data )
+
+If C<$data> is passed as argument then it unpacked and object is
+created based on information contained in it.
+
+See L<Mouse::Manual::Construction/BUILDARGS> for more information.
+
+=cut
+
+around BUILDARGS => sub {
+    my ($orig, $class, %args) = @_;
+    if( exists $args{data} ) {
+        my $parsed_args = $class->_parse_data($args{data});
+        my $tail = delete $parsed_args->{data};
+        warn "Not all data was parsed" if defined $tail && length $tail;
+        return $class->$orig(%$parsed_args, %args);
+    }
+    else {
+        return $class->$orig(%args);
+    }
+};
+
+=item _parse_data( $data )
+
+You B<must> implement this method in you subclass to unpack your object.
+Returns hashref of attributes which will be passed to constructor.
+
+=cut
+
+sub _parse_data {
+    return { data => $_[1] };
+}
+
+=back
+
 =cut
 
 no Mouse;

-- 
Tarantool -- an efficient key/value data store

_______________________________________________
Mailing list: https://launchpad.net/~tarantool-developers
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~tarantool-developers
More help   : https://help.launchpad.net/ListHelp

Reply via email to