]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/perlmods/OpenSRF/AppSession.pm
8aa275f5d8e421bf79f01db937f319e853150d13
[OpenSRF.git] / src / perlmods / OpenSRF / AppSession.pm
1 package OpenSRF::AppSession;
2 use OpenSRF::DOM;
3 #use OpenSRF::DOM::Element::userAuth;
4 use OpenSRF::DomainObject::oilsMessage;
5 use OpenSRF::DomainObject::oilsMethod;
6 use OpenSRF::DomainObject::oilsResponse qw/:status/;
7 use OpenSRF::Transport::PeerHandle;
8 use OpenSRF::Utils::Config;
9 use OpenSRF::Utils::Logger qw(:level);
10 use OpenSRF::EX;
11 use OpenSRF;
12 use Exporter;
13 use base qw/Exporter OpenSRF/;
14 use Time::HiRes qw( time usleep );
15 use warnings;
16 use strict;
17
18 our @EXPORT_OK = qw/CONNECTING INIT_CONNECTED CONNECTED DISCONNECTED CLIENT SERVER/;
19 our %EXPORT_TAGS = ( state => [ qw/CONNECTING INIT_CONNECTED CONNECTED DISCONNECTED/ ],
20                  endpoint => [ qw/CLIENT SERVER/ ],
21 );
22
23 my $logger = "OpenSRF::Utils::Logger";
24
25 our %_CACHE;
26 our @_CLIENT_CACHE;
27 our @_RESEND_QUEUE;
28
29 sub kill_client_session_cache {
30         for my $session ( @_CLIENT_CACHE ) {
31                 $session->kill_me;
32         }
33 }
34
35 sub CONNECTING { return 3 };
36 sub INIT_CONNECTED { return 4 };
37 sub CONNECTED { return 1 };
38 sub DISCONNECTED { return 2 };
39
40 sub CLIENT { return 2 };
41 sub SERVER { return 1 };
42
43 sub find {
44         return undef unless (defined $_[1]);
45         return $_CACHE{$_[1]} if (exists($_CACHE{$_[1]}));
46 }
47
48 sub find_client {
49         my( $self, $app ) = @_;
50         $logger->debug( "Client Cache contains: " .scalar(@_CLIENT_CACHE), INTERNAL );
51         my ($client) = grep { $_->[0] eq $app and $_->[1] == 1 } @_CLIENT_CACHE;
52         $client->[1] = 0;
53         return $client->[2];
54 }
55
56 sub transport_connected {
57         my $self = shift;
58         if( ! exists $self->{peer_handle} || 
59                                         ! $self->{peer_handle} ) {
60                 return 0;
61         }
62         return $self->{peer_handle}->tcp_connected();
63 }
64
65 # ----------------------------------------------------------------------------
66 # Clears the transport buffers
67 # call this if you are not through with the sesssion, but you want 
68 # to have a clean slate.  You shouldn't have to call this if
69 # you are correctly 'recv'ing all of the data from a request.
70 # however, if you don't want all of the data, this will
71 # slough off any excess
72 #  * * Note: This will delete data for all sessions using this transport
73 # handle.  For example, all client sessions use the same handle.
74 # ----------------------------------------------------------------------------
75 sub buffer_reset {
76
77         my $self = shift;
78         if( ! exists $self->{peer_handle} || ! $self->{peer_handle} ) { 
79                 return 0;
80         }
81         $self->{peer_handle}->buffer_reset();
82 }
83
84
85 sub client_cache {
86         my $self = shift;
87         push @_CLIENT_CACHE, [ $self->app, 1, $self ];
88 }
89
90 # when any incoming data is received, this method is called.
91 sub server_build {
92         my $class = shift;
93         $class = ref($class) || $class;
94
95         my $sess_id = shift;
96         my $remote_id = shift;
97         my $service = shift;
98
99         return undef unless ($sess_id and $remote_id and $service);
100
101         my $conf = OpenSRF::Utils::Config->current;
102         
103         if( ! $conf ) { 
104                 OpenSRF::EX::Config->throw( "No suitable config found" ); 
105         }
106
107         if ( my $thingy = $class->find($sess_id) ) {
108                 $thingy->remote_id( $remote_id );
109                 $logger->debug( "AppSession returning existing session $sess_id", DEBUG );
110                 return $thingy;
111         } else {
112                 $logger->debug( "AppSession building new server session $sess_id", DEBUG );
113         }
114
115         if( $service eq "client" ) {
116                 #throw OpenSRF::EX::PANIC ("Attempting to build a client session as a server" .
117                 #       " Session ID [$sess_id], remote_id [$remote_id]");
118                 $logger->debug("Attempting to build a client session as ".
119                                 "a server Session ID [$sess_id], remote_id [$remote_id]", ERROR );
120         }
121
122
123         my $max_requests = $conf->$service->max_requests;
124         $logger->debug( "Max Requests for $service is $max_requests", INTERNAL );# if $max_requests;
125
126         $logger->transport( "AppSession creating new session: $sess_id", INTERNAL );
127
128         my $self = bless { recv_queue  => [],
129                            request_queue  => [],
130                            requests  => 0,
131                            endpoint    => SERVER,
132                            state       => CONNECTING, 
133                            session_id  => $sess_id,
134                            remote_id    => $remote_id,
135                                 peer_handle => OpenSRF::Transport::PeerHandle->retrieve($service),
136                                 max_requests => $max_requests,
137                                 session_threadTrace => 0,
138                                 service => $service,
139                          } => $class;
140
141         return $_CACHE{$sess_id} = $self;
142 }
143
144 sub service { return shift()->{service}; }
145
146 sub continue_request {
147         my $self = shift;
148         $self->{'requests'}++;
149         return $self->{'requests'} <= $self->{'max_requests'} ? 1 : 0;
150 }
151
152 sub last_sent_payload {
153         my( $self, $payload ) = @_;
154         if( $payload ) {
155                 return $self->{'last_sent_payload'} = $payload;
156         }
157         return $self->{'last_sent_payload'};
158 }
159
160 sub last_sent_type {
161         my( $self, $type ) = @_;
162         if( $type ) {
163                 return $self->{'last_sent_type'} = $type;
164         }
165         return $self->{'last_sent_type'};
166 }
167
168 # When we're a client and we want to connect to a remote service
169 # create( $app, username => $user, secret => $passwd );
170 #    OR
171 # create( $app, sysname => $user, secret => $shared_secret );
172 sub create {
173         my $class = shift;
174         $class = ref($class) || $class;
175
176         my $app = shift;
177         my %auth_args = @_;
178
179
180 #       unless ( $app &&
181 #                exists($auth_args{secret}) &&
182 #                ( exists($auth_args{username}) ||
183 #                  exists($auth_args{sysname}) ) ) {
184 #               throw OpenSRF::EX::User ( 'Insufficient authentication information for session creation');
185 #       }
186
187         if( my $thingy = OpenSRF::AppSession->find_client( $app ) ) {
188                         $logger->debug( "AppSession returning existing client session for $app", DEBUG );
189                         return $thingy;
190         } else {
191                 $logger->debug( "AppSession creating new client session for $app", DEBUG );
192         }
193
194
195         
196         #my $auth = OpenSRF::DOM::Element::userAuth->new( %auth_args );
197
198         my $conf = OpenSRF::Utils::Config->current;
199
200         if( ! $conf ) { 
201                 OpenSRF::EX::Config->throw( "No suitable config found" ); 
202         }
203
204         my $sess_id = time . rand( $$ );
205         while ( $class->find($sess_id) ) {
206                 $sess_id = time . rand( $$ );
207         }
208
209         my $r_id = $conf->$app->transport_target ||
210                         die("No remote id for $app!");
211
212         my $peer_handle = OpenSRF::Transport::PeerHandle->retrieve("client"); 
213         if( ! $peer_handle ) {
214                 $peer_handle = OpenSRF::Transport::PeerHandle->retrieve("system_client");
215         }
216
217         my $self = bless { app_name    => $app,
218                                 #client_auth => $auth,
219                            #recv_queue  => [],
220                            request_queue  => [],
221                            endpoint    => CLIENT,
222                            state       => DISCONNECTED,#since we're init'ing
223                            session_id  => $sess_id,
224                            remote_id   => $r_id,
225                            orig_remote_id   => $r_id,
226                                 peer_handle => $peer_handle,
227                                 session_threadTrace => 0,
228                          } => $class;
229
230         $self->client_cache();
231         $_CACHE{$sess_id} = $self;
232         return $self->find_client( $app );
233 }
234
235 sub app {
236         return shift()->{app_name};
237 }
238
239 sub reset {
240         my $self = shift;
241         $self->remote_id($$self{orig_remote_id});
242 }
243
244 # 'connect' can be used as a constructor if called as a class method,
245 # or used to connect a session that has disconnectd if called against
246 # an existing session that seems to be disconnected, or was just built
247 # using 'create' above.
248
249 # connect( $app, username => $user, secret => $passwd );
250 #    OR
251 # connect( $app, sysname => $user, secret => $shared_secret );
252
253 # --- Returns undef if the connect attempt times out.
254 # --- Returns the OpenSRF::EX object if one is returned by the server
255 # --- Returns self if connected
256 sub connect {
257         my $self = shift;
258         my $class = ref($self) || $self;
259
260         if ( ref( $self ) and  $self->state && $self->state == CONNECTED  ) {
261                 $logger->transport("ABC AppSession already connected", DEBUG );
262         } else {
263                 $logger->transport("ABC AppSession not connected, connecting..", DEBUG );
264         }
265         return $self if ( ref( $self ) and  $self->state && $self->state == CONNECTED  );
266
267         my $app = shift;
268
269         $self = $class->create($app, @_) if (!ref($self));
270         return undef unless ($self);
271
272
273         $self->reset;
274         $self->state(CONNECTING);
275         $self->send('CONNECT', "");
276
277         my $time_remaining = OpenSRF::Utils::Config->current->client->connect_timeout;
278
279         while ( $self->state != CONNECTED  and $time_remaining > 0 ) {
280                 my $starttime = time;
281                 $self->queue_wait($time_remaining);
282                 my $endtime = time;
283                 $time_remaining -= ($endtime - $starttime);
284         }
285
286         return undef unless($self->state == CONNECTED);
287
288         return $self;
289 }
290
291 sub finish {
292         my $self = shift;
293         if( ! $self->session_id ) {
294                 return 0;
295         }
296         #$self->disconnect if ($self->endpoint == CLIENT);
297         for my $ses ( @_CLIENT_CACHE ) {
298                 if ($ses->[2]->session_id eq $self->session_id) {
299                         $ses->[1] = 1;
300                 }
301         }
302 }
303
304 sub kill_me {
305         my $self = shift;
306         if( ! $self->session_id ) { return 0; }
307         $self->disconnect;
308         $logger->transport( "AppSession killing self: " . $self->session_id(), DEBUG );
309         my @a;
310         for my $ses ( @_CLIENT_CACHE ) {
311                 push @a, $ses 
312                         if ($ses->[2]->session_id ne $self->session_id);
313         }
314         @_CLIENT_CACHE = @a;
315         delete $_CACHE{$self->session_id};
316         delete($$self{$_}) for (keys %$self);
317 }
318
319 sub disconnect {
320         my $self = shift;
321         unless( $self->state == DISCONNECTED ) {
322                 $self->send('DISCONNECT', "") if ($self->endpoint == CLIENT);;
323                 $self->state( DISCONNECTED ); 
324         }
325         $self->reset;
326 }
327
328 sub request {
329         my $self = shift;
330         my $meth = shift;
331
332         my $method;
333         if (!ref $meth) {
334                 $method = new OpenSRF::DomainObject::oilsMethod ( method => $meth );
335         } else {
336                 $method = $meth;
337         }
338         
339         $method->params( @_ );
340
341         $self->send('REQUEST',$method);
342 }
343
344
345 sub send {
346         my $self = shift;
347         my @payload_list = @_; # this is a Domain Object
348
349
350         $logger->debug( "In send", INTERNAL );
351         
352         my $tT;
353
354         if( @payload_list % 2 ) { $tT = pop @payload_list; }
355
356         if( ! @payload_list ) {
357                 $logger->debug( "payload_list param is incomplete in AppSession::send()", ERROR );
358                 return undef; 
359         }
360
361         my $doc = OpenSRF::DOM->createDocument();
362
363         $logger->debug( "In send2", INTERNAL );
364
365         my $disconnect = 0;
366         my $connecting = 0;
367
368         while( @payload_list ) {
369
370                 my ($msg_type, $payload) = ( shift(@payload_list), shift(@payload_list) ); 
371
372                 if ($msg_type eq 'DISCONNECT' ) {
373                         $disconnect++;
374                         if( $self->state == DISCONNECTED) {
375                                 next;
376                         }
377                 }
378
379                 if( $msg_type eq "CONNECT" ) { $connecting++; }
380
381
382                 if( $payload ) {
383                         $logger->debug( "Payload is ".$payload->toString, INTERNAL );
384                 }
385         
386         
387                 my $msg = OpenSRF::DomainObject::oilsMessage->new();
388                 $logger->debug( "AppSession after creating oilsMessage $msg", INTERNAL );
389                 
390                 $msg->type($msg_type);
391                 $logger->debug( "AppSession after adding type" . $msg->toString(), INTERNAL );
392         
393                 #$msg->userAuth($self->client_auth) if ($self->endpoint == CLIENT && $msg_type eq 'CONNECT');
394         
395                 no warnings;
396                 $msg->threadTrace( $tT || int($self->session_threadTrace) || int($self->last_threadTrace) );
397                 use warnings;
398         
399                 if ($msg->type eq 'REQUEST') {
400                         if ( !defined($tT) || $self->last_threadTrace != $tT ) {
401                                 $msg->update_threadTrace;
402                                 $self->session_threadTrace( $msg->threadTrace );
403                                 $tT = $self->session_threadTrace;
404                                 OpenSRF::AppRequest->new($self, $payload);
405                         }
406                 }
407         
408                 $msg->protocol(1);
409                 $msg->payload($payload) if $payload;
410         
411                 $doc->documentElement->appendChild( $msg );
412
413         
414                 $logger->debug( "AppSession sending ".$msg->type." to ".$self->remote_id.
415                         " with threadTrace [".$msg->threadTrace."]", INFO );
416
417         }
418         
419         if ($self->endpoint == CLIENT and ! $disconnect) {
420                 $self->queue_wait(0);
421                 unless ($self->state == CONNECTED || ($self->state == CONNECTING && $connecting )) {
422                         my $v = $self->connect();
423                         if( ! $v ) {
424                                 $logger->debug( "Unable to connect to remote service in AppSession::send()", ERROR );
425                                 return undef;
426                         }
427                         if( $v and $v->can("class") and $v->class->isa( "OpenSRF::EX" ) ) {
428                                 return $v;
429                         }
430                 }
431         } 
432
433         $logger->debug( "AppSession sending doc: " . $doc->toString(), INTERNAL );
434
435
436         $self->{peer_handle}->send( 
437                                         to     => $self->remote_id,
438                                    thread => $self->session_id,
439                                    body   => $doc->toString );
440
441         return $self->app_request( $tT );
442 }
443
444 sub app_request {
445         my $self = shift;
446         my $tT = shift;
447         
448         return undef unless (defined $tT);
449         my ($req) = grep { $_->threadTrace == $tT } @{ $self->{request_queue} };
450
451         return $req;
452 }
453
454 sub remove_app_request {
455         my $self = shift;
456         my $req = shift;
457         
458         my @list = grep { $_->threadTrace != $req->threadTrace } @{ $self->{request_queue} };
459
460         $self->{request_queue} = \@list;
461 }
462
463 sub endpoint {
464         return $_[0]->{endpoint};
465 }
466
467
468 sub session_id {
469         my $self = shift;
470         return $self->{session_id};
471 }
472
473 sub push_queue {
474         my $self = shift;
475         my $resp = shift;
476         my $req = $self->app_request($resp->[1]);
477         return $req->push_queue( $resp->[0] ) if ($req);
478         push @{ $self->{recv_queue} }, $resp->[0];
479 }
480
481 sub last_threadTrace {
482         my $self = shift;
483         my $new_last_threadTrace = shift;
484
485         my $old_last_threadTrace = $self->{last_threadTrace};
486         if (defined $new_last_threadTrace) {
487                 $self->{last_threadTrace} = $new_last_threadTrace;
488                 return $new_last_threadTrace unless ($old_last_threadTrace);
489         }
490
491         return $old_last_threadTrace;
492 }
493
494 sub session_threadTrace {
495         my $self = shift;
496         my $new_last_threadTrace = shift;
497
498         my $old_last_threadTrace = $self->{session_threadTrace};
499         if (defined $new_last_threadTrace) {
500                 $self->{session_threadTrace} = $new_last_threadTrace;
501                 return $new_last_threadTrace unless ($old_last_threadTrace);
502         }
503
504         return $old_last_threadTrace;
505 }
506
507 sub last_message_type {
508         my $self = shift;
509         my $new_last_message_type = shift;
510
511         my $old_last_message_type = $self->{last_message_type};
512         if (defined $new_last_message_type) {
513                 $self->{last_message_type} = $new_last_message_type;
514                 return $new_last_message_type unless ($old_last_message_type);
515         }
516
517         return $old_last_message_type;
518 }
519
520 sub last_message_protocol {
521         my $self = shift;
522         my $new_last_message_protocol = shift;
523
524         my $old_last_message_protocol = $self->{last_message_protocol};
525         if (defined $new_last_message_protocol) {
526                 $self->{last_message_protocol} = $new_last_message_protocol;
527                 return $new_last_message_protocol unless ($old_last_message_protocol);
528         }
529
530         return $old_last_message_protocol;
531 }
532
533 sub remote_id {
534         my $self = shift;
535         my $new_remote_id = shift;
536
537         my $old_remote_id = $self->{remote_id};
538         if (defined $new_remote_id) {
539                 $self->{remote_id} = $new_remote_id;
540                 return $new_remote_id unless ($old_remote_id);
541         }
542
543         return $old_remote_id;
544 }
545
546 sub client_auth {
547         return undef;
548         my $self = shift;
549         my $new_ua = shift;
550
551         my $old_ua = $self->{client_auth};
552         if (defined $new_ua) {
553                 $self->{client_auth} = $new_ua;
554                 return $new_ua unless ($old_ua);
555         }
556
557         return $old_ua->cloneNode(1);
558 }
559
560 sub state {
561         my $self = shift;
562         my $new_state = shift;
563
564         my $old_state = $self->{state};
565         if (defined $new_state) {
566                 $self->{state} = $new_state;
567                 return $new_state unless ($old_state);
568         }
569
570         return $old_state;
571 }
572
573 sub DESTROY {
574         my $self = shift;
575         delete $$self{$_} for keys %$self;
576         return undef;
577 }
578
579 sub recv {
580         my $self = shift;
581         my @proto_args = @_;
582         my %args;
583
584         if ( @proto_args ) {
585                 if ( !(@proto_args % 2) ) {
586                         %args = @proto_args;
587                 } elsif (@proto_args == 1) {
588                         %args = ( timeout => @proto_args );
589                 }
590         }
591
592         #$logger->debug( ref($self). " recv_queue before wait: " . $self->_print_queue(), INTERNAL );
593
594         if( exists( $args{timeout} ) ) {
595                 $args{timeout} = int($args{timeout});
596         } else {
597                 $args{timeout} = 10;
598         }
599
600         #$args{timeout} = 0 if ($self->complete);
601
602         $logger->debug( ref($self) ."->recv with timeout " . $args{timeout}, INTERNAL );
603
604         $args{count} ||= 1;
605
606         my $avail = @{ $self->{recv_queue} };
607         my $time_remaining = $args{timeout};
608
609         while ( $avail < $args{count} and $time_remaining > 0 ) {
610                 last if $self->complete;
611                 my $starttime = time;
612                 $self->queue_wait($time_remaining);
613                 my $endtime = time;
614                 $time_remaining -= ($endtime - $starttime);
615                 $avail = @{ $self->{recv_queue} };
616         }
617
618         #$logger->debug( ref($self)." queue after wait: " . $self->_print_queue(), INTERNAL );
619                 
620         my @list;
621         while ( my $msg = shift @{ $self->{recv_queue} } ) {
622                 push @list, $msg;
623                 last if (scalar(@list) >= $args{count});
624         }
625
626 #       $self->{recv_queue} = [@unlist, @{ $self->{recv_queue} }];
627         $logger->debug( "Number of matched responses: " . @list, DEBUG );
628
629         $self->queue_wait(0); # check for statuses
630         
631         return $list[0] unless (wantarray);
632         return @list;
633 }
634
635 sub push_resend {
636         my $self = shift;
637         push @OpenSRF::AppSession::_RESEND_QUEUE, @_;
638 }
639
640 sub flush_resend {
641         my $self = shift;
642         $logger->debug( "Resending..." . @_RESEND_QUEUE, DEBUG );
643         while ( my $req = shift @OpenSRF::AppSession::_RESEND_QUEUE ) {
644                 $req->resend;
645         }
646 }
647
648
649 sub queue_wait {
650         my $self = shift;
651         if( ! $self->{peer_handle} ) { return 0; }
652         my $timeout = shift || 0;
653         $logger->debug( "Calling queue_wait($timeout)" , DEBUG );
654         $logger->debug( "Timestamp before process($timeout) : " . $logger->format_time(), INTERNAL );
655         my $o = $self->{peer_handle}->process($timeout);
656         $logger->debug( "Timestamp after  process($timeout) : " . $logger->format_time(), INTERNAL );
657         $self->flush_resend;
658         return $o;
659 }
660
661 sub _print_queue {
662         my( $self ) = @_;
663         my $string = "";
664         foreach my $msg ( @{$self->{recv_queue}} ) {
665                 $string = $string . $msg->toString(1) . "\n";
666         }
667         return $string;
668 }
669
670 sub status {
671         my $self = shift;
672         $self->send( 'STATUS', @_ );
673 }
674
675 #-------------------------------------------------------------------------------
676
677 package OpenSRF::AppRequest;
678 use base qw/OpenSRF::AppSession/;
679 use OpenSRF::Utils::Logger qw/:level/;
680 use OpenSRF::DomainObject::oilsResponse qw/:status/;
681
682 sub new {
683         my $class = shift;
684         $class = ref($class) || $class;
685
686         my $session = shift;
687         my $threadTrace = $session->session_threadTrace || $session->last_threadTrace;
688         my $payload = shift;
689         
690         my $self = {    session     => $session,
691                         threadTrace => $threadTrace,
692                         payload     => $payload,
693                         complete    => 0,
694                         recv_queue  => [],
695         };
696
697         bless $self => $class;
698
699         push @{ $self->session->{request_queue} }, $self;
700
701         return $self;
702 }
703
704 sub queue_size {
705         my $size = @{$_[0]->{recv_queue}};
706         return $size;
707 }
708         
709 sub send {
710         shift()->session->send(@_);
711 }
712
713 sub finish {
714         my $self = shift;
715         $self->session->remove_app_request($self);
716         delete($$self{$_}) for (keys %$self);
717 }
718
719 sub session {
720         return shift()->{session};
721 }
722
723 sub complete {
724         my $self = shift;
725         my $complete = shift;
726         return $self->{complete} if ($self->{complete});
727         if (defined $complete) {
728                 $self->{complete} = $complete;
729         } else {
730                 $self->session->queue_wait(0);
731         }
732         return $self->{complete};
733 }
734
735 sub wait_complete {
736         my $self = shift;
737         my $timeout = shift || 1;
738         my $time_remaining = $timeout;
739
740         while ( ! $self->complete  and $time_remaining > 0 ) {
741                 my $starttime = time;
742                 $self->queue_wait($time_remaining);
743                 my $endtime = time;
744                 $time_remaining -= ($endtime - $starttime);
745         }
746
747         return $self->complete;
748 }
749
750 sub threadTrace {
751         return shift()->{threadTrace};
752 }
753
754 sub push_queue {
755         my $self = shift;
756         my $resp = shift;
757         if( !$resp ) { return 0; }
758         push @{ $self->{recv_queue} }, $resp;
759         OpenSRF::Utils::Logger->debug( "AppRequest pushed ".$resp->toString(), INTERNAL );
760 }
761
762 sub queue_wait {
763         my $self = shift;
764         OpenSRF::Utils::Logger->debug( "Calling queue_wait(@_)", DEBUG );
765         return $self->session->queue_wait(@_)
766 }
767
768 sub payload { return shift()->{payload}; }
769
770 sub resend {
771         my $self = shift;
772         OpenSRF::Utils::Logger->debug(
773                 "I'm resending the request for threadTrace ". $self->threadTrace, DEBUG);
774         if($self->payload) {
775                 OpenSRF::Utils::Logger->debug($self->payload->toString,INTERNAL);
776         }
777         return $self->session->send('REQUEST', $self->payload, $self->threadTrace );
778 }
779
780 sub status {
781         my $self = shift;
782         my $msg = shift;
783         $self->session->send( 'STATUS',$msg, $self->threadTrace );
784 }
785
786 sub respond {
787         my $self = shift;
788         my $msg = shift;
789
790         my $response;
791         if (ref($msg) && $msg->can('getAttribute') && $msg->getAttribute('name') =~ /oilsResult/) {
792                 $response = $msg;
793         } else {
794                 $response = new OpenSRF::DomainObject::oilsResult;
795                 $response->content($msg);
796         }
797
798         $self->session->send('RESULT', $response, $self->threadTrace);
799 }
800
801 sub respond_complete {
802         my $self = shift;
803         my $msg = shift;
804
805         my $response;
806         if (ref($msg) && $msg->can('getAttribute') && $msg->getAttribute('name') =~ /oilsResult/) {
807                 $response = $msg;
808         } else {
809                 $response = new OpenSRF::DomainObject::oilsResult;
810                 $response->content($msg);
811         }
812
813         my $stat = OpenSRF::DomainObject::oilsConnectStatus->new(
814                 statusCode => STATUS_COMPLETE(),
815                 status => 'Request Complete' );
816
817         $self->session->send( 'RESULT' => $response, 'STATUS' => $stat, $self->threadTrace);
818
819 }
820
821
822 package OpenSRF::AppSubrequest;
823
824 sub respond {
825         my $self = shift;
826         my $resp = shift;
827         push @{$$self{resp}}, $resp;
828 }
829
830 sub new {
831         return bless({resp => []}, 'OpenSRF::AppSubrequest');
832 }
833
834 sub responses { @{$_[0]->{resp}} }
835
836 sub status {}
837
838
839
840 1;
841
842
843 __END__
844
845 [client]
846 interval:connect_timeout = 2 seconds
847
848 [servers]
849 subsection:StorageServer = Storage_config
850
851 [Storage_config]
852 #transport = xmlrpc
853 #transport_target = http://open-ils.org/RPC2/services/Storage
854
855 transport = jabber
856 transport_target = Storage@open-ils.org/SERVICE_RECEIVER
857 method_class = OpenSRF::App::Storage::PGStore;
858
859
860
861
862