d1e3d8fd9f0eb8ed43cae35fbaffe8cacbce6e8a
[OpenSRF.git] / src / perl / lib / OpenSRF / Application.pm
1 package OpenSRF::Application;
2 # vim:noet:ts=4
3 use vars qw/$_app $log @_METHODS $thunk $server_class/;
4
5 use base qw/OpenSRF/;
6 use OpenSRF::AppSession;
7 use OpenSRF::DomainObject::oilsMethod;
8 use OpenSRF::DomainObject::oilsResponse qw/:status/;
9 use OpenSRF::Utils::Logger qw/:level $logger/;
10 use Data::Dumper;
11 use Time::HiRes qw/time/;
12 use OpenSRF::EX qw/:try/;
13 use Carp;
14 use OpenSRF::Utils::JSON;
15 #use OpenSRF::UnixServer;  # to get the server class from UnixServer::App
16
17 sub DESTROY{};
18
19 use strict;
20 use warnings;
21
22 $log = 'OpenSRF::Utils::Logger';
23
24 our $in_request = 0;
25 our @pending_requests;
26
27 sub package {
28         my $self = shift;
29         return 1 unless ref($self);
30         return $self->{package};
31 }
32
33 sub signature {
34         my $self = shift;
35         return 0 unless ref($self);
36         return $self->{signature};
37 }
38
39 sub strict {
40     my $self = shift; 
41     return 0 unless ref($self);
42     return $self->{strict};
43 }
44
45 sub argc {
46         my $self = shift;
47         return 0 unless ref($self);
48         return $self->{argc};
49 }
50
51 sub max_chunk_size {
52         my $self = shift;
53         return 0 unless ref($self);
54         return $self->{max_chunk_size} if (defined($self->{max_chunk_size}));
55         return 10240;
56 }
57
58 sub max_chunk_count {
59         my $self = shift;
60         return 0 unless ref($self);
61         return $self->{max_chunk_count} || 0;
62 }
63
64 sub api_name {
65         my $self = shift;
66         return 1 unless ref($self);
67         return $self->{api_name};
68 }
69
70 sub api_level {
71         my $self = shift;
72         return 1 unless ref($self);
73         return $self->{api_level};
74 }
75
76 sub session {
77         my $self = shift;
78         my $session = shift;
79
80         if($session) {
81                 $self->{session} = $session;
82         }
83         return $self->{session};
84 }
85
86 sub server_class {
87         my $class = shift;
88         if($class) {
89                 $server_class = $class;
90         }
91         return $server_class;
92 }
93
94 sub thunk {
95         my $self = shift;
96         my $flag = shift;
97         $thunk = $flag if (defined $flag);
98         return $thunk;
99 }
100
101 sub application_implementation {
102         my $self = shift;
103         my $app = shift;
104
105         if (defined $app) {
106                 $_app = $app;
107                 $_app->use;
108                 if( $@ ) {
109                         $log->error( "Error loading application_implementation: $app -> $@", ERROR);
110                 }
111
112         }
113
114         return $_app;
115 }
116
117 sub handler {
118         my ($self, $session, $app_msg) = @_;
119
120         if( ! $app_msg ) {
121                 return 1;  # error?
122         }
123
124         my $app = $self->application_implementation;
125
126         if ($session->last_message_type eq 'REQUEST') {
127
128         my @p = $app_msg->params;
129                 my $method_name = $app_msg->method;
130                 my $method_proto = $session->last_message_api_level;
131                 $log->info("CALL: $method_name [". (@p ? join(', ',@p) : '') ."]");
132
133                 my $coderef = $app->method_lookup( $method_name, $method_proto, 1, 1 );
134
135                 unless ($coderef) {
136                         $session->status( OpenSRF::DomainObject::oilsMethodException->new( 
137                                                 statusCode => STATUS_NOTFOUND(),
138                                                 status => "Method [$method_name] not found for $app"));
139                         return 1;
140                 }
141
142                 unless ($session->continue_request) {
143                         $session->status(
144                                 OpenSRF::DomainObject::oilsConnectStatus->new(
145                                                 statusCode => STATUS_REDIRECTED(),
146                                                 status => 'Disconnect on max requests' ) );
147                         $session->kill_me;
148                         return 1;
149                 }
150
151                 if (ref $coderef) {
152                         my @args = $app_msg->params;
153                         my $appreq = OpenSRF::AppRequest->new( $session );
154                         $appreq->max_chunk_size( $coderef->max_chunk_size );
155                         $appreq->max_chunk_count( $coderef->max_chunk_count );
156
157                         $log->debug( "in_request = $in_request : [" . $appreq->threadTrace."]", INTERNAL );
158                         if( $in_request ) {
159                                 $log->debug( "Pushing onto pending requests: " . $appreq->threadTrace, DEBUG );
160                                 push @pending_requests, [ $appreq, \@args, $coderef ]; 
161                                 return 1;
162                         }
163
164
165                         $in_request++;
166
167                         $log->debug( "Executing coderef for {$method_name}", INTERNAL );
168
169                         my $resp;
170                         try {
171                                 # un-if(0) this block to enable param checking based on signature and argc
172                                 if ($coderef->strict) {
173                                         if (@args < $coderef->argc) {
174                                                 die     "Not enough params passed to ".
175                                                         $coderef->api_name." : requires ". $coderef->argc
176                                         }
177                                         if (@args) {
178                                                 my $sig = $coderef->signature;
179                                                 if ($sig && exists $sig->{params}) {
180                                                         for my $p (0 .. scalar(@{ $sig->{params} }) - 1 ) {
181                                                                 my $s = $sig->{params}->[$p];
182                                                                 my $a = $args[$p];
183                                                                 if ($s->{class} && OpenSRF::Utils::JSON->lookup_hint(ref $a) ne $s->{class}) {
184                                                                         die "Incorrect param class at position $p : should be a '$$s{class}'";
185                                                                 } elsif ($s->{type}) {
186                                                                         if (lc($s->{type}) eq 'object' && $a !~ /HASH/o) {
187                                                                                 die "Incorrect param type at position $p : should be an 'object'";
188                                                                         } elsif (lc($s->{type}) eq 'array' && $a !~ /ARRAY/o) {
189                                                                                 die "Incorrect param type at position $p : should be an 'array'";
190                                                                         } elsif (lc($s->{type}) eq 'number' && (ref($a) || $a !~ /^-?\d+(?:\.\d+)?$/o)) {
191                                                                                 die "Incorrect param type at position $p : should be a 'number'";
192                                                                         } elsif (lc($s->{type}) eq 'string' && ref($a)) {
193                                                                                 die "Incorrect param type at position $p : should be a 'string'";
194                                                                         }
195                                                                 }
196                                                         }
197                                                 }
198                                         }
199                                 }
200
201                                 my $start = time();
202                                 $resp = $coderef->run( $appreq, @args); 
203                                 my $time = sprintf '%.3f', time() - $start;
204
205                                 $log->debug( "Method duration for [$method_name]:  ". $time );
206                                 if( defined( $resp ) ) {
207                                         $appreq->respond_complete( $resp );
208                                 } else {
209                                         $appreq->status( OpenSRF::DomainObject::oilsConnectStatus->new(
210                                                                 statusCode => STATUS_COMPLETE(),
211                                                                 status => 'Request Complete' ) );
212                                 }
213                         } catch Error with {
214                                 my $e = shift;
215                                 warn "Caught error from 'run' method: $e\n";
216
217                                 if(UNIVERSAL::isa($e,"Error")) {
218                                         $e = $e->stringify();
219                                 } 
220                                 my $sess_id = $session->session_id;
221                                 $session->status(
222                                         OpenSRF::DomainObject::oilsMethodException->new(
223                                                         statusCode      => STATUS_INTERNALSERVERERROR(),
224                                                         status          => " *** Call to [$method_name] failed for session ".
225                                                                            "[$sess_id], thread trace ".
226                                                                            "[".$appreq->threadTrace."]:\n$e\n"
227                                         )
228                                 );
229                         };
230
231
232
233                         # ----------------------------------------------
234
235
236                         # XXX may need this later
237                         # $_->[1] = 1 for (@OpenSRF::AppSession::_CLIENT_CACHE);
238
239                         $in_request--;
240
241                         $log->debug( "Pending Requests: " . scalar(@pending_requests), INTERNAL );
242
243                         # cycle through queued requests
244                         while( my $aref = shift @pending_requests ) {
245                                 $in_request++;
246                                 my $resp;
247                                 try {
248                                         # un-if(0) this block to enable param checking based on signature and argc
249                                         if (0) {
250                                                 if (@args < $aref->[2]->argc) {
251                                                         die     "Not enough params passed to ".
252                                                                 $aref->[2]->api_name." : requires ". $aref->[2]->argc
253                                                 }
254                                                 if (@args) {
255                                                         my $sig = $aref->[2]->signature;
256                                                         if ($sig && exists $sig->{params}) {
257                                                                 for my $p (0 .. scalar(@{ $sig->{params} }) - 1 ) {
258                                                                         my $s = $sig->{params}->[$p];
259                                                                         my $a = $args[$p];
260                                                                         if ($s->{class} && OpenSRF::Utils::JSON->lookup_hint(ref $a) ne $s->{class}) {
261                                                                                 die "Incorrect param class at position $p : should be a '$$s{class}'";
262                                                                         } elsif ($s->{type}) {
263                                                                                 if (lc($s->{type}) eq 'object' && $a !~ /HASH/o) {
264                                                                                         die "Incorrect param type at position $p : should be an 'object'";
265                                                                                 } elsif (lc($s->{type}) eq 'array' && $a !~ /ARRAY/o) {
266                                                                                         die "Incorrect param type at position $p : should be an 'array'";
267                                                                                 } elsif (lc($s->{type}) eq 'number' && (ref($a) || $a !~ /^-?\d+(?:\.\d+)?$/o)) {
268                                                                                         die "Incorrect param type at position $p : should be a 'number'";
269                                                                                 } elsif (lc($s->{type}) eq 'string' && ref($a)) {
270                                                                                         die "Incorrect param type at position $p : should be a 'string'";
271                                                                                 }
272                                                                         }
273                                                                 }
274                                                         }
275                                                 }
276                                         }
277
278                                         my $start = time;
279                                         my $response = $aref->[2]->run( $aref->[0], @{$aref->[1]} );
280                                         my $time = sprintf '%.3f', time - $start;
281                                         $log->debug( "Method duration for [".$aref->[2]->api_name." -> ".join(', ',@{$aref->[1]}).']:  '.$time, DEBUG );
282
283                                         $appreq = $aref->[0];   
284                                         if( ref( $response ) ) {
285                                                 $appreq->respond_complete( $response );
286                                         } else {
287                                                 $appreq->status( OpenSRF::DomainObject::oilsConnectStatus->new(
288                                                                         statusCode => STATUS_COMPLETE(),
289                                                                         status => 'Request Complete' ) );
290                                         }
291                                         $log->debug( "Executed: " . $appreq->threadTrace, INTERNAL );
292                                 } catch Error with {
293                                         my $e = shift;
294                                         if(UNIVERSAL::isa($e,"Error")) {
295                                                 $e = $e->stringify();
296                                         }
297                                         $session->status(
298                                                 OpenSRF::DomainObject::oilsMethodException->new(
299                                                                 statusCode => STATUS_INTERNALSERVERERROR(),
300                                                                 status => "Call to [".$aref->[2]->api_name."] faild:  $e"
301                                                 )
302                                         );
303                                 };
304                                 $in_request--;
305                         }
306
307                         return 1;
308                 } 
309
310                 $log->info("Received non-REQUEST message in Application handler");
311
312                 my $res = OpenSRF::DomainObject::oilsMethodException->new( 
313                                 status => "Received non-REQUEST message in Application handler");
314                 $session->send('ERROR', $res);
315                 $session->kill_me;
316                 return 1;
317
318         } else {
319                 $session->push_queue([ $app_msg, $session->last_threadTrace ]);
320         }
321
322         $session->last_message_type('');
323         $session->last_message_api_level('');
324
325         return 1;
326 }
327
328 sub is_registered {
329         my $self = shift;
330         my $api_name = shift;
331         my $api_level = shift || 1;
332         return exists($_METHODS[$api_level]{$api_name});
333 }
334
335
336 sub normalize_whitespace {
337         my $txt = shift;
338
339         $txt =~ s/^\s+//gso;
340         $txt =~ s/\s+$//gso;
341         $txt =~ s/\s+/ /gso;
342         $txt =~ s/\n//gso;
343         $txt =~ s/\. /\.  /gso;
344
345         return $txt;
346 }
347
348 sub parse_string_signature {
349         my $string = shift;
350         return [] unless $string;
351         my @chunks = split(/\@/smo, $string);
352
353         my @params;
354         my $ret;
355         my $desc = '';
356         for (@chunks) {
357                 if (/^return (.+)$/so) {
358                         $ret = [normalize_whitespace($1)];
359                 } elsif (/^param (\w+) \b(.+)$/so) {
360                         push @params, [ $1, normalize_whitespace($2) ];
361                 } else {
362                         $desc .= '@' if $desc;
363                         $desc .= $_;
364                 }
365         }
366
367         return [normalize_whitespace($desc),\@params, $ret];
368 }
369
370 sub parse_array_signature {
371         my $array = shift;
372         my ($d,$p,$r) = @$array;
373         return {} unless ($d or $p or $r);
374
375         return {
376                 desc    => $d,
377                 params  => [
378                         map { 
379                                 { name  => $$_[0],
380                                   desc  => $$_[1],
381                                   type  => $$_[2],
382                                   class => $$_[3],
383                                 }
384                         } @$p
385                 ],
386                 'return'=>
387                         { desc  => $$r[0],
388                           type  => $$r[1],
389                           class => $$r[2],
390                         }
391         };
392 }
393
394 sub register_method {
395         my $self = shift;
396         my $app = ref($self) || $self;
397         my %args = @_;
398
399
400         throw OpenSRF::DomainObject::oilsMethodException unless ($args{method});
401
402         $args{api_level} = 1 unless(defined($args{api_level}));
403         $args{stream} ||= 0;
404         $args{remote} ||= 0;
405         $args{argc} ||= 0;
406         $args{package} ||= $app;                
407         $args{server_class} = server_class();
408         $args{api_name} ||= $args{server_class} . '.' . $args{method};
409
410         # un-if(0) this block to enable signature parsing
411         if (!$args{signature}) {
412                 if ($args{notes} && !ref($args{notes})) {
413                         $args{signature} =
414                                 parse_array_signature( parse_string_signature( $args{notes} ) );
415                 }
416         } elsif( !ref($args{signature}) ) {
417                 $args{signature} =
418                         parse_array_signature( parse_string_signature( $args{signature} ) );
419         } elsif( ref($args{signature}) eq 'ARRAY') {
420                 $args{signature} =
421                         parse_array_signature( $args{signature} );
422         }
423         
424         unless ($args{object_hint}) {
425                 ($args{object_hint} = $args{package}) =~ s/::/_/go;
426         }
427
428         OpenSRF::Utils::JSON->register_class_hint( name => $args{package}, hint => $args{object_hint}, type => "hash" );
429
430         $_METHODS[$args{api_level}]{$args{api_name}} = bless \%args => $app;
431
432         __PACKAGE__->register_method(
433                 stream => 0,
434                 argc => $args{argc},
435                 api_name => $args{api_name}.'.atomic',
436                 method => 'make_stream_atomic',
437                 notes => "This is a system generated method.  Please see the definition for $args{api_name}",
438         ) if ($args{stream});
439 }
440
441 sub retrieve_remote_apis {
442         my $method = shift;
443         my $session = OpenSRF::AppSession->create('router');
444         try {
445                 $session->connect or OpenSRF::EX::WARN->throw("Connection to router timed out");
446         } catch Error with {
447                 my $e = shift;
448                 $log->debug( "Remote subrequest returned an error:\n". $e );
449                 return undef;
450         } finally {
451                 return undef unless ($session->state == $session->CONNECTED);
452         };
453
454         my $req = $session->request( 'opensrf.router.info.class.list' );
455         my $list = $req->recv;
456
457         if( UNIVERSAL::isa($list,"Error") ) {
458                 throw $list;
459         }
460
461         my $content = $list->content;
462
463         $req->finish;
464         $session->finish;
465         $session->disconnect;
466
467         my %u_list = map { ($_ => 1) } @$content;
468
469         for my $class ( keys %u_list ) {
470                 next if($class eq $server_class);
471                 populate_remote_method_cache($class, $method);
472         }
473 }
474
475 sub populate_remote_method_cache {
476         my $class = shift;
477         my $meth = shift;
478
479         my $session = OpenSRF::AppSession->create($class);
480         try {
481                 $session->connect or OpenSRF::EX::WARN->throw("Connection to $class timed out");
482
483                 my $call = 'opensrf.system.method.all' unless (defined $meth);
484                 $call = 'opensrf.system.method' if (defined $meth);
485
486                 my $req = $session->request( $call, $meth );
487
488                 while (my $method = $req->recv) {
489                         next if (UNIVERSAL::isa($method, 'Error'));
490
491                         $method = $method->content;
492                         next if ( exists($_METHODS[$$method{api_level}]) &&
493                                 exists($_METHODS[$$method{api_level}]{$$method{api_name}}) );
494                         $method->{remote} = 1;
495                         bless($method, __PACKAGE__ );
496                         $_METHODS[$$method{api_level}]{$$method{api_name}} = $method;
497                 }
498
499                 $req->finish;
500                 $session->finish;
501                 $session->disconnect;
502
503         } catch Error with {
504                 my $e = shift;
505                 $log->debug( "Remote subrequest returned an error:\n". $e );
506                 return undef;
507         };
508 }
509
510 sub method_lookup {             
511         my $self = shift;
512         my $method = shift;
513         my $proto = shift;
514         my $no_recurse = shift || 0;
515         my $no_remote = shift || 0;
516
517         # this instead of " || 1;" above to allow api_level 0
518         $proto = $self->api_level unless (defined $proto);
519
520         my $class = ref($self) || $self;
521
522         $log->debug("Lookup of [$method] by [$class] in api_level [$proto]", DEBUG);
523         $log->debug("Available methods\n\t".join("\n\t", keys %{ $_METHODS[$proto] }), INTERNAL);
524
525         my $meth;
526         if (__PACKAGE__->thunk) {
527                 for my $p ( reverse(1 .. $proto) ) {
528                         if (exists $_METHODS[$p]{$method}) {
529                                 $meth = $_METHODS[$p]{$method};
530                         }
531                 }
532         } else {
533                 if (exists $_METHODS[$proto]{$method}) {
534                         $meth = $_METHODS[$proto]{$method};
535                 }
536         }
537
538         if (defined $meth) {
539                 if($no_remote and $meth->{remote}) {
540                         $log->debug("OH CRAP We're not supposed to return remote methods", WARN);
541                         return undef;
542                 }
543
544         } elsif (!$no_recurse) {
545                 $log->debug("We didn't find [$method], asking everyone else.", DEBUG);
546                 retrieve_remote_apis($method);
547                 $meth = $self->method_lookup($method,$proto,1);
548         }
549
550         return $meth;
551 }
552
553 sub run {
554         my $self = shift;
555         my $req = shift;
556
557         my $resp;
558         my @params = @_;
559
560         if ( !UNIVERSAL::isa($req, 'OpenSRF::AppRequest') ) {
561                 $log->debug("Creating a SubRequest object", DEBUG);
562                 unshift @params, $req;
563                 $req = OpenSRF::AppSubrequest->new;
564                 $req->session( $self->session ) if ($self->session);
565
566         } else {
567                 $log->debug("This is a top level request", DEBUG);
568         }
569
570         if (!$self->{remote}) {
571                 my $code = \&{$self->{package} . '::' . $self->{method}};
572                 my $err = undef;
573
574                 try {
575                         $resp = $code->($self, $req, @params);
576
577                 } catch Error with {
578                         $err = shift;
579
580                         if( ref($self) eq 'HASH') {
581                                 $log->error("Sub $$self{package}::$$self{method} DIED!!!\n\t$err\n", ERROR);
582                         }
583                 };
584
585                 if($err) {
586                         if(UNIVERSAL::isa($err,"Error")) { 
587                                 throw $err;
588                         } else {
589                                 die $err->stringify; 
590                         }
591                 }
592
593
594                 $log->debug("Coderef for [$$self{package}::$$self{method}] has been run", DEBUG);
595
596                 if ( ref($req) and UNIVERSAL::isa($req, 'OpenSRF::AppSubrequest') ) {
597                         $req->respond($resp) if (defined $resp);
598                         $log->debug("SubRequest object is responding with : " . join(" ",$req->responses), DEBUG);
599                         return $req->responses;
600                 } else {
601                         $log->debug("A top level Request object is responding $resp", DEBUG) if (defined $resp);
602                         return $resp;
603                 }
604         } else {
605                 my $session = OpenSRF::AppSession->create($self->{server_class});
606                 try {
607                         #$session->connect or OpenSRF::EX::WARN->throw("Connection to [$$self{server_class}] timed out");
608                         my $remote_req = $session->request( $self->{api_name}, @params );
609                         while (my $remote_resp = $remote_req->recv) {
610                                 OpenSRF::Utils::Logger->debug("Remote Subrequest Received " . $remote_resp, INTERNAL );
611                                 if( UNIVERSAL::isa($remote_resp,"Error") ) {
612                                         throw $remote_resp;
613                                 }
614                                 $req->respond( $remote_resp->content );
615                         }
616                         $remote_req->finish();
617
618                 } catch Error with {
619                         my $e = shift;
620                         $log->debug( "Remote subrequest returned an error:\n". $e );
621                         return undef;
622                 };
623
624                 if ($session) {
625                         $session->disconnect();
626                         $session->finish();
627                 }
628
629                 $log->debug( "Remote Subrequest Responses " . join(" ", $req->responses), INTERNAL );
630
631                 return $req->responses;
632         }
633         # huh? how'd we get here...
634         return undef;
635 }
636
637 sub introspect {
638         my $self = shift;
639         my $client = shift;
640         my $method = shift;
641         my $limit = shift;
642         my $offset = shift;
643
644         if ($self->api_name =~ /all$/o) {
645                 $offset = $limit;
646                 $limit = $method;
647                 $method = undef; 
648         }
649
650         my ($seen,$returned) = (0,0);
651         for my $api_level ( reverse(1 .. $#_METHODS) ) {
652                 for my $api_name ( sort keys %{$_METHODS[$api_level]} ) {
653                         if (!$offset || $offset <= $seen) {
654                                 if (!$_METHODS[$api_level]{$api_name}{remote}) {
655                                         if (defined($method)) {
656                                                 if ($api_name =~ $method) {
657                                                         if (!$limit || $returned < $limit) {
658                                                                 $client->respond( $_METHODS[$api_level]{$api_name} );
659                                                                 $returned++;
660                                                         }
661                                                 }
662                                         } else {
663                                                 if (!$limit || $returned < $limit) {
664                                                         $client->respond( $_METHODS[$api_level]{$api_name} );
665                                                         $returned++;
666                                                 }
667                                         }
668                                 }
669                         }
670                         $seen++;
671                 }
672         }
673
674         return undef;
675 }
676 __PACKAGE__->register_method(
677         stream => 1,
678         method => 'introspect',
679         api_name => 'opensrf.system.method.all',
680         argc => 0,
681         signature => {
682                 desc => q/This method is used to introspect an entire OpenSRF Application/,
683                 return => {
684                         desc => q/A stream of objects describing the methods available via this OpenSRF Application/,
685                         type => 'object'
686                 }
687         },
688 );
689 __PACKAGE__->register_method(
690         stream => 1,
691         method => 'introspect',
692         argc => 1,
693         api_name => 'opensrf.system.method',
694         argc => 1,
695         signature => {
696                 desc => q/Use this method to get the definition of a single OpenSRF Method/,
697                 params => [
698                         { desc => q/The method to introspect/,
699                           type => 'string' },
700                 ],
701                 return => { desc => q/An object describing the method requested, or an error if it can't be found/,
702                             type => 'object' }
703         },
704 );
705
706 sub echo_method {
707         my $self = shift;
708         my $client = shift;
709         my @args = @_;
710
711         $client->respond( $_ ) for (@args);
712         return undef;
713 }
714 __PACKAGE__->register_method(
715         stream => 1,
716         method => 'echo_method',
717         argc => 1,
718         api_name => 'opensrf.system.echo',
719         signature => {
720                 desc => q/A test method that will echo back it's arguments in a streaming response/,
721                 params => [
722                         { desc => q/One or more arguments to echo back/ }
723                 ],
724                 return => { desc => q/A stream of the arguments passed/ }
725         },
726 );
727
728 sub time_method {
729         my( $self, $conn ) = @_;
730         return CORE::time;
731 }
732 __PACKAGE__->register_method(
733         method => 'time_method',
734         argc => 0,
735         api_name => 'opensrf.system.time',
736         signature => {
737                 desc => q/Returns the current system time as epoch seconds/,
738                 return => { desc => q/epoch seconds/ }
739         }
740 );
741
742 sub make_stream_atomic {
743         my $self = shift;
744         my $req = shift;
745         my @args = @_;
746
747         (my $m_name = $self->api_name) =~ s/\.atomic$//o;
748         my $m = $self->method_lookup($m_name);
749
750         $m->session( $req->session );
751         my @results = $m->run(@args);
752         $m->session('');
753
754         return \@results;
755 }
756
757
758 1;
759
760