using implicit connect with "method_lookup" style calls;fixing "max_requests" state...
authormiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 25 Jul 2005 13:42:15 +0000 (13:42 +0000)
committermiker <miker@9efc2488-bf62-4759-914b-345cdb29e865>
Mon, 25 Jul 2005 13:42:15 +0000 (13:42 +0000)
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@423 9efc2488-bf62-4759-914b-345cdb29e865

src/perlmods/OpenSRF/AppSession.pm
src/perlmods/OpenSRF/Application.pm
src/perlmods/OpenSRF/DomainObject/oilsMessage.pm

index 891387d..7762322 100644 (file)
@@ -726,8 +726,7 @@ sub recv {
 
        if( exists( $args{timeout} ) ) {
                $args{timeout} = int($args{timeout});
-       } else {
-               $args{timeout} = 10;
+               $self->{recv_timeout} = $args{timeout};
        }
 
        #$args{timeout} = 0 if ($self->complete);
@@ -737,14 +736,18 @@ sub recv {
        $args{count} ||= 1;
 
        my $avail = @{ $self->{recv_queue} };
-       my $time_remaining = $args{timeout};
+       $self->{remaining_recv_timeout} = $self->{recv_timeout};
 
-       while ( $avail < $args{count} and $time_remaining > 0 ) {
+       while ( $self->{remaining_recv_timeout} > 0 and $avail < $args{count} ) {
                last if $self->complete;
                my $starttime = time;
-               $self->queue_wait($time_remaining);
+               $self->queue_wait($self->{remaining_recv_timeout});
                my $endtime = time;
-               $time_remaining -= ($endtime - $starttime);
+               if ($self->{timeout_reset}) {
+                       $self->{timeout_reset} = 0;
+               } else {
+                       $self->{remaining_recv_timeout} -= ($endtime - $starttime)
+               }
                $avail = @{ $self->{recv_queue} };
        }
 
@@ -806,6 +809,14 @@ sub status {
        $self->send( 'STATUS', @_ );
 }
 
+sub reset_request_timeout {
+       my $self = shift;
+       my $tt = shift;
+       my $req = $self->app_request($tt);
+       $req->{remaining_recv_timeout} = $req->{recv_timeout};
+       $req->{timout_reset} = 1;
+}
+
 #-------------------------------------------------------------------------------
 
 package OpenSRF::AppRequest;
@@ -821,11 +832,14 @@ sub new {
        my $threadTrace = $session->session_threadTrace || $session->last_threadTrace;
        my $payload = shift;
        
-       my $self = {    session     => $session,
-                       threadTrace => $threadTrace,
-                       payload     => $payload,
-                       complete    => 0,
-                       recv_queue  => [],
+       my $self = {    session                 => $session,
+                       threadTrace             => $threadTrace,
+                       payload                 => $payload,
+                       complete                => 0,
+                       timeout_reset           => 0,
+                       recv_timeout            => 30,
+                       remaining_recv_timeout  => 30,
+                       recv_queue              => [],
        };
 
        bless $self => $class;
index 128a947..409b780 100644 (file)
@@ -440,7 +440,7 @@ sub run {
        } else {
                my $session = OpenSRF::AppSession->create($self->{server_class});
                try {
-                       $session->connect or OpenSRF::EX::WARN->throw("Connection to [$$self{server_class}] timed out");
+                       #$session->connect or OpenSRF::EX::WARN->throw("Connection to [$$self{server_class}] timed out");
                        my $remote_req = $session->request( $self->{api_name}, @params );
                        while (my $remote_resp = $remote_req->recv) {
                                OpenSRF::Utils::Logger->debug("Remote Subrequest Received " . $remote_resp, INTERNAL );
@@ -450,8 +450,6 @@ sub run {
                                $req->respond( $remote_resp->content );
                        }
                        $remote_req->finish();
-                       $session->disconnect();
-                       $session->finish();
 
                } catch Error with {
                        my $e = shift;
@@ -459,6 +457,11 @@ sub run {
                        return undef;
                };
 
+               if ($session) {
+                       $session->disconnect();
+                       $session->finish();
+               }
+
                $log->debug( "Remote Subrequest Responses " . join(" ", $req->responses), INTERNAL );
 
                return $req->responses;
index f6edbc8..e599f6e 100644 (file)
@@ -256,6 +256,7 @@ sub do_client {
                if ($self->payload->statusCode == STATUS_TIMEOUT) {
                        $session->state( $session->DISCONNECTED );
                        $session->reset;
+                       $session->connect;
                        $session->push_resend( $session->app_request($self->threadTrace) );
                        $log->debug("Disconnected because of timeout", WARN);
                        return 0;
@@ -263,6 +264,7 @@ sub do_client {
                } elsif ($self->payload->statusCode == STATUS_REDIRECTED) {
                        $session->state( $session->DISCONNECTED );
                        $session->reset;
+                       $session->connect;
                        $session->push_resend( $session->app_request($self->threadTrace) );
                        $log->debug("Disconnected because of redirect", WARN);
                        return 0;
@@ -275,6 +277,7 @@ sub do_client {
                        return 0;
 
                } elsif ($self->payload->statusCode == STATUS_CONTINUE) {
+                       $session->reset_request_timeout($self->threadTrace);
                        return 0;
 
                } elsif ($self->payload->statusCode == STATUS_COMPLETE) {