| 1 | =pod | ||
| 2 | |||
| 3 | =head1 NAME | ||
| 4 | |||
| 5 | MOBY::Async - a set of tools for Asynchronous MOBY Services | ||
| 6 | |||
| 7 | =head1 SYNOPSIS | ||
| 8 | |||
| 9 | This is a set of tools for providing and invoking Asynchronous MOBY Services. | ||
| 10 | |||
| 11 | =head1 FORMER AUTHORS | ||
| 12 | |||
| 13 | Enrique de Andres Saiz (enrique.deandres@pcm.uam.es) - | ||
| 14 | INB GNHC-1 (Madrid Science Park, Spain). | ||
| 15 | |||
| 16 | =head1 MAINTAINERS | ||
| 17 | |||
| 18 | Jose Manuel Rodriguez Carrasco (jmrodriguez@cnio.es) - | ||
| 19 | INB GN-2 (Centro Nacional de Investigaciones Oncologicas, Spain). | ||
| 20 | |||
| 21 | Jose Maria Fernandez Gonzalez (jmfernandez@cnio.es) - | ||
| 22 | INB GN-2 (Centro Nacional de Investigaciones Oncologicas, Spain). | ||
| 23 | |||
| 24 | =head1 DESCRIPTION | ||
| 25 | |||
| 26 | MOBY::Async package provides a set of modules for working with Asynchronous MOBY | ||
| 27 | Services, both from client and server side. It consists of the following modules: | ||
| 28 | |||
| 29 | =over | ||
| 30 | |||
| 31 | =item MOBY::Async::SimpleServer | ||
| 32 | |||
| 33 | It provides a simple class that can be extended to build file based asynchronous | ||
| 34 | services. | ||
| 35 | |||
| 36 | =item MOBY::Async::Service | ||
| 37 | |||
| 38 | It provides a class to invoke asynchronous services. | ||
| 39 | |||
| 40 | =item MOBY::Async::LSAE | ||
| 41 | |||
| 42 | It provides functionalities to work with LSAE analysis event blocks. | ||
| 43 | |||
| 44 | =item MOBY::Async::WSRF | ||
| 45 | |||
| 46 | It extends L<WSRF::Lite> perl module and provides everything required for | ||
| 47 | L<MOBY::Async::SimpleServer> class. | ||
| 48 | |||
| 49 | =back | ||
| 50 | |||
| 51 | =head1 EXAMPLE | ||
| 52 | |||
| 53 | The following example implements the classic "Hello World" service with a delay | ||
| 54 | of 60 seconds. | ||
| 55 | |||
| 56 | From the server side, an asynchronous service is very similar to the traditional | ||
| 57 | synchronous BioMOBY services. It is composed by a cgi (dispatcher.cgi) and a | ||
| 58 | Perl module wich extends L<MOBY::Async::SimpleServer> class (HelloWorld.pm). | ||
| 59 | |||
| 60 | B<dispatcher.cgi> | ||
| 61 | |||
| 62 | #!/usr/bin/perl | ||
| 63 | use lib "/path/to/my/libs"; | ||
| 64 | use strict; | ||
| 65 | use SOAP::Transport::HTTP; | ||
| 66 | use MOBY::Async::WSRF; | ||
| 67 | use MOBY::Async::SimpleServer; | ||
| 68 | use HelloWorld; | ||
| 69 | |||
| 70 | my $server = new SOAP::Transport::HTTP::CGI; | ||
| 71 | $server->serializer(WSRF::Serializer->new); | ||
| 72 | $server->deserializer(WSRF::Deserializer->new); | ||
| 73 | $server->on_action(sub{}); | ||
| 74 | $server->dispatch_with({ | ||
| 75 | $WSRF::Constants::MOBY.'#sayHello' => 'HelloWorld', | ||
| 76 | $WSRF::Constants::MOBY.'#sayHello_submit' => 'HelloWorld', | ||
| 77 | $WSRF::Constants::WSRPW.'/GetResourceProperty/GetResourcePropertyRequest' => 'MOBY::Async::SimpleServer', | ||
| 78 | $WSRF::Constants::WSRPW.'/GetMultipleResourceProperties/GetMultipleResourcePropertiesRequest' => 'MOBY::Async::SimpleServer', | ||
| 79 | $WSRF::Constants::WSRLW.'/ImmediateResourceTermination/DestroyRequest' => 'MOBY::Async::SimpleServer', | ||
| 80 | }); | ||
| 81 | $server->handle(); | ||
| 82 | |||
| 83 | B<HelloWorld.pm> | ||
| 84 | |||
| 85 | package HelloWorld; | ||
| 86 | use strict; | ||
| 87 | use MOBY::CommonSubs qw(:all); | ||
| 88 | use MOBY::Async::SimpleServer; | ||
| 89 | use base qw(MOBY::Async::SimpleServer); | ||
| 90 | |||
| 91 | # This environment variable must be set - it is used internally | ||
| 92 | # by MOBY::Async::SimpleServer class | ||
| 93 | $ENV{AUTHURI} = 'your.auth.com'; | ||
| 94 | |||
| 95 | # This variable is a subroutine which carries out the core of the service | ||
| 96 | my $sayHello = sub { | ||
| 97 | my ($caller, $data) = @_; | ||
| 98 | my $response = ''; | ||
| 99 | |||
| 100 | my @queries = getInputs($data); | ||
| 101 | return responseHeader($ENV{AUTHURI}).responseFooter() unless (scalar(@queries)); | ||
| 102 | |||
| 103 | foreach my $query (@queries) { | ||
| 104 | my $queryID = getInputID($query); | ||
| 105 | $response .= simpleResponse('Hello, Asynchronous BioMOBY world!!!', 'message', $queryID); | ||
| 106 | sleep 60; | ||
| 107 | } | ||
| 108 | |||
| 109 | return SOAP::Data->value(responseHeader($ENV{AUTHURI}).$response.responseFooter())->type('string'); | ||
| 110 | }; | ||
| 111 | |||
| 112 | # This is the method which answers to synchronous requests | ||
| 113 | sub sayHello { | ||
| 114 | my $self = shift @_; | ||
| 115 | # Here you can choose between sync or error | ||
| 116 | return $self->sync($sayHello, 180, @_); | ||
| 117 | #return $self->error(@_); | ||
| 118 | } | ||
| 119 | |||
| 120 | # This is the method which answers to asynchronous requests | ||
| 121 | sub sayHello_submit { | ||
| 122 | my $self = shift @_; | ||
| 123 | return $self->async($sayHello, @_); | ||
| 124 | } | ||
| 125 | |||
| 126 | 1; | ||
| 127 | |||
| 128 | A client which wishes to run an asynchronous service as HelloWorld must carry out | ||
| 129 | the following steps: | ||
| 130 | |||
| 131 | 1. First we have a sayHello_submit (servicename_submit) invocation, which | ||
| 132 | returns an EPR, that it is a "ticket" unique for all the async services of | ||
| 133 | the service provider (or at least in that particular server). | ||
| 134 | sayHello_submit is called with a normal BioMOBY input but it returns an EPR | ||
| 135 | which will be included into the SOAP header of all the subsequent calls (to | ||
| 136 | say which batch-call). | ||
| 137 | |||
| 138 | 2. After this, a polling is done by invocating GetMultipleResourceProperties | ||
| 139 | operation. GetMultipleResourceProperties retrieve the content of one or several | ||
| 140 | properties. In this case, as we are trying to determine if a batch-call has | ||
| 141 | finished, we ask all status properties (status_queryID). The status returned | ||
| 142 | for each status property is in LSAE format. Unless all status properties | ||
| 143 | represent that execution for its respective query identifier is finished, we | ||
| 144 | sleep a time and we retry the polling again. | ||
| 145 | |||
| 146 | 3. Once all status properties represent a finished execution, there is another | ||
| 147 | GetMultipleResourceProperties invocation asking for the result properties. | ||
| 148 | The content of the returned result properties are in BioMOBY format. | ||
| 149 | |||
| 150 | 4. The client also explicitly calls the WSRF Destroy operation to clean the | ||
| 151 | results at the service side. | ||
| 152 | |||
| 153 | To do this, a client relies on MOBY::Async::Service class, whose use is very | ||
| 154 | similar to MOBY::Client::Service class available for synchronous services: | ||
| 155 | |||
| 156 | # By default, silent is true, then no messages about the progress are reported | ||
| 157 | my $S = MOBY::Async::Service->new(service => $wsdl); | ||
| 158 | $S->silent(0); | ||
| 159 | my $response = $S->execute(XMLinputlist => [ | ||
| 160 | ['myArtName00', '<String namespace="" id=""><![CDATA[Hey No. 0 !!!]]></String>'], | ||
| 161 | ['myArtName01', '<String namespace="" id=""><![CDATA[Hey No. 1 !!!]]></String>'] | ||
| 162 | ]); | ||
| 163 | print "$response\n"; | ||
| 164 | |||
| 165 | Additionally, MOBY::Async::Service class provides methods to carry out | ||
| 166 | individually the steps previously described: | ||
| 167 | |||
| 168 | my $S = MOBY::Async::Service->new(service => $wsdl); | ||
| 169 | my ($EPR, @queryIDs) = $S->submit(XMLinputlist => [ | ||
| 170 | ['myArtName00', '<String namespace="" id=""><![CDATA[Hey No. 0 !!!]]></String>'], | ||
| 171 | ['myArtName01', '<String namespace="" id=""><![CDATA[Hey No. 1 !!!]]></String>'] | ||
| 172 | ]); | ||
| 173 | #... | ||
| 174 | my @status = $S->poll($EPR, @queryIDs); | ||
| 175 | #... | ||
| 176 | my @response = $S->result($EPR, @queryIDs); | ||
| 177 | #... | ||
| 178 | $S->destroy($EPR); | ||
| 179 | |||
| 180 | =head1 FURTHER READING | ||
| 181 | |||
| 182 | L<MOBY::Async::SimpleServer>, L<MOBY::Async::Service>, L<MOBY::Async::LSAE> and | ||
| 183 | L<MOBY::Async::WSRF> Perl modules documentation. | ||
| 184 | |||
| 185 | Asynchronous BioMOBY Services Specification: | ||
| 186 | L<http://biomoby.open-bio.org/CVS_CONTENT/moby-live/Docs/asyncDocs/BioMOBY%20Asynchronous%20Service%20Specification%20v2.4.2.pdf> | ||
| 187 | |||
| 188 | WSRF Specifications: | ||
| 189 | L<http://www.oasis-open.org/committees/tc_home.php?wg_abbrev=wsrf#technical> | ||
| 190 | |||
| 191 | =cut |