1 package OpenSRF::Application::Demo::Math;
2 use base qw/OpenSRF::Application/;
3 use OpenSRF::Application;
4 use OpenSRF::Utils::Logger qw/:level/;
5 use OpenSRF::DomainObject::oilsResponse;
6 use OpenSRF::EX qw/:try/;
12 our $log = 'OpenSRF::Utils::Logger';
16 # my( $class, $method_name, $method_proto ) = @_;
18 # if( $method_name eq "add" ) {
22 # if( $method_name eq "sub" ) {
26 # if( $method_name eq "mult" ) {
30 # if( $method_name eq "div" ) {
40 my $method_name = shift;
43 $log->debug( "Creating a client environment", DEBUG );
44 my $session = OpenSRF::AppSession->create(
45 "dbmath", sysname => 'math', secret => '12345' );
47 $log->debug( "Sending request to math server", INTERNAL );
49 my $method = OpenSRF::DomainObject::oilsMethod->new( method => $method_name );
51 $method->params( @params );
61 my $vv = $session->connect();
64 throw OpenSRF::EX::CRITICAL ("DBMath connect attempt timed out");
68 $req = $session->request( $method );
69 $resp = $req->recv(10);
71 } catch OpenSRF::DomainObject::oilsAuthException with {
76 if ( defined($resp) and $resp and $resp->class->isa('OpenSRF::DomainObject::oilsResult') ){
78 $log->debug( "Math server returned " . $resp->toString(1), INTERNAL );
85 if( $resp ) { $log->debug( "Math received \n".$resp->toString(), ERROR ); }
86 else{ $log->debug( "Math received empty value", ERROR ); }
89 throw OpenSRF::EX::ERROR ("Did not receive expected data from MathDB");
95 sub add_1_action { 1 };
100 return send_request( "add", @args );
103 sub sub_1_action { 1 };
107 return send_request( "sub", @args );
110 sub mult_1_action { 1 };
114 return send_request( "mult", @args );
117 sub div_1_action { 1 };
121 return send_request( "div", @args );