OGSA-DAI provides several ways of delivering input and output data asynchronously. For example, data can be delivered to or from a URL or file, between a client and a session, or directly between multiple data service resources. This section will show you how to use this functionality.
Data can be delivered to and from a URL using the deliverToURL and deliverFromURL activities. Using these activities, the results of a database query could be written to a remote FTP server, a file containing WebRowSet XML data could be read from a URL and bulkloaded into a database.
http://www.ogsadai.org.uk/tutorial/transformRowSet.xsl ftp://user:password@example.com/path/filename
DeliverFromURL deliver = new DeliverFromURL(sourceURL);
anotherActivity.setInput(deliver.getOutput());
Delivery to a URL works in a similar way via the deliverToURL activity and its corresponding DeliverToURL client activity class:
DeliverToURL deliver = new DeliverToURL(destinationURL); deliver.setInput(anotherActivity.getOutput());
Note that the http protocol does not support the writing of data, however the ftp protocol does.
For a full example, see OGSA-DAI/examples/src/uk/org/ogsadai/examples/clienttoolkit/XSLTransformWithDelivery.java
Data can also be delivered to and from a file using the deliverToFile and deliverFromFile activities. In a similar way to the URL activities, these activities can be used to store the result data produced by another activity or to read input data for an activity pipeline.
DeliverFromFile deliver = new DeliverFromFile("C:/path/to/myfile.txt");
anotherActivity.setInput(deliver.getOutput());
Delivery to a file works in a similar way via the deliverToFile activity and its corresponding DeliverToFile client activity class:
DeliverToFile deliver = new DeliverToFile( "C:/path/to/myfile.txt" ); deliver.setInput(anotherActivity.getOutput());
Note that, by default, these activities are disabled in activity configuration documents used to configure OGSA-DAI services, due to the security issue arising from enabling access to anywhere on the data service file system.
Data can also be delivered to and from a remote GridFTP server using the deliverToGFTP and deliverFromGFTP activities.
DeliverToGFTP deliver = new DeliverToGFTP("ogsadai.org.uk", 8080, "myResults.txt");
DeliverToGFTP deliver = new DeliverToGFTP(); deliver.setHost(hostName); deliver.setPort(portNumber); deliver.setFile(fileName);
DeliverFromGFTP deliver = new DeliverFromGFTP("ogsadai.org.uk", 8080, "myResults.txt");
The DeliverToGFTP activity has one input and no output while the DeliverFromGFTP activity has one output and no input.
Using the outputStream activity it is possible to pull data from a session stream to a client. When a request containing an outputStream activity is sent to a data service resource, a new session stream will be created. The output of another activity must be connected to the outputStream activity and this data will be written to the session stream. The OGSA-DAI data transport functionality can then be used to stream data from that session stream to the client.
The complexities of the data transport functionality are encapsulated by the client toolkit DTOutputStream class. This is a great way to run a query that returns a large amount of data without either the server or client failing with a java.lang.OutOfMemoryError.
ActivityRequest request = new ActivityRequest(); request.setSessionRequirements(new JoinNewSession()); Response response = service.perform(request); Session session = response.getSession();
SQLQuery sqlQuery = new SQLQuery("select * from littleblackbook"); WebRowSet rowset = new WebRowSet(sqlQuery.getOutput()); DTOutputStream outputStream = new DTOutputStream(rowset.getOutput()); ActivityRequest queryRequest = new ActivityRequest(); queryRequest.add(sqlQuery); queryRequest.add(rowset); queryRequest.add(outputStream); queryRequest.setSessionRequirements(new JoinExistingSession(session));
service.perform(queryRequest);
ResultSet rs = outputStream.getResultSet();
This will create a ResultSet object that will be of type ResultSet.TYPE_FORWARD_ONLY. When the next row is requested from the ResultSet object, the data transport operations of the data service will be used to retrieve the data.
For an example, see OGSA-DAI/examples/src/uk/org/ogsadai/examples/clienttoolkit/ProcessingSQLQueryLargeResults.java
Using the inputStream activity it is possible to push data from a client into a session stream. The inputStream activity then reads the data and makes it available to a connected activity. When a request containing an outputStream activity is sent to a data service resource, a new session stream will be created. The data transport functionality can then be used to stream data from a client into the session stream.
ActivityRequest request = new ActivityRequest(); request.setSessionRequirements(new JoinNewSession()); Response response = service.perform(request); Session session = response.getSession();
DTInputStream inputStream = new DTInputStream(); SQLUpdate update = new SQLUpdate("insert into littleblackbook values (?,?,?,?)"); update.setParameter(1, inputStream.getOutput()); update.setParameter(2, inputStream.getOutput()); update.setParameter(3, inputStream.getOutput()); update.setParameter(4, inputStream.getOutput()); ActivityRequest updateRequest = new ActivityRequest(); updateRequest.addActivity(inputStream); updateRequest.addActivity(update); updateRequest.setSessionRequirements(new JoinExistingSession(session));
service.perform(updateRequest);
DataTransport putter = inputStream.getDataTransport();
putter.putBlock(new Integer(10010)); putter.putBlock("Albert Einstein"); putter.putBlock("Patent Office, Bern"); putter.putBlock("0123456789");
putter.putClosingBlock();
For an example, see OGSA-DAI/examples/src/uk/org/ogsadai/examples/clienttoolkit/ParameterisedUpdateViaDataTransport.java
Data can be pulled between two data service resources using the outputStream activity in conjunction with the deliverFromDT activity. In this example we refer to the data service resource that produces the data as the source and the data service resource that consumes the data as the sink.
The figure above illustrates the delivery scenario. Three requests are involved:
To realise this scenario using the client toolkit, follow these steps:
DataService sourceService = GenericServiceFetcher.getInstance().getDataService( sourceHandle, sourceResourceID); DataService sinkService = GenericServiceFetcher.getInstance().getDataService( sinkHandle, sinkResourceID);
SQLQuery sqlQuery = new SQLQuery("select * from littleblackbook where id<100"); WebRowSet rowset = new WebRowSet(sqlQuery.getOutput()); DTOutputStream outputStream = new DTOutputStream(); outputStream.setInput(rowset.getOutput()); ActivityRequest sourceRequest = new ActivityRequest(); sourceRequest.add(sqlQuery); sourceRequest.add(rowset); sourceRequest.add(outputStream); sourceRequest.setSessionRequirements(new JoinNewSession());
Response response = sourceService.perform(sourceRequest); Session session = response.getSession();
DeliverFromDT deliverFromDT = new DeliverFromDT(); deliverFromDT.setDataTransportInput(outputStream.getDataTransport()); deliverFromDT.setDataTransportMode(DataTransportMode.BLOCK); ActivityRequest sinkRequest = new ActivityRequest(); sinkRequest.add(deliverFromDT);
response = sinkService.perform(sinkRequest); System.out.println(response.getAsString());
sourceRequest = new ActivityRequest(); sourceRequest.setSessionRequirements(new TerminateSession(session)); sourceService.perform(sourceRequest);
For a full example. see OGSA-DAI/examples/src/uk/org/ogsadai/examples/clienttoolkit/DataTransportExample.java
Data can also be pushed between two data service resources. To achieve this, the inputStream activity can be used in conjunction with the deliverToDT activity. In this example we refer to the data service resource that produces the data as the source and the data service resource that consumes the data as the sink. The figure below illustrates such a scenario.
In this case, the first request must be sent to the sink data service resource since it instructs the creation of the session and session stream. The second request is then sent to the source data service resource containing a DeliverToDT activity which will push the result data to the session stream at the sink data service resource. This will cause the first request to start processing, reading the pushed data and writing it into a local file.
When working with data delivery between data service resources, care must be taken to consider the synchronous or asynchronous nature of requests. In the above example, the first request is an asynchronous request with no result data to deliver in the response. So when it is performed, the client code will not block until the request is finished. If this request was instead a synchronous request with result data to return, the perform invocation would block, so the client would need to use a different thread for sending the second request to the source data service resource.
Back: Asynchronous Requests | Up: Using the Client Toolkit | Next: Data Integration | |
© International Business Machines Corporation, 2002-2006 | © The University of Edinburgh, 2002-2006 |